]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamSequenceDictionary.h
Removed explicit keyword from SamHeader-related object copy ctors
[bamtools.git] / src / api / SamSequenceDictionary.h
1 // ***************************************************************************
2 // SamSequenceDictionary.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 sequence entries
9 // *************************************************************************
10
11 #ifndef SAM_SEQUENCE_DICTIONARY_H
12 #define SAM_SEQUENCE_DICTIONARY_H
13
14 #include <api/api_global.h>
15 #include <api/SamSequence.h>
16 #include <string>
17 #include <vector>
18
19 namespace BamTools {
20
21 typedef std::vector<SamSequence>             SamSequenceContainer;
22 typedef SamSequenceContainer::iterator       SamSequenceIterator;
23 typedef SamSequenceContainer::const_iterator SamSequenceConstIterator;
24
25 class API_EXPORT SamSequenceDictionary {
26
27     // ctor & dtor
28     public:
29         SamSequenceDictionary(void);
30         SamSequenceDictionary(const SamSequenceDictionary& other);
31         ~SamSequenceDictionary(void);
32
33     // query/modify sequence data
34     public:
35         // add a sequence
36         void Add(const SamSequence& sequence);
37         void Add(const std::string& sequenceNames);
38
39         // add multiple sequences
40         void Add(const std::vector<SamSequence>& sequences);
41         void Add(const std::vector<std::string>& sequenceNames);
42
43         // clear all sequence records
44         void Clear(void);
45
46         // returns true if dictionary contains this sequence
47         bool Contains(const SamSequence& sequence) const;
48         bool Contains(const std::string& sequenceName) const;
49
50         // returns true if dictionary is empty
51         bool IsEmpty(void) const;
52
53         // remove a single sequence (does nothing if sequence not found)
54         void Remove(const SamSequence& sequence);
55         void Remove(const std::string& sequenceName);
56
57         // remove multiple sequences
58         void Remove(const std::vector<SamSequence>& sequences);
59         void Remove(const std::vector<std::string>& sequenceNames);
60
61         // returns size of dictionary (number of current elements)
62         int Size(void) const;
63
64         // retrieves the SamSequence object associated with this name
65         // if sequenceName is unknown, a new SamSequence is created with this name (and invalid length 0)
66         // and a reference to this new sequence entry is returned (like std::map)
67         //
68         // * To avoid these partial entries being created, it is recommended to check
69         //   for existence first using Contains()
70         SamSequence& operator[](const std::string& sequenceName);
71
72     // retrieve sequence iterators
73     // these are typedefs for STL iterators and thus are compatible with STL containers/algorithms
74     public:
75         SamSequenceIterator      Begin(void);
76         SamSequenceConstIterator Begin(void) const;
77         SamSequenceConstIterator ConstBegin(void) const;
78         SamSequenceIterator      End(void);
79         SamSequenceConstIterator End(void) const;
80         SamSequenceConstIterator ConstEnd(void) const;
81
82     // internal methods
83     private:
84         int IndexOf(const SamSequence& sequence) const;
85         int IndexOf(const std::string& sequenceName) const;
86
87     // data members
88     private:
89         SamSequenceContainer m_data;
90 };
91
92 } // namespace BamTools
93
94 #endif // SAM_SEQUENCE_DICTIONARY 
95