A library for working with phylogenetic and population genetic data.
v0.27.0
nested.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TAXONOMY_PRINTERS_NESTED_H_
2 #define GENESIS_TAXONOMY_PRINTERS_NESTED_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 <iosfwd>
35 #include <string>
36 
37 namespace genesis {
38 namespace taxonomy {
39 
40 // =================================================================================================
41 // Forward Declarations
42 // =================================================================================================
43 
44 class Taxonomy;
45 
46 // =================================================================================================
47 // PrinterNested
48 // =================================================================================================
49 
54 {
55 public:
56 
57  // -------------------------------------------------------------------------
58  // Constructors and Rule of Five
59  // -------------------------------------------------------------------------
60 
61  PrinterNested() = default;
62  ~PrinterNested() = default;
63 
64  PrinterNested( PrinterNested const& ) = default;
65  PrinterNested( PrinterNested&& ) = default;
66 
67  PrinterNested& operator= ( PrinterNested const& ) = default;
68  PrinterNested& operator= ( PrinterNested&& ) = default;
69 
70  // -------------------------------------------------------------------------
71  // Print
72  // -------------------------------------------------------------------------
73 
74  void print(
75  std::ostream& out,
76  Taxonomy const& tax
77  ) const;
78 
79  std::string print(
80  Taxonomy const& tax
81  ) const;
82 
83  std::string operator() (
84  Taxonomy const& tax
85  ) const;
86 
87  // -------------------------------------------------------------------------
88  // Properties
89  // -------------------------------------------------------------------------
90 
91  PrinterNested& line_limit( int value );
92  int line_limit() const;
93 
94  PrinterNested& depth_limit( int value );
95  int depth_limit() const;
96 
97  PrinterNested& print_ranks( bool value );
98  bool print_ranks() const;
99 
100  PrinterNested& print_ids( bool value );
101  bool print_ids() const;
102 
103  // -------------------------------------------------------------------------
104  // Internal Functions
105  // -------------------------------------------------------------------------
106 
107 private:
108 
109  bool print_to_ostream(
110  std::ostream& out,
111  Taxonomy const& tax,
112  size_t depth,
113  size_t& lines
114  ) const;
115 
116  // -------------------------------------------------------------------------
117  // Data Members
118  // -------------------------------------------------------------------------
119 
120 private:
121 
122  int line_limit_ = -1;
123  int depth_limit_ = -1;
124  bool print_ranks_ = true;
125  bool print_ids_ = true;
126 };
127 
128 } // namespace taxonomy
129 } // namespace genesis
130 
131 #endif // include guard
genesis::taxonomy::PrinterNested::operator=
PrinterNested & operator=(PrinterNested const &)=default
genesis::taxonomy::PrinterNested::print_ranks
bool print_ranks() const
Definition: nested.cpp:149
genesis::taxonomy::PrinterNested::print
void print(std::ostream &out, Taxonomy const &tax) const
Definition: nested.cpp:45
genesis::taxonomy::PrinterNested::PrinterNested
PrinterNested()=default
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::Taxonomy
Store a Taxonomy, i.e., a nested hierarchy of Taxa.
Definition: taxonomy/taxonomy.hpp:96
genesis::taxonomy::PrinterNested::depth_limit
int depth_limit() const
Definition: nested.cpp:138
genesis::taxonomy::PrinterNested::print_ids
bool print_ids() const
Definition: nested.cpp:160
genesis::taxonomy::PrinterNested
Simple printer class for Taxonomy.
Definition: nested.hpp:53
genesis::taxonomy::PrinterNested::line_limit
int line_limit() const
Definition: nested.cpp:127
genesis::taxonomy::PrinterNested::operator()
std::string operator()(Taxonomy const &tax) const
Definition: nested.cpp:61
genesis::taxonomy::PrinterNested::~PrinterNested
~PrinterNested()=default