Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

NodeVisitor

With the help of the visitor design pattern analysis and modification algorithms can be made available for the tree structure without changing the Node classes. More...

Compounds

class  CollectVisitor
 This visitor collects all nodes into a vector which is provided through 'getList()'. More...

class  DepthVisitor
 This visitor measures the maximum depth of the tree, which is the distance from the given node to the farest leave. The distance is provided through 'getDepth()'. More...

class  NodeVisitor
 Visitors are used to extend the Node classes without changing their implementation ('visitor pattern') NodeVisitor is the base class of all visitors. Visitors use an iterator to traverse the tree. So the result depends on the given iteration algorithm. If set to non-recursive they only visit one node. The default value is true, so the visitor works recursively. More...

class  NodeVisitorBase
 Visitors are used to extend the Node classes without changing their implementation ('visitor pattern') NodeVisitor is the base class of all visitors. Visitors use an iterator to traverse the tree. So the result depends on the given iteration algorithm. If set to non-recursive they only visit one node. The default value is true, so the visitor works recursively. More...

class  OutputVisitor
 OutputVisitor is used for output of the tree. It uses an configurable OutputStrategy (see OutputStrategy), 'DefaultOutputStrategy' if none is given. More...


Detailed Description

With the help of the visitor design pattern analysis and modification algorithms can be made available for the tree structure without changing the Node classes.

The Node interface also remains clean of application specific details and reuse is simplified.

A visitor traverses over the tree with the help of an iterater and adds functionality at the desired positions within the tree. The interface of the visitor classes is declarated in the abstract base class NodeVisitor. Visitor is a functor and must contain the method NodeVisitor::operator()() with a NodeIterator or Node as argument to execute the algorithm. By providing a pointer to a Node or a NodeIterator a tree structure is attached to the visitor and it will use the NodeIterator to traverse the tree. The type of the iterator must be configured as template parameter.

The actual functionality must be implemented in the methods NodeVisitor::visitNormalNode() and NodeVisitor::visitRootNode(), which are called by a NormalNode resp. a RootNode. Note, that the result of a visit depends on the choice of visitor, which is also a template parameter. The iterator determines, which nodes are visited and if subtrees are visited or not (see section NodeIterator). If the traversal should not include the subtree under the start node, the method NodeVisitor::setRecursive with parameter false prevents this. In this case only the start node will be visited.

The following visitor classes exist in TreeComp. Further functionality can easily be implemented by further visitor classes without changing the Node classes. Since visitor classes might also work on the content of a node, the have the content type as a template parameter.

DepthVisitor
This visitor determines the depth of a tree, that is the largest distance between the root and a leave. After having executed DepthVisitor::operator()() the depth can be retreived with Node::getDepth().
CollectVisitor
The CollectVisitor collets all visited nodes in a vector and returns them with CollectVisitor::getList(). Thus a simple conversion of a tree into a list representation is possible. Note: Maybe this class will be removed in future in favor of the IterNodeTraversal class. A real traversal is more effective than the iterator implementation since it can be recursive.
LayoutVisitor
This visitor arranges nodes on an plain area. It uses a very simple layout algorithm. The coordinates and the corresponding nodes will be saved an an STL map. The map can be accessed by LayoutVisitor::getMap(). This map can i.e. be used by an OutputVisitor with a corresponding OutputStrategy (i.e. TEXGraphOutputStrategy, see section OutputStrategy) to print the tree.
OutputVisitor
The output of a tree can be done by the OutputVisitor. In order to have different output formats this visitor uses an OutputStrategy, which can be configured by OutputVisitor::setOutputStrategy(). Each format has an own Outputstrategy (see section OutputStrategy). If no strategy is set the DefaultOutputStrategy will be used, which writes the names and the types of nodes to cout.

Note:
This default behaviour might be replaced by a NullOutputStrategy in near future. A NullOutputStrategy doesn't produce any output.

nodevisitor2.jpg

Hierarchy of Visitor classes


Generated on Mon Jan 6 12:02:16 2003 for TreeComp by doxygen1.2.17