A library for working with phylogenetic and population genetic data.
v0.27.0
taxopath_parser.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TAXONOMY_FORMATS_TAXOPATH_PARSER_H_
2 #define GENESIS_TAXONOMY_FORMATS_TAXOPATH_PARSER_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 Taxopath;
46 
47 // =================================================================================================
48 // Taxopath Parser
49 // =================================================================================================
50 
82 {
83 public:
84 
85  // -------------------------------------------------------------------------
86  // Constructors and Rule of Five
87  // -------------------------------------------------------------------------
88 
89  TaxopathParser() = default;
90  ~TaxopathParser() = default;
91 
92  TaxopathParser( TaxopathParser const& ) = default;
93  TaxopathParser( TaxopathParser&& ) = default;
94 
95  TaxopathParser& operator= ( TaxopathParser const& ) = default;
97 
98  // -------------------------------------------------------------------------
99  // Parsing
100  // -------------------------------------------------------------------------
101 
107  Taxopath parse( std::string const& taxopath ) const;
108 
118  Taxopath parse( Taxon const& taxon ) const;
119 
120  // -------------------------------------------------------------------------
121  // Properties
122  // -------------------------------------------------------------------------
123 
138  TaxopathParser& delimiters( std::string const& value )
139  {
140  delimiters_ = value;
141  return *this;
142  }
143 
149  std::string delimiters() const
150  {
151  return delimiters_;
152  }
153 
171  {
172  trim_whitespaces_ = value;
173  return *this;
174  }
175 
181  bool trim_whitespaces() const
182  {
183  return trim_whitespaces_;
184  }
185 
198  {
199  remove_trailing_delimiter_ = value;
200  return *this;
201  }
202 
210  {
211  return remove_trailing_delimiter_;
212  }
213 
214  // -------------------------------------------------------------------------
215  // Data Members
216  // -------------------------------------------------------------------------
217 
218 private:
219 
220  std::string delimiters_ = ";";
221  bool trim_whitespaces_ = true;
222  bool remove_trailing_delimiter_ = true;
223 
224 };
225 
226 } // namespace taxonomy
227 } // namespace genesis
228 
229 #endif // include guard
genesis::taxonomy::TaxopathParser::delimiters
TaxopathParser & delimiters(std::string const &value)
Set the chars used to split the taxonomic path string.
Definition: taxopath_parser.hpp:138
genesis::taxonomy::TaxopathParser::remove_trailing_delimiter
bool remove_trailing_delimiter() const
Return whether currently trailing delimiters are removed from the taxonomic path string.
Definition: taxopath_parser.hpp:209
genesis::taxonomy::Taxon
Store a Taxon, i.e., an element in a Taxonomy, with its name, rank, ID and sub-taxa.
Definition: taxon.hpp:76
genesis::taxonomy::Taxopath
Helper class to store a taxonomic path.
Definition: taxopath.hpp:83
genesis::taxonomy::TaxopathParser::operator=
TaxopathParser & operator=(TaxopathParser const &)=default
genesis::taxonomy::TaxopathParser::parse
Taxopath parse(std::string const &taxopath) const
Parse a taxonomic path string into a Taxopath object and return it.
Definition: taxopath_parser.cpp:48
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::taxonomy::TaxopathParser::remove_trailing_delimiter
TaxopathParser & remove_trailing_delimiter(bool value)
Set whether to remove an empty taxonomic element at the end, if it occurs.
Definition: taxopath_parser.hpp:197
genesis::taxonomy::TaxopathParser::TaxopathParser
TaxopathParser()=default
genesis::taxonomy::TaxopathParser::delimiters
std::string delimiters() const
Return the currelty set delimiter chars used to split the taxonomic path string.
Definition: taxopath_parser.hpp:149
genesis::taxonomy::TaxopathParser::trim_whitespaces
TaxopathParser & trim_whitespaces(bool value)
Set whether to trim whitespaces around the taxonomic elements after splitting them.
Definition: taxopath_parser.hpp:170
genesis::taxonomy::TaxopathParser
Helper class to parse a string containing a taxonomic path string into a Taxopath object.
Definition: taxopath_parser.hpp:81
genesis::taxonomy::TaxopathParser::trim_whitespaces
bool trim_whitespaces() const
Return the currently set value whether whitespaces are trimmed off the taxonomic elements.
Definition: taxopath_parser.hpp:181
genesis::taxonomy::TaxopathParser::~TaxopathParser
~TaxopathParser()=default