A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2018 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 <string>
35 
36 namespace genesis {
37 namespace tree {
38 
39 // =================================================================================================
40 // Forward declarations
41 // =================================================================================================
42 
43 class Tree;
44 class TreeEdge;
45 class TreeNode;
46 
47 // =================================================================================================
48 // TreeLink
49 // =================================================================================================
50 
51 class TreeLink
52 {
53 public:
54 
55  // ---------------------------------------------------------------------
56  // Typedefs and Enums
57  // ---------------------------------------------------------------------
58 
59  friend class Tree;
60 
61  // ---------------------------------------------------------------------
62  // Constructor and Rule of Five
63  // ---------------------------------------------------------------------
64 
66  : index_( 0 )
67  , next_( nullptr )
68  , outer_( nullptr )
69  , node_( nullptr )
70  , edge_( nullptr )
71  {}
72 
74  : index_( index )
75  , next_( next )
76  , outer_( outer )
77  , node_( node )
78  , edge_( edge )
79  {}
80 
81  ~TreeLink() = default;
82 
83  // avoid copy constructor and assignment operator.
84  // creating copies is maintained by Tree only.
85 
86  TreeLink( TreeLink const& ) = delete;
87  TreeLink( TreeLink&& ) = delete;
88 
89  TreeLink& operator= ( TreeLink const& ) = delete;
90  TreeLink& operator= ( TreeLink&& ) = delete;
91 
92  // ---------------------------------------------------------------------
93  // Accessors
94  // ---------------------------------------------------------------------
95 
99  size_t index() const
100  {
101  return index_;
102  }
103 
108  {
109  return *next_;
110  }
111 
115  TreeLink const& next() const
116  {
117  return *next_;
118  }
119 
127  {
128  TreeLink* res = this;
129  while( &res->next() != this ) {
130  res = &res->next();
131  }
132  return *res;
133  }
134 
141  TreeLink const& prev() const
142  {
143  TreeLink const* res = this;
144  while( &res->next() != this ) {
145  res = &res->next();
146  }
147  return *res;
148  }
149 
154  {
155  return *outer_;
156  }
157 
161  TreeLink const& outer() const
162  {
163  return *outer_;
164  }
165 
170  {
171  return *edge_;
172  }
173 
177  TreeEdge const& edge() const
178  {
179  return *edge_;
180  }
181 
186  {
187  return *node_;
188  }
189 
193  TreeNode const& node() const
194  {
195  return *node_;
196  }
197 
198  // ---------------------------------------------------------------------
199  // Modifiers
200  // ---------------------------------------------------------------------
201 
212  TreeLink& reset_index( size_t val )
213  {
214  index_ = val;
215  return *this;
216  }
217 
227  {
228  next_ = val;
229  return *this;
230  }
231 
241  {
242  outer_ = val;
243  return *this;
244  }
245 
255  {
256  node_ = val;
257  return *this;
258  }
259 
269  {
270  edge_ = val;
271  return *this;
272  }
273 
274  // ---------------------------------------------------------------------
275  // Member Variables
276  // ---------------------------------------------------------------------
277 
278 private:
279 
280  size_t index_;
281 
282  TreeLink* next_;
283  TreeLink* outer_;
284 
285  TreeNode* node_;
286  TreeEdge* edge_;
287 };
288 
289 } // namespace tree
290 } // namespace genesis
291 
292 #endif // include guard
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95