A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-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 #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 
102  Taxopath from_string( std::string const& taxopath ) const;
103  Taxopath operator() ( std::string const& taxopath ) const;
104 
105  Taxopath from_taxon( Taxon const& taxon ) const;
106  Taxopath operator() ( Taxon const& taxon ) const;
107 
108  // -------------------------------------------------------------------------
109  // Properties
110  // -------------------------------------------------------------------------
111 
112  TaxopathParser& delimiters( std::string const& value );
113  std::string delimiters() const;
114 
115  TaxopathParser& trim_whitespaces( bool value );
116  bool trim_whitespaces() const;
117 
119  bool remove_trailing_delimiter() const;
120 
121  // -------------------------------------------------------------------------
122  // Data Members
123  // -------------------------------------------------------------------------
124 
125 private:
126 
127  std::string delimiters_ = ";";
128  bool trim_whitespaces_ = true;
129  bool remove_trailing_delimiter_ = true;
130 
131 };
132 
133 } // namespace taxonomy
134 } // namespace genesis
135 
136 #endif // include guard
bool trim_whitespaces() const
Return the currently set value whether whitespaces are trimmed off the taxonomic elements.
Taxopath operator()(std::string const &taxopath) const
Shortcut function alias for from_string().
bool remove_trailing_delimiter() const
Return whether currently trailing delimiters are removed from the taxonomic path string.
std::string delimiters() const
Return the currelty set delimiter chars used to split the taxonomic path string.
Store a Taxon, i.e., an element in a Taxonomy, with its name, rank, ID and sub-taxa.
Definition: taxon.hpp:76
Helper class to store a taxonomic path.
Definition: taxopath.hpp:81
Helper class to parse a string containing a taxonomic path string into a Taxopath object...
Taxopath from_string(std::string const &taxopath) const
Parse a taxonomic path string into a Taxopath object and return it.
Taxopath from_taxon(Taxon const &taxon) const
Helper function to turn a Taxon into a Taxopath.
TaxopathParser & operator=(TaxopathParser const &)=default