StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
StiCompositeLeafIterator< T > Class Template Reference

#include <StiCompositeLeafIterator.h>

Public Types

typedef StiCompositeTreeNode< T > tnode_t
 For internal convenience.
 
typedef vector< tnode_t * > tnode_vec
 For internal convenience.
 

Public Member Functions

 StiCompositeLeafIterator (tnode_t *node)
 Only the daughters of node will automatically be found. More...
 
virtual ~StiCompositeLeafIterator ()
 Defualt destructor.
 
void reset ()
 Reset iterator to point to first leaf. More...
 
void unset ()
 
tnode_toperator* () const
 Dereference iterator, just as an STL iterator. More...
 
void operator++ ()
 Define only prefix of ++ (only a forward iterator) More...
 
bool operator!= (const typename tnode_vec::const_iterator &rhs)
 Define !=.
 
unsigned int getLeafCount () const
 
tnode_vec::iterator begin ()
 Return an iterator marking the beginning of the leaf vector.
 
tnode_vec::iterator end ()
 Return an iterator marking the end of the leaf vector.
 
tnode_vec::const_iterator const_begin () const
 Return a const_iterator marking the beginning of the leaf vector.
 
tnode_vec::const_iterator const_end () const
 Return a const_iterator marking the end of the leaf vector.
 

Protected Member Functions

 StiCompositeLeafIterator ()
 
void findLeaves ()
 Internal function used to find leaves. It is called in the constructor. More...
 

Protected Attributes

tnode_tmcurrentnode
 We store a pointer to the root of the tree for internal convenience.
 
tnode_vec::const_iterator mcurrentleaf
 We have to store an interator into the leaf vector for traversal.
 
tnode_vec mleaves
 The vector of leaves.
 

Detailed Description

template<class T>
class StiCompositeLeafIterator< T >

StiCompositeLeafIterator is a templated iterator class that is complimenatary to StiCompositeTreeNode. Given a pointer to a StiCompositeTreeNode in its constructor, StiCompositeLeafIterator provides access to all of the leaves of that node. Leaves are defined as nodes that have no daughters, and are actaully found using the templated helper class LeafFinder. StiCompositeLeafIterator stores pointers to the leaves in an internal container and provides limited access to the leaves. Ultimately, StiCompositeLeafIterator should conform to the requirements of (at least) an STL forward iterator, however it does not yet. As such, it will currently work when passed to some, but not all, STL algorithms. However, let it be noted that it provides access to const_iterators into the vector of leaves. These are true STL iterators and can be passed to any algorithm that takes const_iterators.

Note that StiCompositeLeafIterator is a "meta" iterator. That is, it is a combination of an iterator and a container. As such, it must provide functionality for both. This is reflected in its providal of operators, e.g., operator++(), and memberfunctions that denote the container characteristics, specifically begin() and end(). These names have been changed to const_begin() and const_end() to reflect that they return const_iterators.

Author
M.L. Miller (Yale Software)

Definition at line 45 of file StiCompositeLeafIterator.h.

Constructor & Destructor Documentation

template<class T >
StiCompositeLeafIterator< T >::StiCompositeLeafIterator ( tnode_t node)

Only the daughters of node will automatically be found.

The created instance of StiCompositeLeafIterator will find only the leaves that belong to the argument to the constructor call, node. That is, the iterator will treat node as if it is the root of a tree. Suppose that node is itself has a parent, and that parent has leaves that exist on a branch other than node. In such a case, these leaves will be ignored by StiCompositeLeafIterator. Therefore, if one wants to find all possible leaves of a given tree, one must be sure that node corresponds to the true root of the tree.

Definition at line 127 of file StiCompositeLeafIterator.h.

References StiCompositeLeafIterator< T >::findLeaves().

template<class T>
StiCompositeLeafIterator< T >::StiCompositeLeafIterator ( )
protected

This is not implemented. One must pass a node to the constructor in order for the leaves to be found.

Member Function Documentation

template<class T >
void StiCompositeLeafIterator< T >::findLeaves ( )
protected

Internal function used to find leaves. It is called in the constructor.

We provide safe forward access to the vector of leaves. This is a real STL iterator (std::vector::const_iterator) and can be used accordingly. It can be used to modify the container of leaves that the iterator points into.

begin() marks a valid iterator, and it points to the first entry in the leaf vector.

We provide safe forward access to the vector of leaves. This is a real STL iterator (std::vector::const_iterator) and can be used accordingly. It can be used to modify the container of leaves that the iterator points into.

const_begin() marks a valid iterator, and it points to the first entry in the leaf vector.

We provide safe forward access to the vector of leaves. This is a real STL iterator (std::vector::const_iterator) and can be used accordingly. Howver, it cannot be used to modify the container of leaves that the iterator points into.

const_begin() marks a valid iterator, and it points to the first entry in the leaf vector.

We provide safe forward access to the vector of leaves. This is a real STL iterator (std::vector::const_iterator) and can be used accordingly. Howver, it cannot be used to modify the container of leaves that the iterator points into.

const_end() marks an invalid iterator, and it points to one entry past the last valid entry in the leaf vector.

Definition at line 270 of file StiCompositeLeafIterator.h.

Referenced by StiCompositeLeafIterator< T >::StiCompositeLeafIterator().

template<class T >
unsigned int StiCompositeLeafIterator< T >::getLeafCount ( ) const
inline

Returns the number of leaves found for the tree node passed in constructor.

We provide the inequality operator that takes as an argument a real std::vector::const_iterator. That is, if one has an iterator into a vector of type StiCompositeTreeNode<T>, then one can check if that iterator is not equal to the current internal state of this StiCompositeLeafIterator.

This returns the number of leaves that can be found by following all possible paths downward from the node passed to the constructor.

Definition at line 197 of file StiCompositeLeafIterator.h.

template<class T >
StiCompositeLeafIterator< T >::tnode_t * StiCompositeLeafIterator< T >::operator* ( void  ) const
inline

Dereference iterator, just as an STL iterator.

Suppose that you had declared the following typedefs:
typedef StiCompositeTreeNode<Foo> tnode_t;
typedef StiCompositeLeafIterator<Foo> tleafit_t;
And you added the following code:
tnode_t root;
... code to hang other nodes on the root ...
Then you dereference the leaf iterator as follows:
for (tleafit_t it(root); it!=it.const_end(); ++it) {
Foo* myFoo = *it;
}

Definition at line 166 of file StiCompositeLeafIterator.h.

template<class T >
void StiCompositeLeafIterator< T >::operator++ ( void  )
inline

Define only prefix of ++ (only a forward iterator)

This simply increments the iterator to point to the next leaf in the leave vector.

Definition at line 175 of file StiCompositeLeafIterator.h.

template<class T >
void StiCompositeLeafIterator< T >::reset ( void  )
inline

Reset iterator to point to first leaf.

A call to reset does not invalidate the leaves that this iterator corresponds to. Instead, it simple resets the iterator to point to the first leaf in the leaf vector. Therefore, one may call reset() with impuninity. However, this also means that a StiCompositeLeafIterator can never be assigned to point to a different collection of leaves. This can only be accomplished by constructing a new instance of StiCompositeLeafIterator that points to a different node.

Definition at line 147 of file StiCompositeLeafIterator.h.


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