A library for working with phylogenetic and population genetic data.
v0.27.0
tree/tree/link.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_TREE_LINK_H_
2 #define GENESIS_TREE_TREE_LINK_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 <cassert>
35 #include <string>
36 
37 namespace genesis {
38 namespace tree {
39 
40 // =================================================================================================
41 // Forward declarations
42 // =================================================================================================
43 
44 class Tree;
45 class TreeEdge;
46 class TreeNode;
47 
48 // =================================================================================================
49 // TreeLink
50 // =================================================================================================
51 
52 class TreeLink
53 {
54 public:
55 
56  // ---------------------------------------------------------------------
57  // Typedefs and Enums
58  // ---------------------------------------------------------------------
59 
60  friend class Tree;
61 
62  // ---------------------------------------------------------------------
63  // Constructor and Rule of Five
64  // ---------------------------------------------------------------------
65 
67  : index_( 0 )
68  , next_( nullptr )
69  , outer_( nullptr )
70  , node_( nullptr )
71  , edge_( nullptr )
72  {}
73 
75  : index_( index )
76  , next_( next )
77  , outer_( outer )
78  , node_( node )
79  , edge_( edge )
80  {}
81 
82  ~TreeLink() = default;
83 
84  // avoid copy constructor and assignment operator.
85  // creating copies is maintained by Tree only.
86 
87  TreeLink( TreeLink const& ) = delete;
88  TreeLink( TreeLink&& ) = delete;
89 
90  TreeLink& operator= ( TreeLink const& ) = delete;
91  TreeLink& operator= ( TreeLink&& ) = delete;
92 
93  // ---------------------------------------------------------------------
94  // Accessors
95  // ---------------------------------------------------------------------
96 
100  size_t index() const
101  {
102  return index_;
103  }
104 
109  {
110  return *next_;
111  }
112 
116  TreeLink const& next() const
117  {
118  return *next_;
119  }
120 
128  {
129  TreeLink* res = this;
130  while( &res->next() != this ) {
131  res = &res->next();
132  }
133  assert( &res->next() == this );
134  return *res;
135  }
136 
143  TreeLink const& prev() const
144  {
145  TreeLink const* res = this;
146  while( &res->next() != this ) {
147  res = &res->next();
148  }
149  assert( &res->next() == this );
150  return *res;
151  }
152 
157  {
158  return *outer_;
159  }
160 
164  TreeLink const& outer() const
165  {
166  return *outer_;
167  }
168 
173  {
174  return *edge_;
175  }
176 
180  TreeEdge const& edge() const
181  {
182  return *edge_;
183  }
184 
189  {
190  return *node_;
191  }
192 
196  TreeNode const& node() const
197  {
198  return *node_;
199  }
200 
201  // ---------------------------------------------------------------------
202  // Modifiers
203  // ---------------------------------------------------------------------
204 
215  TreeLink& reset_index( size_t val )
216  {
217  index_ = val;
218  return *this;
219  }
220 
230  {
231  next_ = val;
232  return *this;
233  }
234 
244  {
245  outer_ = val;
246  return *this;
247  }
248 
258  {
259  node_ = val;
260  return *this;
261  }
262 
272  {
273  edge_ = val;
274  return *this;
275  }
276 
277  // ---------------------------------------------------------------------
278  // Member Variables
279  // ---------------------------------------------------------------------
280 
281 private:
282 
283  size_t index_;
284 
285  TreeLink* next_;
286  TreeLink* outer_;
287 
288  TreeNode* node_;
289  TreeEdge* edge_;
290 };
291 
292 } // namespace tree
293 } // namespace genesis
294 
295 #endif // include guard
genesis::tree::Tree
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
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