A library for working with phylogenetic and population genetic data.
v0.27.0
bipartition.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_BIPARTITION_BIPARTITION_H_
2 #define GENESIS_TREE_BIPARTITION_BIPARTITION_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"
37 
38 #include <stdexcept>
39 
40 namespace genesis {
41 namespace tree {
42 
43 // =============================================================================
44 // Bipartition
45 // =============================================================================
46 
48 {
49 public:
50 
51  // -------------------------------------------------------------
52  // Declarations and Constructor
53  // -------------------------------------------------------------
54 
55  Bipartition() = default;
56 
58  : link_( &link )
60  {}
61 
62  ~Bipartition() = default;
63 
64  Bipartition( Bipartition const& ) = default;
65  Bipartition( Bipartition&& ) = default;
66 
67  Bipartition& operator= ( Bipartition const& ) = default;
68  Bipartition& operator= ( Bipartition&& ) = default;
69 
70  // -------------------------------------------------------------
71  // Member Functions
72  // -------------------------------------------------------------
73 
74  Subtree subtree() const
75  {
76  if( empty() ) {
77  throw std::runtime_error( "Cannot return Subtree for empty Bipartition." );
78  }
79  return Subtree( *link_ );
80  }
81 
82  TreeLink const& link() const
83  {
84  return *link_;
85  }
86 
88  {
89  return leaf_nodes_;
90  }
91 
93  {
94  return leaf_nodes_;
95  }
96 
97  void invert()
98  {
100  link_ = &link_->outer();
101  }
102 
103  bool empty() const
104  {
105  return link_ == nullptr;
106  }
107 
108  // -------------------------------------------------------------
109  // Member Variables
110  // -------------------------------------------------------------
111 
112 protected:
113 
114  TreeLink const* link_ = nullptr;
116 
117 };
118 
119 } // namespace tree
120 } // namespace genesis
121 
122 #endif // include guard
genesis::tree::Bipartition::leaf_nodes
utils::Bitvector const & leaf_nodes() const
Definition: bipartition.hpp:92
genesis::tree::Bipartition::Bipartition
Bipartition()=default
tree.hpp
Header of Tree class.
genesis::tree::Bipartition::operator=
Bipartition & operator=(Bipartition const &)=default
genesis::tree::Bipartition::subtree
Subtree subtree() const
Definition: bipartition.hpp:74
genesis::tree::Bipartition::bitvector
utils::Bitvector & bitvector()
Definition: bipartition.hpp:87
genesis::tree::Bipartition::invert
void invert()
Definition: bipartition.hpp:97
genesis::tree::Bipartition::Bipartition
Bipartition(TreeLink const &link, utils::Bitvector const &leaf_nodes)
Definition: bipartition.hpp:57
genesis::tree::Bipartition::empty
bool empty() const
Definition: bipartition.hpp:103
subtree.hpp
genesis::utils::Bitvector::negate
void negate()
Flip all bits.
Definition: bitvector.cpp:270
genesis::tree::Subtree
Reference to a subtree of a Tree.
Definition: subtree.hpp:69
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::Bipartition
Definition: bipartition.hpp:47
genesis::tree::Bipartition::link
TreeLink const & link() const
Definition: bipartition.hpp:82
bitvector.hpp
genesis::tree::Bipartition::link_
TreeLink const * link_
Definition: bipartition.hpp:114
genesis::tree::Bipartition::leaf_nodes_
utils::Bitvector leaf_nodes_
Definition: bipartition.hpp:115
genesis::tree::Bipartition::~Bipartition
~Bipartition()=default
genesis::utils::Bitvector
Definition: bitvector.hpp:48