Compounds | |
class | AllNodeIterator |
This iterator iterates over all nodes that follow a given node (with no respect to the root of node). More... | |
class | LeaveIterator |
This iterator iterates over all leaves that belong to a given node (have the same root). More... | |
class | NodeIterator |
This iterator iterates in preorder over all nodes that belong to a given node (have the same root). More... | |
class | PostOrderNodeIterator |
This iterator iterates over all nodes in post order that belong to a given node (have the same root) and are not fixed. More... | |
class | VariableNodeIterator |
These classes realize the preorder iteration over trees with the help of the iterator design pattern. Preorder iteration means, that it first visits a node before descending to its children.
A NodeIterator iterates over all nodes of a tree that have the same root. In a simple tree, that does not contain subtrees, it iterates over all nodes. If subtrees are present, the inner nodes of a subtree are not traversed. This way subtrees are treated as complete entities.
The linkage of an iterator with a tree can happen in several ways. The constructor of NodeIterator takes a node as argument which is the start node of the iteration. There also is the method NodeIterator::setStart() to set the start node after construction. The third method is inspired by STL: The methods Node::begin() and Node::end() return a NodeIterator, which points to the first resp. behind the last node. With the method NodeIterator::isEnd() there also can be tested, if the end of a traversion is reached.
NodeIterator<Node<mytype> >* p_myIter = new NodeIterator<Node<mytype> >(); p_myIter->setStart(p_startnode); myIter = p_startnode.begin(); for (myIter=p_startnode.begin();myIter!=p_startnode.end();++myIter) dosomething(myIter);
The iteration with NodeIterator is done by the method NodeIterator::operator++():
++myIter;
The access is done by NodeIterator::operator *(), NodeIterator::operator->() or NodeIterator::operator()().
nodepointer = myIter(); node = *myIter; myIter->nodemethod();
Since the iterator interface also contains the methods NodeIterator::operator==() and NodeIterator::operator!=() for comparsion it is conform it iterator of STL. Therefore the interesting possibility is given to use the algorithms of the STL library, i.e. for_each().
The NodeIterator has 3 template parameters:
_Node: | node type that is iterated |
_Ref: | reference type to node |
_Ptr: | pointer type to node |
Node<mytype>::iterator p_myIter;
Node<mytype>::const_iterator p_myIter;
The NodeIterator class contains the interface that is (at the moment) implemented by the following classes.
Hierarchy of NodeIterator classes