A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
taxonomy_writer.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TAXONOMY_FORMATS_TAXONOMY_WRITER_H_
2 #define GENESIS_TAXONOMY_FORMATS_TAXONOMY_WRITER_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 
36 
37 #include <iosfwd>
38 #include <string>
39 
40 namespace genesis {
41 namespace taxonomy {
42 
43 // =================================================================================================
44 // Taxonomy Writer
45 // =================================================================================================
46 
51 {
52 public:
53 
54  // ---------------------------------------------------------------------
55  // Constructor and Rule of Five
56  // ---------------------------------------------------------------------
57 
58  TaxonomyWriter() = default;
59  ~TaxonomyWriter() = default;
60 
61  TaxonomyWriter( TaxonomyWriter const& ) = default;
62  TaxonomyWriter( TaxonomyWriter&& ) = default;
63 
64  TaxonomyWriter& operator= ( TaxonomyWriter const& ) = default;
66 
67  // ---------------------------------------------------------------------
68  // Writing
69  // ---------------------------------------------------------------------
70 
71  void to_stream ( Taxonomy const& tax, std::ostream& os ) const;
72  void to_file ( Taxonomy const& tax, std::string const& fn ) const;
73  std::string to_string ( Taxonomy const& tax ) const;
74 
75  // ---------------------------------------------------------------------
76  // Properties
77  // ---------------------------------------------------------------------
78 
79 public:
80 
82  {
83  return tax_gen_;
84  }
85 
86  TaxonomyWriter& write_ids( bool value )
87  {
88  write_ids_ = value;
89  return *this;
90  }
91 
92  bool write_ids() const
93  {
94  return write_ids_;
95  }
96 
97  TaxonomyWriter& write_ranks( bool value )
98  {
99  write_ranks_ = value;
100  return *this;
101  }
102 
103  bool write_ranks() const
104  {
105  return write_ranks_;
106  }
107 
108  // ---------------------------------------------------------------------
109  // Members
110  // ---------------------------------------------------------------------
111 
112 private:
113 
114  bool write_ids_ = true;
115  bool write_ranks_ = true;
116 
117  TaxopathGenerator tax_gen_;
118 
119 };
120 
121 } // namespace taxonomy
122 } // namespace genesis
123 
124 #endif // include guard
Helper class to generate a taxonomic path string from a Taxopath object or a Taxon.
void to_stream(Taxonomy const &tax, std::ostream &os) const
TaxonomyWriter & write_ranks(bool value)
Store a Taxonomy, i.e., a nested hierarchy of Taxa.
void to_file(Taxonomy const &tax, std::string const &fn) const
TaxonomyWriter & operator=(TaxonomyWriter const &)=default
TaxonomyWriter & write_ids(bool value)
Write a Taxonomy as a list of Taxopaths.
TaxopathGenerator & taxopath_generator()
std::string to_string(Taxonomy const &tax) const