hierarchy_iterator Class
class hierarchy_iterator
The hierarchy_iterator templated class is an iterator that traverses a hierarchy in depth first order. When traversing a hierarchy, the iterator visits the parent first, then the first child, second child etc. When the last child is reached, the parent's next sibling is visited. In effect, the hierarchy is visited in the same order that nodes in a tree control are shown reading from top to bottom. This permits every node in a hierarchy to be visited with one simple for loopThe hierarchy_iterator class defines a query, depth which tells you the iterator's current depth within the hierarchy. Aside from this additional member, the hierarchy_iterator is the same as the iterator you pass in as its template parameter.
To use the hierarchy_iterator, you must first tell it how to access the children of a given node. There are three ways to do so. First, you can simply add a GetChildren method to the node type. By default, the hierarchy iterator will assume this member exists and call it to access children. The GetChildren method should return a traversable to its children or NULL if it has no children.
Second, you can derive a specialized hierarchy_iterator and override its get_children virtual function. This function is expected to test the current node when called upon. If it has children, a traversable interface must be returned which permits access to those child. If not, a NULL traversable indicates no children.
The second method is two declare an accessor object and pass it into the constructor. To declare a accessor object, derive a a class from the nested type . accessor_type is a base class for a functor that implements operator(), and receives the current element as a parameter. The operator is expected to return a traversable interface if the element has children or NULL if it doesn't. To use the hierarchy_iterator, define an accessor object and pass it into the hierarchy_iterator constructor.
Defined in: PolyIter.h
Class Template Arguments
_It
The type of iterator to wrap and traverse hierarchically.
Member functions include: hierarhcy_iterator::hierarchy_iteratorhierarhcy_iterator::depth