SamHeaderRecord.h

00001 /*
00002  *  Copyright (C) 2010  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef __SAMHEADER_RECORD_H__
00019 #define __SAMHEADER_RECORD_H__
00020 
00021 #include "StringArray.h"
00022 #include "StringHash.h"
00023 #include "SamHeaderTag.h"
00024 
00025 class SamHeaderRecord
00026 {
00027 public:
00028     enum SamHeaderRecordType {HD, SQ, RG, PG};
00029 
00030     // Constructor
00031     SamHeaderRecord();
00032    
00033     // Destructor
00034     ~SamHeaderRecord();
00035 
00036     // Set the fields from the passed in line.
00037     // Return true if successfully set.
00038     bool setFields(const StringArray& tokens);
00039 
00040     // Check to see if the record is valid.
00041     bool isValid();
00042 
00043     // Return the value associated with the specified tag.
00044     const char* getTagValue(const char* tag) const;
00045 
00046     // Set the value of the specified tag to the specified value.
00047     // Set value to NULL in order to delete the tag.
00048     // Returns whether or not it was successful.
00049     // Fails if tag is the key tag and the key tag already exists.
00050     bool setTag(const char* tag, const char* value);
00051 
00052     // Reset this header record to an empty state.
00053     void reset();
00054 
00055     // Appends the string representation of this header record
00056     // to the passed in string.
00057     bool appendString(std::string& header);
00058 
00059     // Add the key tag with the specified value.
00060     bool addKey(const char* value);
00061 
00062     // This record is active if there is at least one tag set.
00063     bool isActiveHeaderRecord();
00064 
00065     // Return the type of this header record.
00066     const char* getTypeString();
00067 
00068     // Return the type of this header record.
00069     SamHeaderRecordType getType();
00070 
00071 protected:
00072     void addRequiredTag(const char* requiredTag);
00073 
00074     // The type for this header record.
00075     std::string myTypeString;
00076 
00077     // The type for this header record.
00078     SamHeaderRecordType myType;
00079 
00080     // The TAG name that is the key for this record
00081     // Only applicable if more than one of this type
00082     // of record is allowed.
00083     std::string myKeyTag;
00084 
00085 private:
00086     // hash from tag name to index into the tag values vector.
00087     StringIntHash myTagHash;
00088     std::vector<SamHeaderTag*> myTags;
00089 
00090     // The tags that are required for this record.
00091     std::vector<String> myRequiredTags;
00092 
00093     int myNumActiveTags;
00094 };
00095 
00096 #endif
Generated on Wed Nov 17 15:38:27 2010 for StatGen Software by  doxygen 1.6.3