A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tree/tree.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_TREE_H_
2 #define GENESIS_TREE_TREE_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 
44 
46 
47 #include <memory>
48 #include <vector>
49 
50 namespace genesis {
51 namespace tree {
52 
53 // =================================================================================================
54 // Forward Declarations
55 // =================================================================================================
56 
57 class Tree;
58 bool validate_topology( Tree const& tree );
59 
60 // =================================================================================================
61 // Tree
62 // =================================================================================================
63 
95 class Tree
96 {
97 public:
98 
99  // -------------------------------------------------------------------------
100  // Typedefs
101  // -------------------------------------------------------------------------
102 
107  template< class T >
108  using ContainerType = std::vector< std::unique_ptr< T >>;
109 
114 
119 
124 
127 
130 
133 
134  // -------------------------------------------------------------------------
135  // Construction and Rule of Five
136  // -------------------------------------------------------------------------
137 
138  Tree() = default;
139  ~Tree() = default;
140 
141  Tree( Tree const& other );
142  Tree( Tree&& ) = default;
143 
144  Tree& operator= ( Tree const& other );
145  Tree& operator= ( Tree&& ) = default;
146 
147  Tree clone_topology() const;
148  void swap( Tree& other );
149 
150  void clear();
151 
152  // -------------------------------------------------------------------------
153  // Accessors
154  // -------------------------------------------------------------------------
155 
156  bool empty() const;
157 
158  TreeLink & root_link();
159  TreeLink const& root_link() const;
160 
161  TreeNode & root_node();
162  TreeNode const& root_node() const;
163 
164  TreeLink & link_at(size_t index);
165  TreeLink const& link_at(size_t index) const;
166 
167  TreeNode & node_at(size_t index);
168  TreeNode const& node_at(size_t index) const;
169 
170  TreeEdge & edge_at(size_t index);
171  TreeEdge const& edge_at(size_t index) const;
172 
173  size_t link_count() const;
174  size_t node_count() const;
175  size_t edge_count() const;
176 
177  // -------------------------------------------------------------------------
178  // Data Accessors
179  // -------------------------------------------------------------------------
180 
181  Tree& reset_root_link_index( size_t val );
182 
186 
187  // -------------------------------------------------------------------------
188  // Iterators
189  // -------------------------------------------------------------------------
190 
191  // -----------------------------------------------------
192  // Links
193  // -----------------------------------------------------
194 
197 
200 
203 
204  // -----------------------------------------------------
205  // Nodes
206  // -----------------------------------------------------
207 
210 
213 
216 
217  // -----------------------------------------------------
218  // Edges
219  // -----------------------------------------------------
220 
223 
226 
229 
230  // -------------------------------------------------------------------------
231  // Debug and Dump
232  // -------------------------------------------------------------------------
233 
239  friend bool validate_topology( Tree const& tree );
240 
241  // -------------------------------------------------------------------------
242  // Data Members
243  // -------------------------------------------------------------------------
244 
245 private:
246 
247  size_t root_link_index_ = 0;
248 
249  LinkContainerType links_;
250  NodeContainerType nodes_;
251  EdgeContainerType edges_;
252 
253 };
254 
255 } // namespace tree
256 } // namespace genesis
257 
258 #endif // include guard
IteratorEdges begin_edges()
Definition: tree/tree.cpp:498
ContainerType< TreeEdge > EdgeContainerType
Alias for the container type that is used to store TreeEdges.
Definition: tree/tree.hpp:123
IteratorEdges end_edges()
Definition: tree/tree.cpp:503
typename ContainerType< TreeEdge >::const_iterator ConstIteratorEdges
Definition: tree/tree.hpp:132
typename ContainerType< TreeLink >::const_iterator ConstIteratorLinks
Definition: tree/tree.hpp:126
IteratorLinks end_links()
Definition: tree/tree.cpp:435
typename ContainerType< TreeNode >::iterator IteratorNodes
Definition: tree/tree.hpp:128
TreeNode & node_at(size_t index)
Return the TreeNode at a certain index.
Definition: tree/tree.cpp:304
friend bool validate_topology(Tree const &tree)
Validate the correctness of all Tree pointers etc.
utils::Range< IteratorNodes > nodes()
Definition: tree/tree.cpp:484
typename ContainerType< TreeNode >::const_iterator ConstIteratorNodes
Definition: tree/tree.hpp:129
TreeLink & link_at(size_t index)
Return the TreeLink at a certain index.
Definition: tree/tree.cpp:284
IteratorNodes end_nodes()
Definition: tree/tree.cpp:469
TreeNode & root_node()
Return the TreeNode at the current root of the Tree.
Definition: tree/tree.cpp:258
size_t node_count() const
Return the number of TreeNodes of the Tree.
Definition: tree/tree.cpp:350
ContainerType< TreeNode > NodeContainerType
Alias for the container type that is used to store TreeNodes.
Definition: tree/tree.hpp:118
utils::Range< IteratorEdges > edges()
Definition: tree/tree.cpp:518
Tree & operator=(Tree const &other)
Assignment operator.
Definition: tree/tree.cpp:119
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
bool empty() const
Return whether the Tree is empty (i.e., has no nodes, edges and links).
Definition: tree/tree.cpp:222
Tree clone_topology() const
Return a Tree with the same topology, but without any data.
Definition: tree/tree.cpp:137
void swap(Tree &other)
Swap.
Definition: tree/tree.cpp:191
bool validate_topology(Tree const &tree)
Validate that all internal pointers of the Tree elements (TreeLinks, TreeNodes, TreeEdges) to each ot...
LinkContainerType & expose_link_container()
Get the container that stores all TreeLinks of the Tree.
Definition: tree/tree.cpp:393
IteratorNodes begin_nodes()
Definition: tree/tree.cpp:464
utils::Range< IteratorLinks > links()
Definition: tree/tree.cpp:450
typename ContainerType< TreeLink >::iterator IteratorLinks
Definition: tree/tree.hpp:125
size_t edge_count() const
Return the number of TreeEdges of the Tree.
Definition: tree/tree.cpp:358
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
Definition: tree/tree.cpp:324
void clear()
Deletes all data of the tree, including all links, nodes and edges.
Definition: tree/tree.cpp:207
ContainerType< TreeLink > LinkContainerType
Alias for the container type that is used to store TreeLinks.
Definition: tree/tree.hpp:113
TreeLink & root_link()
Return the TreeLink at the current root of the Tree.
Definition: tree/tree.cpp:232
Tree & reset_root_link_index(size_t val)
Reset the index of the link that is considered to be the root of the Tree.
Definition: tree/tree.cpp:377
std::vector< std::unique_ptr< T >> ContainerType
Alias for the container type that is used to store TreeLinks, TreeNodes and TreeEdges.
Definition: tree/tree.hpp:108
IteratorLinks begin_links()
Definition: tree/tree.cpp:430
EdgeContainerType & expose_edge_container()
Get the container that stores all TreeEdges of the Tree.
Definition: tree/tree.cpp:417
size_t link_count() const
Return the number of TreeLinks of the Tree.
Definition: tree/tree.cpp:342
NodeContainerType & expose_node_container()
Get the container that stores all TreeNodes of the Tree.
Definition: tree/tree.cpp:405
typename ContainerType< TreeEdge >::iterator IteratorEdges
Definition: tree/tree.hpp:131