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... |
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.
Hierarchy of Visitor classes