OpenWalnut  1.4.0
WTreeNode.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WTREENODE_H
00026 #define WTREENODE_H
00027 
00028 #include <sstream>
00029 #include <string>
00030 #include <vector>
00031 
00032 #include <boost/shared_ptr.hpp>
00033 #include <boost/enable_shared_from_this.hpp>
00034 #include "../../common/datastructures/WDendrogram.h"
00035 
00036 /**
00037  * A node in a tree, holding an index, a level in the tree and pointers to its child nodes
00038  */
00039 class WTreeNode : public boost::enable_shared_from_this<WTreeNode>
00040 {
00041 public:
00042     /**
00043      * Shared pointer abbreviation.
00044      */
00045     typedef boost::shared_ptr< WTreeNode > SPtr;
00046 
00047     /**
00048      * Constructs a new TreeNode.
00049      *
00050      * \param index the index of the new Node.
00051      * \param level the level of the Node in the Tree
00052      */
00053     WTreeNode( size_t index, double level );
00054 
00055     /**
00056      * Constructs a tree of WTreeNodes from a WDendrogram with this WTreeNode as root
00057      *
00058      * \param dendrogram Reference to the dendrogram to construct the tree from
00059      */
00060     explicit WTreeNode( const WDendrogram &dendrogram );
00061 
00062     /**
00063      * Default destructor.
00064      */
00065     ~WTreeNode();
00066 
00067     /**
00068      * Adds a childnode to this node
00069      *
00070      * \param child the child node to add
00071      */
00072     void addChild( WTreeNode::SPtr child );
00073 
00074     /**
00075      * Returns the index of the TreeNode
00076      *
00077      * \return the node's index
00078      */
00079     size_t index();
00080 
00081     /**
00082      * Returns the level of the TreeNode. All level-0-nodes are leaves.
00083      *
00084      * \return the node's level
00085      */
00086     double level();
00087 
00088     /**
00089      * Returns the child nodes of this node
00090      *
00091      * \return the child nodes of this node
00092      */
00093     std::vector< WTreeNode::SPtr > getChildren();
00094 
00095     /**
00096      * Returns the parent node of this node
00097      *
00098      * \return the parent node of this node
00099      */
00100     WTreeNode::SPtr getParent();
00101 
00102 private:
00103     /**
00104      * Stores the childnodes of this node
00105      */
00106     std::vector< WTreeNode::SPtr > m_children;
00107 
00108     /**
00109      * Stores the level of this node
00110      */
00111     double m_level;
00112 
00113     /**
00114      * Stores the index of this node
00115      */
00116     size_t m_index;
00117 
00118     /**
00119      * Stores the parent node
00120      */
00121     WTreeNode::SPtr m_parent;
00122 };
00123 
00124 #endif  // WTREENODE_H