00001 // *************************************************************************** 00002 // SamProgramChain.h (c) 2011 Derek Barnett 00003 // Marth Lab, Department of Biology, Boston College 00004 // --------------------------------------------------------------------------- 00005 // Last modified: 10 October 2011 (DB) 00006 // --------------------------------------------------------------------------- 00007 // Provides methods for operating on a SamProgram record "chain" 00008 // *************************************************************************** 00009 00010 #ifndef SAM_PROGRAMCHAIN_H 00011 #define SAM_PROGRAMCHAIN_H 00012 00013 #include "api/api_global.h" 00014 #include "api/SamProgram.h" 00015 #include <string> 00016 #include <vector> 00017 00018 namespace BamTools { 00019 00020 // chain is *NOT* sorted in any order 00021 // use First()/Last() to retrieve oldest/newest programs, respectively 00022 typedef std::vector<SamProgram> SamProgramContainer; 00023 typedef SamProgramContainer::iterator SamProgramIterator; 00024 typedef SamProgramContainer::const_iterator SamProgramConstIterator; 00025 00026 class API_EXPORT SamProgramChain { 00027 00028 // ctor & dtor 00029 public: 00030 SamProgramChain(void); 00031 SamProgramChain(const SamProgramChain& other); 00032 ~SamProgramChain(void); 00033 00034 // query/modify program data 00035 public: 00036 // appends a program record to the chain 00037 void Add(SamProgram& program); 00038 void Add(std::vector<SamProgram>& programs); 00039 00040 // clears all read group entries 00041 void Clear(void); 00042 00043 // returns true if chain contains this program record (matches on ID) 00044 bool Contains(const SamProgram& program) const; 00045 bool Contains(const std::string& programId) const; 00046 00047 // returns the first (oldest) program in the chain 00048 SamProgram& First(void); 00049 const SamProgram& First(void) const; 00050 00051 // returns true if chain is empty 00052 bool IsEmpty(void) const; 00053 00054 // returns last (most recent) program in the chain 00055 SamProgram& Last(void); 00056 const SamProgram& Last(void) const; 00057 00058 // returns number of program records in the chain 00059 int Size(void) const; 00060 00061 // retrieves a modifiable reference to the SamProgram object associated with this ID 00062 SamProgram& operator[](const std::string& programId); 00063 00064 // retrieve STL-compatible iterators 00065 public: 00066 SamProgramIterator Begin(void); // returns iterator to begin() 00067 SamProgramConstIterator Begin(void) const; // returns const_iterator to begin() 00068 SamProgramConstIterator ConstBegin(void) const; // returns const_iterator to begin() 00069 SamProgramIterator End(void); // returns iterator to end() 00070 SamProgramConstIterator End(void) const; // returns const_iterator to end() 00071 SamProgramConstIterator ConstEnd(void) const; // returns const_iterator to end() 00072 00073 // internal methods 00074 private: 00075 int IndexOf(const std::string& programId) const; 00076 const std::string NextIdFor(const std::string& programId) const; 00077 00078 // data members 00079 private: 00080 SamProgramContainer m_data; 00081 }; 00082 00083 } // namespace BamTools 00084 00085 #endif // SAM_PROGRAMCHAIN_H