LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::tree< T > Class Template Reference
[Aggregate Data Types]

Tree container class. More...

#include <ltiTree.h>

Inheritance diagram for lti::tree< T >:
Inheritance graph
[legend]
Collaboration diagram for lti::tree< T >:
Collaboration graph
[legend]

List of all members.

Classes

class  const_iterator
 Const iterator type (allows read-only operations). More...
class  iterator
 Iterator type (allows read and write operations). More...
class  node
 The elements of the tree are instances of the "node" class. More...
class  nodeManager
 The nodeManager takes care of the memory administration. More...

Public Types

typedef T value_type
typedef int size_type

Public Member Functions

 tree (const int &n=0)
 tree (const tree< T > &other)
virtual ~tree ()
const char * getTypeName () const
size_type size () const
size_type height () const
const_iterator begin () const
iterator begin ()
const_iterator end () const
iterator end ()
iterator getIteratorTo (node &aNode)
const_iterator getIteratorTo (const node &aNode) const
void clear ()
void fill (const T &iniValue)
noderoot ()
const noderoot () const
void pushRoot (const T &newData)
tree< T > & copy (const tree< T > &other)
virtual mathObjectclone () const
bool empty () const
bool equals (const tree< T > &other) const
bool operator== (const tree< T > &other) const
tree< T > & operator= (const tree< T > &other)
virtual bool write (ioHandler &handler, const bool complete=true) const
virtual bool read (ioHandler &handler, const bool complete=true)

Protected Attributes

nodetheRoot
int rootDegree
nodeManager theNodeManager

Detailed Description

template<class T>
class lti::tree< T >

Tree container class.

The lti::tree class allows the representation of rooted ordered trees.

The tree class is a container class implemented as template. The template type T is the type of a data element contained in each node of the tree, independently if it is a leaf or not. The only requirement for the type T is that is must not depend on dynamic allocation of internal data.

All types defined in ltiTypes.h use static members and can be contained by the lti::tree class.

The tree is always created empty. You can however specify in the constructor a default degree, i.e. the maximal number of childs to be expected per node.

The first element will be inserted with pushRoot().


Member Typedef Documentation

template<class T>
typedef int lti::tree< T >::size_type

Return type of the size() member.

template<class T>
typedef T lti::tree< T >::value_type

Type of the data in the nodes of the tree.


Constructor & Destructor Documentation

template<class T>
lti::tree< T >::tree ( const int &  n = 0  ) 

Default constructor.

If you do not provide any arguments, an empty tree of zero-degree will be created.

You can also provide the degree of the tree, which is the maximal number of children a node can have, but even if you provide the degree, the tree will be empty. Use pushRoot to insert the first node in the tree.

Parameters:
n the default number of children (degree) of the root node.
template<class T>
lti::tree< T >::tree ( const tree< T > &  other  ) 

Create this tree as a copy of another tree.

Parameters:
other the tree to be copied.
template<class T>
virtual lti::tree< T >::~tree (  )  [virtual]

Destructor.


Member Function Documentation

template<class T>
iterator lti::tree< T >::begin (  )  [inline]

Returns an iterator to the first element.

The use of the interators is similar to the iterators of the Standard Template Library (STL). If you need to iterate on all elements of the tree, you can use following code:

 int tmp,accu;                   // a temporal variable
 lti::tree<int> myTree();        // empty tree
 // fill your tree here
 lti::tree<int>::iterator it;    // an iterator

 for (it=myTree.begin();it!=myTree.end();++it) {
   tmp = (*it).getData();        // tmp has value of element pointed
                                 // by the iterator.
   accu += tmp;
   (*it).setData(accu);          // change the value in the tree.
 }

Please note that if you define it as a const_iterator, you can NOT make something like *it=accu.

template<class T>
const_iterator lti::tree< T >::begin (  )  const [inline]

Returns const_iterator to a "first" node of the tree.

This node will be allways the root Note that you can not change the values of the tree elements when you use a const_iterator. See also begin()

template<class T>
void lti::tree< T >::clear (  ) 

Clears the tree (this tree will be empty!).

see fill(const T&) to initialize all tree nodes with some value

Referenced by lti::tree< T >::node::setDegree().

template<class T>
virtual mathObject* lti::tree< T >::clone (  )  const [virtual]

Create a clone of this tree.

Returns:
a pointer to a copy of this tree

Implements lti::mathObject.

template<class T>
tree<T>& lti::tree< T >::copy ( const tree< T > &  other  ) 

Assigment operator.

copy the contents of other in this object.

Parameters:
other the source tree to be copied.

Reimplemented from lti::ioObject.

Referenced by lti::tree< objectStruct >::operator=().

template<class T>
bool lti::tree< T >::empty (  )  const

Returns true if the tree is empty.

template<class T>
iterator lti::tree< T >::end (  )  [inline]

Returns last index as an iterator For an example see begin().

template<class T>
const_iterator lti::tree< T >::end (  )  const [inline]

Returns last index as a const iterator.

For an example see begin()

template<class T>
bool lti::tree< T >::equals ( const tree< T > &  other  )  const

Compare this tree with other.

Parameters:
other the other tree to be compared with
Returns:
true if both trees have the same elements and topology
template<class T>
void lti::tree< T >::fill ( const T &  iniValue  ) 

Fills all tree elements with iniValue.

Parameters:
iniValue the elements will be initialized with this value.
template<class T>
const_iterator lti::tree< T >::getIteratorTo ( const node aNode  )  const [inline]

Return a const_iterator which points to the given node.

template<class T>
iterator lti::tree< T >::getIteratorTo ( node aNode  )  [inline]

Return an iterator which points to the given node.

template<class T>
const char* lti::tree< T >::getTypeName ( void   )  const [inline, virtual]

Returns the name of this class: "tree".

Reimplemented from lti::mathObject.

template<class T>
size_type lti::tree< T >::height (  )  const [inline]

Returns the height of the tree, defined as the length of the longest path from the root to some leaf node.

template<class T>
tree<T>& lti::tree< T >::operator= ( const tree< T > &  other  )  [inline]

Assigment operator (alias for copy(other)).

Parameters:
other the tree to be copied
Returns:
a reference to the actual tree

Reimplemented from lti::ioObject.

template<class T>
bool lti::tree< T >::operator== ( const tree< T > &  other  )  const [inline]

Compare this tree with other.

Parameters:
other the other tree to be compared with
Returns:
true if both trees have the same elements and topology
template<class T>
void lti::tree< T >::pushRoot ( const T &  newData  ) 

Insert a node at the root position.

pushRoot will insert the given data as the root of the tree, and the old root will be inserted as its first child. The root will have the mininum between 1 and the degree specified in the creation of the tree.

If the tree was empty, it will have a new node with the given data.

template<class T>
virtual bool lti::tree< T >::read ( ioHandler handler,
const bool  complete = true 
) [virtual]

Read the parameters from the given ioHandler.

The default implementation is to read just the parameters object.

Parameters:
handler the ioHandler to be used
complete if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written.
Returns:
true if write was successful

Reimplemented from lti::mathObject.

template<class T>
const node& lti::tree< T >::root (  )  const

Access element x of the tree in a read-only modus.

Note that if the tree is empty, the reference is invalid. Use empty() to check this.

template<class T>
node& lti::tree< T >::root (  ) 

Return the root node of the tree.

Note that if the tree is empty the reference is invalid. Use empty() to check this

template<class T>
size_type lti::tree< T >::size (  )  const [inline]
template<class T>
virtual bool lti::tree< T >::write ( ioHandler handler,
const bool  complete = true 
) const [virtual]

Write the functor in the given ioHandler.

The default implementation is to write just the parameters object.

Parameters:
handler the ioHandler to be used
complete if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written.
Returns:
true if write was successful

Reimplemented from lti::mathObject.


Member Data Documentation

template<class T>
int lti::tree< T >::rootDegree [protected]

Degree for the root specified by the user in constructor.

template<class T>
nodeManager lti::tree< T >::theNodeManager [protected]

The node manager administrates the memory allocation and deallocation for all nodes in the tree.

template<class T>
node* lti::tree< T >::theRoot [protected]

The root of the tree.


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

Generated on Sat Apr 10 15:28:47 2010 for LTI-Lib by Doxygen 1.6.1