]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamSequenceDictionary.h
Minor cleanup
[bamtools.git] / src / api / SamSequenceDictionary.h
1 // ***************************************************************************
2 // SamSequenceDictionary.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 18 April 2011
6 // ---------------------------------------------------------------------------
7 // Provides methods for operating on a collection of SamSequence entries.
8 // ***************************************************************************
9
10 #ifndef SAM_SEQUENCE_DICTIONARY_H
11 #define SAM_SEQUENCE_DICTIONARY_H
12
13 #include <api/api_global.h>
14 #include <api/SamSequence.h>
15 #include <string>
16 #include <map>
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         // adds a sequence
36         void Add(const SamSequence& sequence);
37         void Add(const std::string& name, const int& length);
38
39         // adds multiple sequences
40         void Add(const std::vector<SamSequence>& sequences);
41         void Add(const std::map<std::string, int>& sequenceMap);
42
43         // clears all sequence entries
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         // removes sequence, if found
54         void Remove(const SamSequence& sequence);
55         void Remove(const std::string& sequenceName);
56
57         // removes multiple sequences
58         void Remove(const std::vector<SamSequence>& sequences);
59         void Remove(const std::vector<std::string>& sequenceNames);
60
61         // returns number of sequences in dictionary
62         int Size(void) const;
63
64         // retrieves a modifiable reference to the SamSequence object associated with this name
65         SamSequence& operator[](const std::string& sequenceName);
66
67     // retrieve STL-compatible iterators
68     public:
69         SamSequenceIterator      Begin(void);               // returns iterator to begin()
70         SamSequenceConstIterator Begin(void) const;         // returns const_iterator to begin()
71         SamSequenceConstIterator ConstBegin(void) const;    // returns const_iterator to begin()
72         SamSequenceIterator      End(void);                 // returns iterator to end()
73         SamSequenceConstIterator End(void) const;           // returns const_iterator to end()
74         SamSequenceConstIterator ConstEnd(void) const;      // returns const_iterator to end()
75
76     // internal methods
77     private:
78         int IndexOf(const std::string& name) const;
79
80     // data members
81     private:
82         SamSequenceContainer m_data;
83 };
84
85 } // namespace BamTools
86
87 #endif // SAM_SEQUENCE_DICTIONARY_H
88