A toolkit for working with phylogenetic data.
v0.18.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-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 
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 
96  size_t index() const;
97 
98  TreeLink & next();
99  TreeLink const& next() const;
100 
101  TreeLink & prev();
102  TreeLink const& prev() const;
103 
104  TreeLink & outer();
105  TreeLink const& outer() const;
106 
107  TreeEdge & edge();
108  TreeEdge const& edge() const;
109 
110  TreeNode & node();
111  TreeNode const& node() const;
112 
113  // ---------------------------------------------------------------------
114  // Modifiers
115  // ---------------------------------------------------------------------
116 
117  TreeLink& reset_index( size_t val );
118 
119  TreeLink& reset_next( TreeLink* val );
120  TreeLink& reset_outer( TreeLink* val );
121 
122  TreeLink& reset_node( TreeNode* val );
123  TreeLink& reset_edge( TreeEdge* val );
124 
125  // ---------------------------------------------------------------------
126  // Member Functions
127  // ---------------------------------------------------------------------
128 
129  bool is_leaf() const;
130  bool is_inner() const;
131 
132  std::string dump() const;
133 
134  // ---------------------------------------------------------------------
135  // Member Variables
136  // ---------------------------------------------------------------------
137 
138 private:
139 
140  size_t index_;
141 
142  TreeLink* next_;
143  TreeLink* outer_;
144 
145  TreeNode* node_;
146  TreeEdge* edge_;
147 };
148 
149 } // namespace tree
150 } // namespace genesis
151 
152 #endif // include guard
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95