A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
taxopath.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TAXONOMY_TAXOPATH_H_
2 #define GENESIS_TAXONOMY_TAXOPATH_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 #include <vector>
36 
37 namespace genesis {
38 namespace taxonomy {
39 
40 // =================================================================================================
41 // Forward Declarations
42 // =================================================================================================
43 
44 class Taxon;
45 class Taxonomy;
46 
47 // =================================================================================================
48 // Taxopath
49 // =================================================================================================
50 
81 class Taxopath
82 {
83 public:
84 
85  // -------------------------------------------------------------------------
86  // Typedefs and Enums
87  // -------------------------------------------------------------------------
88 
89  typedef std::vector< std::string >::iterator iterator;
90  typedef std::vector< std::string >::const_iterator const_iterator;
91  typedef std::vector< std::string >::reverse_iterator reverse_iterator;
92  typedef std::vector< std::string >::const_reverse_iterator const_reverse_iterator;
93 
94  // -------------------------------------------------------------------------
95  // Constructors and Rule of Five
96  // -------------------------------------------------------------------------
97 
98  Taxopath() = default;
99  ~Taxopath() = default;
100 
101  explicit Taxopath( std::vector< std::string > const& elements );
102  explicit Taxopath( std::vector< std::string > && elements );
103 
104  Taxopath( Taxopath const& ) = default;
105  Taxopath( Taxopath&& ) = default;
106 
107  Taxopath& operator= ( Taxopath const& ) = default;
108  Taxopath& operator= ( Taxopath&& ) = default;
109 
110  void swap( Taxopath& other );
111 
112  // -------------------------------------------------------------------------
113  // Accessors
114  // -------------------------------------------------------------------------
115 
116  bool empty() const;
117  size_t size() const;
118 
119  std::string const& at ( size_t index ) const;
120  std::string& at ( size_t index );
121 
122  std::string const& operator [] ( size_t index ) const;
123  std::string& operator [] ( size_t index );
124 
125  std::vector< std::string > const& elements() const;
126  std::vector< std::string > & elements();
127 
128  // -------------------------------------------------------------------------
129  // Modifiers
130  // -------------------------------------------------------------------------
131 
132  void assign( std::vector< std::string > const& from );
133 
134  void push_back( std::string const& value );
135  void push_back( std::string&& value );
136 
137  std::string pop_back();
138 
139  void clear();
140 
141  // -------------------------------------------------------------------------
142  // Iterators
143  // -------------------------------------------------------------------------
144 
145  iterator begin();
146  iterator end();
147 
148  const_iterator begin() const;
149  const_iterator end() const;
150 
153 
156 
157  // -------------------------------------------------------------------------
158  // Data Members
159  // -------------------------------------------------------------------------
160 
161 private:
162 
163  std::vector< std::string > elements_;
164 };
165 
166 } // namespace taxonomy
167 } // namespace genesis
168 
169 #endif // include guard
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 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
Taxopath & operator=(Taxopath const &)=default
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