]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamReadGroupDictionary.h
Added explicit copy ctors to SamHeader data structures
[bamtools.git] / src / api / SamReadGroupDictionary.h
1 // ***************************************************************************
2 // SamReadGroupDictionary.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 23 December 2010 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides container operations for collection of read group entries
9 // *************************************************************************
10
11 #ifndef SAM_READGROUP_DICTIONARY_H
12 #define SAM_READGROUP_DICTIONARY_H
13
14 #include <api/api_global.h>
15 #include <api/SamReadGroup.h>
16 #include <string>
17 #include <vector>
18
19 namespace BamTools {
20
21 typedef std::vector<SamReadGroup>             SamReadGroupContainer;
22 typedef SamReadGroupContainer::iterator       SamReadGroupIterator;
23 typedef SamReadGroupContainer::const_iterator SamReadGroupConstIterator;
24
25 // stores read groups
26 // can access read groups using SamReadGroup object or (std::string) read group ID tag
27 class API_EXPORT SamReadGroupDictionary {
28
29     // ctor & dtor
30     public:
31         SamReadGroupDictionary(void);
32         explicit SamReadGroupDictionary(const SamReadGroupDictionary& other);
33         ~SamReadGroupDictionary(void);
34
35     // query/modify read group data
36     public:
37         // add a read group
38         void Add(const SamReadGroup& readGroup);
39         void Add(const std::string& readGroupIds);
40
41         // add multiple read groups
42         void Add(const std::vector<SamReadGroup>& readGroups);
43         void Add(const std::vector<std::string>& readGroupIds);
44
45         // clear all read groups records
46         void Clear(void);
47
48         // returns true if dictionary contains this read group
49         bool Contains(const SamReadGroup& readGroup) const;
50         bool Contains(const std::string& readGroupId) const;
51
52         // returns true if dictionary is empty
53         bool IsEmpty(void) const;
54
55         // remove a single read group (does nothing if read group not found)
56         void Remove(const SamReadGroup& readGroup);
57         void Remove(const std::string& readGroupId);
58
59         // remove multiple read groups
60         void Remove(const std::vector<SamReadGroup>& readGroups);
61         void Remove(const std::vector<std::string>& readGroupIds);
62
63         // returns size of dictionary (number of current elements)
64         int Size(void) const;
65
66         // retrieves the SamReadGroup object associated with this ID
67         // if readGroupId is unknown, a new SamReadGroup is created with this ID (and no other data)
68         // and a reference to this new read group entry is returned (like std::map)
69         //
70         // * To avoid these partial entries being created, it is recommended to check
71         //   for existence first using Contains()
72         SamReadGroup& operator[](const std::string& readGroupId);
73
74     // retrieve read group iterators
75     // these are typedefs for STL iterators and thus are compatible with STL containers/algorithms
76     public:
77         SamReadGroupIterator      Begin(void);
78         SamReadGroupConstIterator Begin(void) const;
79         SamReadGroupConstIterator ConstBegin(void) const;
80         SamReadGroupIterator      End(void);
81         SamReadGroupConstIterator End(void) const;
82         SamReadGroupConstIterator ConstEnd(void) const;
83
84     // internal methods
85     private:
86         int IndexOf(const SamReadGroup& readGroup) const;
87         int IndexOf(const std::string& readGroupId) const;
88
89     // data members
90     private:
91         SamReadGroupContainer m_data;
92 };
93
94 } // namespace BamTools
95
96 #endif // SAM_READGROUP_DICTIONARY