]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamProgramChain.h
Brought API up to compliance with recent SAM Format Spec (v1.4-r962)
[bamtools.git] / src / api / SamProgramChain.h
1 // ***************************************************************************
2 // SamProgramChain.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 19 April 2011 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides methods for operating on a SamProgram record "chain"
9 // ***************************************************************************
10
11 #ifndef SAM_PROGRAMCHAIN_H
12 #define SAM_PROGRAMCHAIN_H
13
14 #include <api/api_global.h>
15 #include <api/SamProgram.h>
16 #include <string>
17 #include <vector>
18
19 namespace BamTools {
20
21 // chain is *NOT* sorted in any order
22 // use First()/Last() to retrieve oldest/newest programs, respectively
23 typedef std::vector<SamProgram>             SamProgramContainer;
24 typedef SamProgramContainer::iterator       SamProgramIterator;
25 typedef SamProgramContainer::const_iterator SamProgramConstIterator;
26
27 class API_EXPORT SamProgramChain {
28
29     // ctor & dtor
30     public:
31         SamProgramChain(void);
32         SamProgramChain(const SamProgramChain& other);
33         ~SamProgramChain(void);
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(void);
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(void);
50         const SamProgram& First(void) const;
51
52         // returns true if chain is empty
53         bool IsEmpty(void) const;
54
55         // returns last (most recent) program in the chain
56         SamProgram& Last(void);
57         const SamProgram& Last(void) const;
58
59         // returns number of program records in the chain
60         int Size(void) 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(void);              // returns iterator to begin()
68         SamProgramConstIterator Begin(void) const;        // returns const_iterator to begin()
69         SamProgramConstIterator ConstBegin(void) const;   // returns const_iterator to begin()
70         SamProgramIterator      End(void);                // returns iterator to end()
71         SamProgramConstIterator End(void) const;          // returns const_iterator to end()
72         SamProgramConstIterator ConstEnd(void) 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