| 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 nodes. | |
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. | |
| openvrml::node_traverser::node_traverser | ( | ) | throw (std::bad_alloc) |
Construct.
| std::bad_alloc | if memory allocation fails. |
| openvrml::node_traverser::~node_traverser | ( | ) | throw () [pure virtual] |
Destroy.
| void openvrml::node_traverser::traverse | ( | node & | n | ) |
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 std::bad_alloc, this function throws any exception thrown from on_entering or on_leaving.
| n | the root node of the branch to traverse. |
| std::bad_alloc | if memory allocation fails. |
| void openvrml::node_traverser::traverse | ( | const node_ptr & | node | ) |
| void openvrml::node_traverser::traverse | ( | const std::vector< node_ptr > & | nodes | ) |
| void openvrml::node_traverser::halt_traversal | ( | ) | throw () [protected] |
Halt the traversal.
If this method is called during a traversal, no more descendant nodes will be traversed. Note that if halt_traversal is called in the implementation of on_entering, on_leaving will still be called for the current node and any parent nodes (that is, any node for which on_entering has been called). Implementations of on_leaving can call node_traverser::halted to check whether the traversal has been halted.
| bool openvrml::node_traverser::halted | ( | ) | throw () [protected] |
Indicate whether the traversal has been halted.
This function is useful in implementations of on_leaving that need to check whether the traversal has been halted.
true if the traversal has been halted; false otherwise. | void openvrml::node_traverser::on_entering | ( | node & | n | ) | [private, virtual] |
| void openvrml::node_traverser::on_leaving | ( | node & | n | ) | [private, virtual] |
| void openvrml::node_traverser::do_traversal | ( | node & | n | ) | [private] |
std::set< node * > openvrml::node_traverser::traversed_nodes [private] |
The set of nodes that have already been traversed.
For internal use only.
bool openvrml::node_traverser::halt [private] |
Flag to indicate if the traversal should be halted.
For internal use only.