A library for working with phylogenetic and population genetic data.
v0.32.0
subtree.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_TREE_SUBTREE_H_
2 #define GENESIS_TREE_TREE_SUBTREE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2019 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 "genesis/tree/tree.hpp"
35 
36 namespace genesis {
37 namespace tree {
38 
39 // =============================================================================
40 // Subtree
41 // =============================================================================
42 
69 class Subtree
70 {
71 public:
72 
73  // -------------------------------------------------------------
74  // Declarations and Constructor
75  // -------------------------------------------------------------
76 
77  // /* *
78  // * @ brief Default construct a subtree that does .
79  // */
80  // Subtree() = default;
81 
86  explicit Subtree( TreeLink const& link )
87  : link_( &link )
88  {}
89 
94  explicit Subtree( TreeNode const& node )
95  : link_( &node.primary_link() )
96  {}
97 
104  Subtree( TreeEdge const& edge, bool use_primary = false )
105  : link_( use_primary ? &edge.primary_link() : &edge.secondary_link() )
106  {}
107 
108  ~Subtree() = default;
109 
110  Subtree( Subtree const& ) = default;
111  Subtree( Subtree&& ) = default;
112 
113  Subtree& operator= ( Subtree const& ) = default;
114  Subtree& operator= ( Subtree&& ) = default;
115 
116  // -------------------------------------------------------------
117  // Member Functions
118  // -------------------------------------------------------------
119 
125  TreeLink const& link() const
126  {
127  return *link_;
128  }
129 
133  TreeNode const& node() const
134  {
135  return link_->node();
136  }
137 
141  TreeEdge const& edge() const
142  {
143  return link_->edge();
144  }
145 
149  void invert()
150  {
151  link_ = &link_->outer();
152  }
153 
154  // /**
155  // * @brief Return whether this subtree points to something, or was default constructed.
156  // */
157  // operator bool() const
158  // {
159  // return link_ == nullptr;
160  // }
161 
162  // -------------------------------------------------------------
163  // Member Variables
164  // -------------------------------------------------------------
165 
166 protected:
167 
168  TreeLink const* link_ = nullptr;
169 
170 };
171 
172 } // namespace tree
173 } // namespace genesis
174 
175 #endif // include guard
genesis::tree::Subtree::node
TreeNode const & node() const
Get the TreeNode at which the subtree starts.
Definition: subtree.hpp:133
genesis::tree::Subtree::link
TreeLink const & link() const
Get the TreeLink that separates the subtree from the rest of the tree.
Definition: subtree.hpp:125
genesis::tree::Subtree::operator=
Subtree & operator=(Subtree const &)=default
genesis::tree::Subtree::Subtree
Subtree(TreeEdge const &edge, bool use_primary=false)
Construct a Subtree in one of the two directions of a given TreeEdge.
Definition: subtree.hpp:104
tree.hpp
Header of Tree class.
genesis::tree::Subtree::Subtree
Subtree(TreeNode const &node)
Construct a Subtree representing the given TreeNode and the part of the Tree away from its root node.
Definition: subtree.hpp:94
genesis::tree::Subtree::edge
TreeEdge const & edge() const
Get the TreeEdge that separates the subtree from the rest of the tree.
Definition: subtree.hpp:141
genesis::tree::Subtree::~Subtree
~Subtree()=default
genesis::tree::Subtree
Reference to a subtree of a Tree.
Definition: subtree.hpp:69
genesis::tree::Subtree::invert
void invert()
Invert/flip the subtree to represent the other (complementary) part of the tree.
Definition: subtree.hpp:149
genesis::tree::TreeEdge
Definition: edge.hpp:60
genesis::tree::TreeNode
Definition: tree/tree/node.hpp:58
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::tree::Subtree::link_
TreeLink const * link_
Definition: subtree.hpp:168
genesis::tree::Subtree::Subtree
Subtree(TreeLink const &link)
Construct a Subtree that contains all of the tree except for the part that the outer() link of the gi...
Definition: subtree.hpp:86