Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kome::core::TreeNode< T > Class Template Reference

tree structure data management class More...

#include <TreeNode.h>

Public Member Functions

 TreeNode ()
 constructor
 
 TreeNode (T &elm)
 constructor
 
virtual ~TreeNode ()
 destructor
 
T & getElement ()
 gets the element that the node has
 
void setElement (T &elm)
 sets the element that the node has
 
TreeNodegetParentNode ()
 gets parent node More...
 
unsigned int getNumberOfChildren ()
 gets the number of child nodes More...
 
TreeNodegetChild (int index)
 get child node More...
 
void clearChildren ()
 remove all child nodes
 
TreeNodeaddChild ()
 create child node More...
 
TreeNodeaddChild (T &elm)
 create child node More...
 
void sortChildren (boost::function< bool(TreeNode< T > &, TreeNode< T > &) > lessFun)
 sort child nodes More...
 

Protected Member Functions

 TreeNode (TreeNode< T > *parent)
 constructor More...
 
 TreeNode (TreeNode< T > *parent, T &elm)
 constructor More...
 

Protected Attributes

m_element
 
std::vector< TreeNode< T > * > m_children
 
TreeNode< T > * m_parent
 

Detailed Description

template<typename T>
class kome::core::TreeNode< T >

tree structure data management class

Definition at line 29 of file TreeNode.h.

Constructor & Destructor Documentation

template<typename T>
kome::core::TreeNode< T >::TreeNode ( TreeNode< T > *  parent)
inlineprotected

constructor

Parameters
[in]parentparent node

Definition at line 176 of file TreeNode.h.

176  : m_element() {
177  m_parent = parent;
178  }
TreeNode< T > * m_parent
Definition: TreeNode.h:169
template<typename T>
kome::core::TreeNode< T >::TreeNode ( TreeNode< T > *  parent,
T &  elm 
)
inlineprotected

constructor

Parameters
[in]parentparent node
[in]elmthe element that the node has

Definition at line 186 of file TreeNode.h.

186  : m_element( elm ) {
187  m_parent = parent;
188  }
TreeNode< T > * m_parent
Definition: TreeNode.h:169

Member Function Documentation

template<typename T>
TreeNode * kome::core::TreeNode< T >::addChild ( )
inline

create child node

Returns
the child node created

Definition at line 120 of file TreeNode.h.

120  {
121  TreeNode<T>* child = new TreeNode<T>();
122  m_children.push_back( child );
123  return child;
124  }
std::vector< TreeNode< T > * > m_children
Definition: TreeNode.h:166
template<typename T>
TreeNode * kome::core::TreeNode< T >::addChild ( T &  elm)
inline

create child node

Parameters
[in]elmthe element that child node has
Returns
the child node created

Definition at line 132 of file TreeNode.h.

132  {
133  TreeNode<T>* child = new TreeNode<T>( elm );
134  m_children.push_back( child );
135  return child;
136  }
std::vector< TreeNode< T > * > m_children
Definition: TreeNode.h:166
template<typename T>
TreeNode * kome::core::TreeNode< T >::getChild ( int  index)
inline

get child node

Parameters
[in]indexchild index
Returns
child node ( If there is no child node that has index specified, this method returns NULL )

Definition at line 95 of file TreeNode.h.

95  {
96  // check parameter
97  if( index < 0 || index > m_children.size() ) {
98  return NULL;
99  }
100 
101  return m_children[index];
102  }
#define NULL
Definition: CoreMacros.h:18
std::vector< TreeNode< T > * > m_children
Definition: TreeNode.h:166
template<typename T>
unsigned int kome::core::TreeNode< T >::getNumberOfChildren ( )
inline

gets the number of child nodes

Returns
the number of child nodes

Definition at line 85 of file TreeNode.h.

85  {
86  return m_children.size();
87  }
std::vector< TreeNode< T > * > m_children
Definition: TreeNode.h:166
template<typename T>
TreeNode * kome::core::TreeNode< T >::getParentNode ( )
inline

gets parent node

Returns
parent node. ( If this node has no parent, this method returns NULL )

Definition at line 76 of file TreeNode.h.

76  {
77  return m_parent;
78  }
TreeNode< T > * m_parent
Definition: TreeNode.h:169
template<typename T>
void kome::core::TreeNode< T >::sortChildren ( boost::function< bool(TreeNode< T > &, TreeNode< T > &) >  lessFun)
inline

sort child nodes

Parameters
[in]lessFunthe function to compare. This function has two Properties. The first parameter is the node to compare. The second parameter is the node to be compared. If the node specified by the first parameter sorts before the node specified by second parameter, this function returns true

Definition at line 147 of file TreeNode.h.

147  {
148  // check member
149  if( m_children.size() == 0 ) {
150  return;
151  }
152 
153  // sort ( This method is called recursively. )
154  for( unsigned int i = 0; i < m_children.size(); i++ ) {
155  m_children[i]->sortChildre( lessFun );
156  }
157 
158  std::sort( m_children.begin(), m_children.end(), lessFun );
159  }
std::vector< TreeNode< T > * > m_children
Definition: TreeNode.h:166

Member Data Documentation

template<typename T>
std::vector< TreeNode<T>* > kome::core::TreeNode< T >::m_children
protected

the array of child nodes

Definition at line 166 of file TreeNode.h.

template<typename T>
T kome::core::TreeNode< T >::m_element
protected

the element that the node has

Definition at line 163 of file TreeNode.h.

template<typename T>
TreeNode<T>* kome::core::TreeNode< T >::m_parent
protected

the parent node

Definition at line 169 of file TreeNode.h.


The documentation for this class was generated from the following file: