A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sequence/sequence.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_SEQUENCE_SEQUENCE_H_
2 #define GENESIS_SEQUENCE_SEQUENCE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <string>
35 
36 namespace genesis {
37 namespace sequence {
38 
39 class Sequence
40 {
41 public:
42 
43  // -------------------------------------------------------------------------
44  // Typedefs and Enums
45  // -------------------------------------------------------------------------
46 
47  typedef std::string::iterator iterator;
48  typedef std::string::const_iterator const_iterator;
49 
50  // -------------------------------------------------------------------------
51  // Constructors and Rule of Five
52  // -------------------------------------------------------------------------
53 
54  Sequence() = default;
55 
56  Sequence( std::string const& label, std::string const& sites, size_t abundance = 1 )
57  : label_(label)
58  , sites_(sites)
59  , abundance_(abundance)
60  {}
61 
62  ~Sequence() = default;
63 
64  Sequence( Sequence const& ) = default;
65  Sequence( Sequence&& ) = default;
66 
67  Sequence& operator= ( Sequence const& ) = default;
68  Sequence& operator= ( Sequence&& ) = default;
69 
70  void swap( Sequence& other )
71  {
72  using std::swap;
73  swap( label_, other.label_ );
74  swap( sites_, other.sites_ );
75  }
76 
77  // -------------------------------------------------------------------------
78  // Properties
79  // -------------------------------------------------------------------------
80 
81  std::string const& label() const;
82  void label( std::string const& value );
83 
84  std::string const& sites() const;
85  void sites( std::string const& value );
86  void sites( std::string && value );
87  std::string& sites();
88 
89  size_t abundance() const;
90  void abundance( size_t value );
91 
92  void clear();
93 
94  // -------------------------------------------------------------------------
95  // Accessors
96  // -------------------------------------------------------------------------
97 
101  size_t length() const;
102 
106  size_t size() const;
107 
108  char& site_at( size_t index );
109  char site_at( size_t index ) const;
110 
111  char& operator [] (size_t index);
112  char operator [] (size_t index) const;
113 
114  // -------------------------------------------------------------------------
115  // Iterators
116  // -------------------------------------------------------------------------
117 
118  iterator begin();
119  iterator end();
120 
121  const_iterator begin() const;
122  const_iterator end() const;
123 
124  const_iterator cbegin() const;
125  const_iterator cend() const;
126 
127  // -------------------------------------------------------------------------
128  // Data Members
129  // -------------------------------------------------------------------------
130 
131 private:
132 
133  std::string label_;
134  std::string sites_;
135  size_t abundance_ = 1;
136 
137 };
138 
139 } // namespace sequence
140 } // namespace genesis
141 
142 #endif // include guard
size_t abundance() const
Definition: sequence.cpp:82
size_t size() const
Alias for length().
Definition: sequence.cpp:111
Sequence(std::string const &label, std::string const &sites, size_t abundance=1)
void swap(SequenceSet &lhs, SequenceSet &rhs)
std::string::const_iterator const_iterator
size_t length() const
Return the length (number of sites) of this sequence.
Definition: sequence.cpp:106
std::string const & sites() const
Definition: sequence.cpp:58
const_iterator cbegin() const
Definition: sequence.cpp:160
std::string const & label() const
Definition: sequence.cpp:44
const_iterator cend() const
Definition: sequence.cpp:165
char & site_at(size_t index)
Definition: sequence.cpp:116
void swap(Sequence &other)
std::string::iterator iterator
Sequence & operator=(Sequence const &)=default
char & operator[](size_t index)
Definition: sequence.cpp:126