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