Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Visitor< V > Class Template Reference

A context specific visitor class. More...

#include <Composite.h>

Inheritance diagram for Visitor< V >:

VisitorCore< Visitable< V > > VisitorBase Referenced List of all members.

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.


Detailed Description

template<class V>
class Visitor< V >

A context specific visitor class.

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.


Member Typedef Documentation

typedef CompositeBase<Visitable< V >> VisitorCore< Visitable< V > >::Node [inherited]
 

Base class type for nodes in the graph.


Member Function Documentation

virtual void VisitorCore< Visitable< V > >::apply Node   node [inline, virtual, inherited]
 

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.

TraversalMode VisitorCore< Visitable< V > >::getTraversalMode   const [inline, inherited]
 

Get the mode for traversing the composite graph.

void VisitorCore< Visitable< V > >::setTraversalMode TraversalMode    mode [inline, protected, inherited]
 

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).

void VisitorCore< Visitable< V > >::traverse Node   node [inline, protected, inherited]
 

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.


The documentation for this class was generated from the following file:
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.

[SF.net]