StRoot
1
|
#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_t * | operator* () 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_t * | mcurrentnode |
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. | |
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.
Definition at line 45 of file StiCompositeLeafIterator.h.
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().
|
protected |
This is not implemented. One must pass a node to the constructor in order for the leaves to be found.
|
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().
|
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.
|
inline |
Dereference iterator, just as an STL iterator.
Suppose that you had declared the following typedefs:
And you added the following code:
typedef StiCompositeTreeNode<Foo> tnode_t;
typedef StiCompositeLeafIterator<Foo> tleafit_t;
Then you dereference the leaf iterator as follows:
tnode_t root;
... code to hang other nodes on the root ...
for (tleafit_t it(root); it!=it.const_end(); ++it) {
Foo* myFoo = *it;
}
Definition at line 166 of file StiCompositeLeafIterator.h.
|
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.
|
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.