A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
element.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_FORMATS_NEWICK_ELEMENT_H_
2 #define GENESIS_TREE_FORMATS_NEWICK_ELEMENT_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 <stdexcept>
35 #include <string>
36 #include <vector>
37 
38 namespace genesis {
39 namespace tree {
40 
41 // =================================================================================================
42 // Forward Declarations
43 // =================================================================================================
44 
45 class NewickBroker;
46 
47 // =================================================================================================
48 // NewickBrokerElement
49 // =================================================================================================
50 
61 {
62  friend NewickBroker;
63 
64  // -------------------------------------------------------------------------
65  // Constructor and Rule of Five
66  // -------------------------------------------------------------------------
67 
68 public:
73  : depth( -1 )
74  , rank_( -1 )
75  {}
76 
77  ~NewickBrokerElement() = default;
78 
79  NewickBrokerElement(NewickBrokerElement const&) = default;
81 
84 
85  // -------------------------------------------------------------------------
86  // Public Data Members
87  // -------------------------------------------------------------------------
88 
96  std::string name;
97 
104  std::vector<std::string> values;
105 
109  std::vector<std::string> tags;
110 
114  std::vector<std::string> comments;
115 
119  int depth;
120 
121  // -------------------------------------------------------------------------
122  // Additional Members
123  // -------------------------------------------------------------------------
124 
131  int rank() const
132  {
133  if (rank_ < 0) {
134  throw std::logic_error("NewickBroker::assign_ranks() was not called before.");
135  }
136  return rank_;
137  }
138 
142  bool is_root() const
143  {
144  return depth == 0;
145  }
146 
150  bool is_leaf() const
151  {
152  if (rank_ < 0) {
153  throw std::logic_error("NewickBroker::is_leaf() was not called before.");
154  }
155  return rank_ == 0;
156  }
157 
161  bool is_inner() const
162  {
163  if (rank_ < 0) {
164  throw std::logic_error("NewickBroker::is_leaf() was not called before.");
165  }
166  return rank_ != 0;
167  }
168 
169 private:
170 
174  mutable int rank_;
175 };
176 
177 } // namespace tree
178 } // namespace genesis
179 
180 #endif // include guard
std::vector< std::string > values
Numerical values associated with the node, i.e. branch lengths.
Definition: element.hpp:104
NewickBrokerElement()
Constructor, initializes the item values.
Definition: element.hpp:72
int rank() const
Returns the rank (number of immediate children) of this node.
Definition: element.hpp:131
int depth
Depth of the node in the tree, i.e. its distance from the root.
Definition: element.hpp:119
bool is_inner() const
Return whether this is an inner node, i.e., not a leaf node.
Definition: element.hpp:161
std::vector< std::string > comments
Arbitrary strings that can be attached to a node, e.g. in Newick format via "[]". ...
Definition: element.hpp:114
std::vector< std::string > tags
Arbitrary strings that can be attached to a node, e.g. in Newick format via "{}". ...
Definition: element.hpp:109
bool is_root() const
Return whether this is the root node of the tree.
Definition: element.hpp:142
std::string name
Name of the node.
Definition: element.hpp:96
bool is_leaf() const
Return whether this is a leaf node.
Definition: element.hpp:150
Store the information for one element of a Newick tree.
Definition: element.hpp:60
NewickBrokerElement & operator=(NewickBrokerElement const &)=default