Home | Download | Screen shots | Discussion | Documentation |
---|
The node_traverser
provides a generalized traversal mechanism that avoids redundantly traversing branches of the node hierarchy. If a node occurs multiple places in a branch, the children of that node will be visted in the traversal only once.
For each node encountered in the traversal, node_traverser
does the following:
node_traverser::on_entering
.node_traverser::on_leaving
.
Concrete subclasses of node_traverser
implement the on_entering
and/or on_leaving
member functions in order to perform some operation(s) on each node. The traversal can be ended prematurely by calling node_traverser::halt_traversal
.
Public Member Functions | |
node_traverser () throw (std::bad_alloc) | |
Construct. | |
virtual | ~node_traverser ()=0 throw () |
Destroy. | |
void | traverse (node &n) |
Traverse a node. | |
void | traverse (const node_ptr &node) |
Traverse a node . | |
void | traverse (const std::vector< node_ptr > &nodes) |
Traverse a std::vector of node s. | |
Protected Member Functions | |
void | halt_traversal () throw () |
Halt the traversal. | |
bool | halted () throw () |
Indicate whether the traversal has been halted. | |
Private Member Functions | |
virtual void | on_entering (node &n) |
Called for each node in the traversal before traversing the its descendants. | |
virtual void | on_leaving (node &n) |
Called for each node in the traversal after traversing the its descendants. | |
void | do_traversal (node &n) |
Traverse a node . | |
Private Attributes | |
std::set< node * > | traversed_nodes |
The set of nodes that have already been traversed. | |
bool | halt |
Flag to indicate if the traversal should be halted. |
|
Construct.
|
|
Destroy.
|
|
Traverse a node. No guarantee is made about the state of the node_traverser instance in the event that this method throws.
In addition to
|
|
Traverse a This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
|
Traverse a This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
|
Halt the traversal.
If this method is called during a traversal, no more descendant nodes will be traversed. Note that if |
|
Indicate whether the traversal has been halted.
This function is useful in implementations of
|
|
Called for each
|
|
Called for each
|
|
Traverse a
For internal use only.
|
|
The set of nodes that have already been traversed.
For internal use only.
|
|
Flag to indicate if the traversal should be halted.
For internal use only.
|