A toolkit for working with phylogenetic data.
v0.19.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 )
57  : label_(label)
58  , sites_(sites)
59  {}
60 
61  ~Sequence() = default;
62 
63  Sequence( Sequence const& ) = default;
64  Sequence( Sequence&& ) = default;
65 
66  Sequence& operator= ( Sequence const& ) = default;
67  Sequence& operator= ( Sequence&& ) = default;
68 
69  void swap( Sequence& other )
70  {
71  using std::swap;
72  swap( label_, other.label_ );
73  swap( sites_, other.sites_ );
74  }
75 
76  // -------------------------------------------------------------------------
77  // Properties
78  // -------------------------------------------------------------------------
79 
80  std::string const& label() const;
81  void label( std::string const& value );
82 
83  std::string const& sites() const;
84  void sites( std::string const& value );
85  void sites( std::string && value );
86  std::string& sites();
87 
88  void clear();
89 
90  // -------------------------------------------------------------------------
91  // Accessors
92  // -------------------------------------------------------------------------
93 
97  size_t length() const;
98 
102  size_t size() const;
103 
104  char& site_at( size_t index );
105  char site_at( size_t index ) const;
106 
107  char& operator [] (size_t index);
108  char operator [] (size_t index) const;
109 
110  // -------------------------------------------------------------------------
111  // Iterators
112  // -------------------------------------------------------------------------
113 
114  iterator begin();
115  iterator end();
116 
117  const_iterator begin() const;
118  const_iterator end() const;
119 
120  const_iterator cbegin() const;
121  const_iterator cend() const;
122 
123  // -------------------------------------------------------------------------
124  // Data Members
125  // -------------------------------------------------------------------------
126 
127 private:
128 
129  std::string label_;
130  std::string sites_;
131 };
132 
133 } // namespace sequence
134 } // namespace genesis
135 
136 #endif // include guard
size_t size() const
Alias for length().
Definition: sequence.cpp:97
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:92
std::string const & sites() const
Definition: sequence.cpp:58
const_iterator cbegin() const
Definition: sequence.cpp:146
Sequence(std::string const &label, std::string const &sites)
std::string const & label() const
Definition: sequence.cpp:44
const_iterator cend() const
Definition: sequence.cpp:151
char & site_at(size_t index)
Definition: sequence.cpp:102
void swap(Sequence &other)
std::string::iterator iterator
Sequence & operator=(Sequence const &)=default
char & operator[](size_t index)
Definition: sequence.cpp:112