BamTools  2.5.1
SamProgramChain.h
Go to the documentation of this file.
1 // ***************************************************************************
2 // SamProgramChain.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 October 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides methods for operating on a SamProgram record "chain"
8 // ***************************************************************************
9 
10 #ifndef SAM_PROGRAMCHAIN_H
11 #define SAM_PROGRAMCHAIN_H
12 
13 #include <string>
14 #include <vector>
15 #include "api/SamProgram.h"
16 #include "api/api_global.h"
17 
18 namespace BamTools {
19 
20 // chain is *NOT* sorted in any order
21 // use First()/Last() to retrieve oldest/newest programs, respectively
22 typedef std::vector<SamProgram> SamProgramContainer;
23 typedef SamProgramContainer::iterator SamProgramIterator;
24 typedef SamProgramContainer::const_iterator SamProgramConstIterator;
25 
27 {
28 
29  // ctor & dtor
30 public:
32  SamProgramChain(const SamProgramChain& other);
33  ~SamProgramChain();
34 
35  // query/modify program data
36 public:
37  // appends a program record to the chain
38  void Add(SamProgram& program);
39  void Add(std::vector<SamProgram>& programs);
40 
41  // clears all read group entries
42  void Clear();
43 
44  // returns true if chain contains this program record (matches on ID)
45  bool Contains(const SamProgram& program) const;
46  bool Contains(const std::string& programId) const;
47 
48  // returns the first (oldest) program in the chain
49  SamProgram& First();
50  const SamProgram& First() const;
51 
52  // returns true if chain is empty
53  bool IsEmpty() const;
54 
55  // returns last (most recent) program in the chain
56  SamProgram& Last();
57  const SamProgram& Last() const;
58 
59  // returns number of program records in the chain
60  int Size() const;
61 
62  // retrieves a modifiable reference to the SamProgram object associated with this ID
63  SamProgram& operator[](const std::string& programId);
64 
65  // retrieve STL-compatible iterators
66 public:
67  SamProgramIterator Begin(); // returns iterator to begin()
68  SamProgramConstIterator Begin() const; // returns const_iterator to begin()
69  SamProgramConstIterator ConstBegin() const; // returns const_iterator to begin()
70  SamProgramIterator End(); // returns iterator to end()
71  SamProgramConstIterator End() const; // returns const_iterator to end()
72  SamProgramConstIterator ConstEnd() const; // returns const_iterator to end()
73 
74  // internal methods
75 private:
76  int IndexOf(const std::string& programId) const;
77  const std::string NextIdFor(const std::string& programId) const;
78 
79  // data members
80 private:
81  SamProgramContainer m_data;
82 };
83 
84 } // namespace BamTools
85 
86 #endif // SAM_PROGRAMCHAIN_H
#define API_EXPORT
Definition: api_global.h:18
Sorted container "chain" of SamProgram records.
Definition: SamProgramChain.h:27
Contains all BamTools classes & methods.
Definition: Sort.h:24
std::vector< SamProgram > SamProgramContainer
Definition: SamProgramChain.h:22
SamProgramContainer::iterator SamProgramIterator
Definition: SamProgramChain.h:23
SamProgramContainer::const_iterator SamProgramConstIterator
Definition: SamProgramChain.h:24
Represents a SAM program record.
Definition: SamProgram.h:22