A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
taxopath.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
33 #include <stdexcept>
34 
35 namespace genesis {
36 namespace taxonomy {
37 
38 // =================================================================================================
39 // Constructors and Rule of Five
40 // =================================================================================================
41 
48 Taxopath::Taxopath( std::vector< std::string > const& elements )
49  : elements_( elements )
50 {}
51 
58 Taxopath::Taxopath( std::vector< std::string > && elements )
59  : elements_( std::move( elements ))
60 {}
61 
65 void Taxopath::swap( Taxopath& other )
66 {
67  using std::swap;
68  swap( elements_, other.elements_ );
69 }
70 
71 // =================================================================================================
72 // Accessors
73 // =================================================================================================
74 
78 bool Taxopath::empty() const
79 {
80  return elements_.empty();
81 }
82 
86 size_t Taxopath::size() const
87 {
88  return elements_.size();
89 }
90 
96 std::string const& Taxopath::at ( size_t index ) const
97 {
98  return elements_.at( index );
99 }
100 
106 std::string& Taxopath::at ( size_t index )
107 {
108  return elements_.at( index );
109 }
110 
116 std::string const& Taxopath::operator [] ( size_t index ) const
117 {
118  return elements_[ index ];
119 }
120 
126 std::string& Taxopath::operator [] ( size_t index )
127 {
128  return elements_[ index ];
129 }
130 
134 std::vector< std::string > const& Taxopath::elements() const
135 {
136  return elements_;
137 }
138 
142 std::vector< std::string > & Taxopath::elements()
143 {
144  return elements_;
145 }
146 
147 // =================================================================================================
148 // Modifiers
149 // =================================================================================================
150 
157 void Taxopath::assign( std::vector< std::string > const& from )
158 {
159  elements_ = from;
160 }
161 
165 void Taxopath::push_back( std::string const& value )
166 {
167  elements_.push_back( value );
168 }
169 
173 void Taxopath::push_back( std::string&& value )
174 {
175  elements_.push_back( std::move( value ));
176 }
177 
183 std::string Taxopath::pop_back()
184 {
185  if( elements_.empty() ) {
186  throw std::out_of_range( "Cannot pop last element of empty Taxopath." );
187  }
188  auto last = elements_.back();
189  elements_.pop_back();
190  return last;
191 }
192 
197 {
198  elements_.clear();
199 }
200 
201 // =================================================================================================
202 // Iterators
203 // =================================================================================================
204 
209 {
210  return elements_.begin();
211 }
212 
217 {
218  return elements_.end();
219 }
220 
225 {
226  return elements_.cbegin();
227 }
228 
233 {
234  return elements_.cend();
235 }
236 
241 {
242  return elements_.rbegin();
243 }
244 
249 {
250  return elements_.rend();
251 }
252 
257 {
258  return elements_.crbegin();
259 }
260 
265 {
266  return elements_.crend();
267 }
268 
269 } // namespace taxonomy
270 } // namespace genesis
iterator begin()
Return an iterator to the beginning of the taxonomic elements.
Definition: taxopath.cpp:208
iterator end()
Return an iterator to the end of the taxonomic elements.
Definition: taxopath.cpp:216
std::string const & at(size_t index) const
Return the taxonomic element at a certain position.
Definition: taxopath.cpp:96
std::vector< std::string > const & elements() const
Return the elements of the Taxopath as a vector of strings.
Definition: taxopath.cpp:134
void assign(std::vector< std::string > const &from)
Replace the current elements of the Taxopath by a list of strings.
Definition: taxopath.cpp:157
void swap(SequenceSet &lhs, SequenceSet &rhs)
void clear()
Clear all taxonomic elements. This results in an empty Taxopath.
Definition: taxopath.cpp:196
std::vector< std::string >::const_reverse_iterator const_reverse_iterator
Definition: taxopath.hpp:92
void push_back(std::string const &value)
Add an element to the end of the Taxopath by copying it.
Definition: taxopath.cpp:165
std::vector< std::string >::reverse_iterator reverse_iterator
Definition: taxopath.hpp:91
std::string const & operator[](size_t index) const
Return the taxonomic element at a certain position.
Definition: taxopath.cpp:116
bool empty() const
Return whether the Taxopath is empty, i.e., does not contain any elements.
Definition: taxopath.cpp:78
reverse_iterator rbegin()
Return a reverse iterator to the reverse beginning of the taxonomic elements.
Definition: taxopath.cpp:240
std::vector< std::string >::const_iterator const_iterator
Definition: taxopath.hpp:90
std::string pop_back()
Remove the last element of the Taxopath and return its value.
Definition: taxopath.cpp:183
Helper class to store a taxonomic path.
Definition: taxopath.hpp:81
size_t size() const
Return the number of elements of this Taxopath.
Definition: taxopath.cpp:86
std::vector< std::string >::iterator iterator
Definition: taxopath.hpp:89
reverse_iterator rend()
Return a reverse iterator to the reverse end of the taxonomic elements.
Definition: taxopath.cpp:248
void swap(Taxopath &other)
Swap the elements of two Taxopaths.
Definition: taxopath.cpp:65