OpenWalnut  1.4.0
WTreeNode.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WTREENODE_H
26 #define WTREENODE_H
27 
28 #include <sstream>
29 #include <string>
30 #include <vector>
31 
32 #ifndef Q_MOC_RUN
33 #include <boost/shared_ptr.hpp>
34 #endif
35 #ifndef Q_MOC_RUN
36 #include <boost/enable_shared_from_this.hpp>
37 #endif
38 #include "../../common/datastructures/WDendrogram.h"
39 
40 /**
41  * A node in a tree, holding an index, a level in the tree and pointers to its child nodes
42  */
43 class WTreeNode : public boost::enable_shared_from_this<WTreeNode>
44 {
45 public:
46  /**
47  * Shared pointer abbreviation.
48  */
49  typedef boost::shared_ptr< WTreeNode > SPtr;
50 
51  /**
52  * Constructs a new TreeNode.
53  *
54  * \param index the index of the new Node.
55  * \param level the level of the Node in the Tree
56  */
57  WTreeNode( size_t index, double level );
58 
59  /**
60  * Constructs a tree of WTreeNodes from a WDendrogram with this WTreeNode as root
61  *
62  * \param dendrogram Reference to the dendrogram to construct the tree from
63  */
64  explicit WTreeNode( const WDendrogram &dendrogram );
65 
66  /**
67  * Default destructor.
68  */
69  ~WTreeNode();
70 
71  /**
72  * Adds a childnode to this node
73  *
74  * \param child the child node to add
75  */
76  void addChild( WTreeNode::SPtr child );
77 
78  /**
79  * Returns the index of the TreeNode
80  *
81  * \return the node's index
82  */
83  size_t index();
84 
85  /**
86  * Returns the level of the TreeNode. All level-0-nodes are leaves.
87  *
88  * \return the node's level
89  */
90  double level();
91 
92  /**
93  * Returns the child nodes of this node
94  *
95  * \return the child nodes of this node
96  */
97  std::vector< WTreeNode::SPtr > getChildren();
98 
99  /**
100  * Returns the parent node of this node
101  *
102  * \return the parent node of this node
103  */
105 
106 private:
107  /**
108  * Stores the childnodes of this node
109  */
110  std::vector< WTreeNode::SPtr > m_children;
111 
112  /**
113  * Stores the level of this node
114  */
115  double m_level;
116 
117  /**
118  * Stores the index of this node
119  */
120  size_t m_index;
121 
122  /**
123  * Stores the parent node
124  */
126 };
127 
128 #endif // WTREENODE_H
WTreeNode::SPtr getParent()
Returns the parent node of this node.
Definition: WTreeNode.cpp:94
size_t m_index
Stores the index of this node.
Definition: WTreeNode.h:120
double level()
Returns the level of the TreeNode.
Definition: WTreeNode.cpp:78
std::vector< WTreeNode::SPtr > getChildren()
Returns the child nodes of this node.
Definition: WTreeNode.cpp:99
void addChild(WTreeNode::SPtr child)
Adds a childnode to this node.
Definition: WTreeNode.cpp:88
std::vector< WTreeNode::SPtr > m_children
Stores the childnodes of this node.
Definition: WTreeNode.h:110
WTreeNode::SPtr m_parent
Stores the parent node.
Definition: WTreeNode.h:125
WTreeNode(size_t index, double level)
Constructs a new TreeNode.
Definition: WTreeNode.cpp:32
size_t index()
Returns the index of the TreeNode.
Definition: WTreeNode.cpp:83
~WTreeNode()
Default destructor.
Definition: WTreeNode.cpp:74
A node in a tree, holding an index, a level in the tree and pointers to its child nodes...
Definition: WTreeNode.h:43
double m_level
Stores the level of this node.
Definition: WTreeNode.h:115
Hirachical binary tree datastructure with spatial layout information called dendrogram.
Definition: WDendrogram.h:64
boost::shared_ptr< WTreeNode > SPtr
Shared pointer abbreviation.
Definition: WTreeNode.h:49