#include <Composite.h>
Inheritance diagram for Visitor< V >:

Public Types | |
| typedef CompositeBase< Visitable< V > > | Node |
| Base class type for nodes in the graph. | |
Public Methods | |
| TraversalMode | getTraversalMode () const |
| Get the mode for traversing the composite graph. | |
| virtual void | apply (Node &node) |
| Visit a node and propagate. | |
Protected Methods | |
| void | traverse (Node &node) |
| Propagate from a given node based on the current traversal mode. | |
| void | setTraversalMode (TraversalMode mode) |
| Change the traversal mode. | |
Subclass Visitor to define a custom visitor class for a specific context. Although somewhat counter intuitive, the template parameter must be the sub- class being defined. For example:
class MyNode; class MySpecialNode; // forward declarations of other subclasses of MyNode
class MyNodeVisitor: public Visitor<MyNodeVisitor> { public: using Visitor<MyNodeVisitor>::apply; virtual void apply(MyNode &node) { apply((Node&)node); } virtual void apply(MySpecialNode &node) { apply((MyNode&)node); } // apply stubs for any other subclasses of MyNode }
Note first that the base class apply() method must be brought into scope with a using directive. There is also a macro SIMDATA_VISITOR() which does this and defines a Ref typedef, if you prefer using macros for boilerplate.
The rest of the class should define apply() stubs for each of the node classes in the current context. Each of these node classes must be forward declared, and the apply stubs should chain from subclass to baseclass, ending finally with a call to apply((Node&)node), where Node is a type defined by Visitor that will be a base class of MyNode as long as MyNode derives from Composite<>. See Composite for more details.
|
|
Base class type for nodes in the graph.
|
|
|
Visit a node and propagate. This method is overloaded in the actual visitor classes to apply distinct operations to each type of node. Apply methods should generally conclude with a call to traverse(node) to continue progagation of the visitor through the graph. |
|
|
Get the mode for traversing the composite graph.
|
|
|
Change the traversal mode. The initial traversal mode can be set as a contructor parameter. This method allows the traversal mode to be changed on the fly, for example to abort traversal of a graph once a condition is met (such as finding a matching node during a search). |
|
|
Propagate from a given node based on the current traversal mode. TRAVERSE_CHILDREN will visit the subgraph of the node (depth first), while TRAVERSE_PARENTS will visit all parents until the root of the graph is reached. |
|
SimData version pre-0.4.0. For more information on SimData, visit the SimData Homepage. Generated on Tue Oct 14 12:06:42 2003, using Doxygen 1.2.18. |