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 #include <boost/shared_ptr.hpp>
33 #include <boost/enable_shared_from_this.hpp>
34 #include "../../common/datastructures/WDendrogram.h"
35 
36 /**
37  * A node in a tree, holding an index, a level in the tree and pointers to its child nodes
38  */
39 class WTreeNode : public boost::enable_shared_from_this<WTreeNode>
40 {
41 public:
42  /**
43  * Shared pointer abbreviation.
44  */
45  typedef boost::shared_ptr< WTreeNode > SPtr;
46 
47  /**
48  * Constructs a new TreeNode.
49  *
50  * \param index the index of the new Node.
51  * \param level the level of the Node in the Tree
52  */
53  WTreeNode( size_t index, double level );
54 
55  /**
56  * Constructs a tree of WTreeNodes from a WDendrogram with this WTreeNode as root
57  *
58  * \param dendrogram Reference to the dendrogram to construct the tree from
59  */
60  explicit WTreeNode( const WDendrogram &dendrogram );
61 
62  /**
63  * Default destructor.
64  */
65  ~WTreeNode();
66 
67  /**
68  * Adds a childnode to this node
69  *
70  * \param child the child node to add
71  */
72  void addChild( WTreeNode::SPtr child );
73 
74  /**
75  * Returns the index of the TreeNode
76  *
77  * \return the node's index
78  */
79  size_t index();
80 
81  /**
82  * Returns the level of the TreeNode. All level-0-nodes are leaves.
83  *
84  * \return the node's level
85  */
86  double level();
87 
88  /**
89  * Returns the child nodes of this node
90  *
91  * \return the child nodes of this node
92  */
93  std::vector< WTreeNode::SPtr > getChildren();
94 
95  /**
96  * Returns the parent node of this node
97  *
98  * \return the parent node of this node
99  */
101 
102 private:
103  /**
104  * Stores the childnodes of this node
105  */
106  std::vector< WTreeNode::SPtr > m_children;
107 
108  /**
109  * Stores the level of this node
110  */
111  double m_level;
112 
113  /**
114  * Stores the index of this node
115  */
116  size_t m_index;
117 
118  /**
119  * Stores the parent node
120  */
122 };
123 
124 #endif // WTREENODE_H