A tree structure with any number of children. More...
#include <tree.hpp>
Public Types | |
typedef T | value_type |
The type of the value stored in the nodes. | |
typedef tree< T > | self_type |
The type of the current class. | |
typedef child_list::iterator | iterator |
typedef child_list::const_iterator | const_iterator |
Public Member Functions | |
tree () | |
Default constructor. | |
tree (const T &that) | |
Constructor with initialization. | |
bool | operator== (const self_type &that) const |
Equality operator. | |
bool | is_leaf () const |
Tell if this node is a leaf (ie. it has no child). | |
self_type & | add_child (const T &v) |
Add a child to this node. | |
self_type & | add_child (const self_type &v) |
Add a child subtree to this node. | |
iterator | find (const T &v) |
Search the first child having a given value. | |
const_iterator | find (const T &v) const |
Search the first child having a given value. | |
iterator | begin () |
Get an iterator on the begining of the children. | |
iterator | end () |
Get an iterator just past the end of the children. | |
const_iterator | begin () const |
Get a constant iterator on the begining of the children. | |
const_iterator | end () const |
Get a constant iterator just past the end of the children. | |
Public Attributes | |
T | value |
The value in this node. | |
Private Types | |
typedef std::list< tree< T > > | child_list |
The type of the list in which are stored the children. | |
Private Attributes | |
child_list | m_child |
The children of this node. |
A tree structure with any number of children.
Definition at line 42 of file tree.hpp.
typedef std::list< tree<T> > claw::tree< T >::child_list [private] |
typedef child_list::const_iterator claw::tree< T >::const_iterator |
typedef child_list::iterator claw::tree< T >::iterator |
typedef tree<T> claw::tree< T >::self_type |
typedef T claw::tree< T >::value_type |
claw::tree< T >::tree | ( | ) | [inline] |
claw::tree< T >::tree | ( | const T & | v | ) | [inline, explicit] |
claw::tree< T >::self_type & claw::tree< T >::add_child | ( | const self_type & | v | ) | [inline] |
Add a child subtree to this node.
v | The tree to add. |
Definition at line 110 of file tree.tpp.
References claw::tree< T >::m_child.
00111 { 00112 m_child.push_back( v ); 00113 } // tree::add_child()
claw::tree< T >::self_type & claw::tree< T >::add_child | ( | const T & | v | ) | [inline] |
claw::tree< T >::const_iterator claw::tree< T >::begin | ( | ) | const [inline] |
Get a constant iterator on the begining of the children.
Definition at line 180 of file tree.tpp.
References claw::tree< T >::m_child.
00181 { 00182 return const_iterator( m_child.begin() ); 00183 } // tree::begin()
claw::tree< T >::iterator claw::tree< T >::begin | ( | ) | [inline] |
Get an iterator on the begining of the children.
Definition at line 160 of file tree.tpp.
References claw::tree< T >::m_child.
claw::tree< T >::const_iterator claw::tree< T >::end | ( | ) | const [inline] |
Get a constant iterator just past the end of the children.
Definition at line 190 of file tree.tpp.
References claw::tree< T >::m_child.
00191 { 00192 return const_iterator( m_child.end() ); 00193 } // tree::end()
claw::tree< T >::iterator claw::tree< T >::end | ( | ) | [inline] |
Get an iterator just past the end of the children.
Definition at line 170 of file tree.tpp.
References claw::tree< T >::m_child.
Referenced by claw::tree< T >::find().
claw::tree< T >::const_iterator claw::tree< T >::find | ( | const T & | v | ) | const [inline] |
Search the first child having a given value.
v | The value of the child to find. |
Definition at line 141 of file tree.tpp.
References claw::tree< T >::end(), and claw::tree< T >::m_child.
00142 { 00143 typename child_list::const_iterator it; 00144 bool found = false; 00145 00146 for ( it=m_child.begin(); !found && (it!=end()) ; ) 00147 if ( it->value == v ) 00148 found = true; 00149 else 00150 ++it; 00151 00152 return const_iterator( it ); 00153 } // tree::find()
claw::tree< T >::iterator claw::tree< T >::find | ( | const T & | v | ) | [inline] |
Search the first child having a given value.
v | The value of the child to find. |
Definition at line 121 of file tree.tpp.
References claw::tree< T >::end(), and claw::tree< T >::m_child.
bool claw::tree< T >::is_leaf | ( | ) | const [inline] |
Tell if this node is a leaf (ie. it has no child).
Definition at line 86 of file tree.tpp.
References claw::tree< T >::m_child.
00087 { 00088 return m_child.empty(); 00089 } // tree::is_leaf()
bool claw::tree< T >::operator== | ( | const self_type & | that | ) | const [inline] |
Equality operator.
that | The tree to compare to. |
Definition at line 60 of file tree.tpp.
References claw::tree< T >::m_child, and claw::tree< T >::value.
00061 { 00062 bool result = ( value == that.value ); 00063 00064 if (result) 00065 { 00066 typename child_list::const_iterator it_me = m_child.begin(); 00067 typename child_list::const_iterator it_him = that.m_child.begin(); 00068 typename child_list::const_iterator eit_me = m_child.end(); 00069 typename child_list::const_iterator eit_him = that.m_child.end(); 00070 00071 while ( result && (it_me!=eit_me) && (it_him!=eit_him) ) 00072 result = (*it_me == *it_him); 00073 00074 if ( (it_me!=eit_me) || (it_him!=eit_him) ) 00075 result = false; 00076 } 00077 00078 return result; 00079 } // tree::operator==()
child_list claw::tree< T >::m_child [private] |
The children of this node.
Definition at line 85 of file tree.hpp.
Referenced by claw::tree< T >::add_child(), claw::tree< T >::begin(), claw::tree< T >::end(), claw::tree< T >::find(), claw::tree< T >::is_leaf(), and claw::tree< T >::operator==().
T claw::tree< T >::value |
The value in this node.
Definition at line 81 of file tree.hpp.
Referenced by claw::tree< T >::operator==().