Loading...
Searching...
No Matches
Dune::TypeTree::DefaultPairVisitor Struct Reference
dune-typetree » Traversal

Visitor interface and base class for visitors of pairs of TypeTrees. More...

`#include <dune/typetree/visitor.hh>`

Inheritance diagram for Dune::TypeTree::DefaultPairVisitor:

## Public Member Functions

template<typename T1, typename T2, typename TreePath>
void | pre (T1 &&, T2 &&, TreePath) const
| Method for prefix tree traversal.
template<typename T1, typename T2, typename TreePath>
void | in (T1 &&, T2 &&, TreePath) const
| Method for infix tree traversal.
template<typename T1, typename T2, typename TreePath>
void | post (T1 &&, T2 &&, TreePath) const
| Method for postfix traversal.
template<typename T1, typename T2, typename TreePath>
void | leaf (T1 &&, T2 &&, TreePath) const
| Method for leaf traversal.
template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
void | beforeChild (T1 &&, Child1 &&, T2 &&, Child2 &&, TreePath, ChildIndex) const
| Method for parent-child traversal.
template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
void | afterChild (T1 &&, Child1 &&, T2 &&, Child2 &&, TreePath, ChildIndex) const
| Method for child-parent traversal.

## Detailed Description

Visitor interface and base class for visitors of pairs of TypeTrees.

DefaultPairVisitor defines the interface for visitors that can be applied to a pair of TypeTrees using applyToTreePair(). Each method of the visitor is passed a node of both trees (either as a mutable or a const reference, depending on the constness of the tree applyToTreePair() was called with). The last argument is of type TreePath and denotes the exact position of the nodes within the TypeTrees, encoded as child indices starting at the root node.

In order to create a functioning visitor, an implementation will - in addition to providing the methods of this class - also have to contain the following template struct, which is used to determine whether to visit a given node:

template<typename Node1,
typename Child1,
typename Node2,
typename Child2,
typename TreePath>
struct VisitChild
{
static const bool value = ...; // decide whether to visit Child
};

For the two most common scenarios - visiting only direct children and visiting the whole tree - there are mixin classes VisitDirectChildren and VisitTree and combined base classes TreePairVisitor and DirectChildrenPairVisitor. The latter two inherit from both DefaultVisitor and one of the two mixin classes and can thus be used as convenient base classes.

Note
  If your compiler does not support rvalue references, both trees must be either const or non-const. If you call applyToTreePair() with two trees of different constness, they will both be made const.
  This class can also be used as a convenient base class if the implemented visitor only needs to act on some of the possible callback sites, avoiding a lot of boilerplate code.

## Member Function Documentation

## afterChild()

template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>

void Dune::TypeTree::DefaultPairVisitor::afterChild | ( | T1 && | ,
|  | Child1 && | ,
|  | T2 && | ,
|  | Child2 && | ,
|  | TreePath | ,
|  | ChildIndex | ) const

inline

Method for child-parent traversal.

This method gets called after visiting a child node.

Note
  This method gets called even if the visitor decides not to visit the child in question.

Parameters

  t1 | The node of the first tree to visit.
  child1 | The child of t1 to visit.
  t2 | The node of the second tree to visit.
  child2 | The child of t2 to visit.
  treePath | The position of the parent nodes within the TypeTree.
  childIndex | The index of the child nodes in relation to the parent nodes.

## beforeChild()

template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>

void Dune::TypeTree::DefaultPairVisitor::beforeChild | ( | T1 && | ,
|  | Child1 && | ,
|  | T2 && | ,
|  | Child2 && | ,
|  | TreePath | ,
|  | ChildIndex | ) const

inline

Method for parent-child traversal.

This method gets called before visiting a child node.

Note
  This method gets called even if the visitor decides not to visit the child in question.

Parameters

  t1 | The node of the first tree to visit.
  child1 | The child of t1 to visit.
  t2 | The node of the second tree to visit.
  child2 | The child of t2 to visit.
  treePath | The position of the parent nodes within the TypeTree.
  childIndex | The index of the child nodes in relation to the parent nodes.

## in()

template<typename T1, typename T2, typename TreePath>

void Dune::TypeTree::DefaultPairVisitor::in | ( | T1 && | ,
|  | T2 && | ,
|  | TreePath | ) const

inline

Method for infix tree traversal.

This method gets called BETWEEN visits of children of a non-leaf node. That definition implies that this method will only be called for nodes with at least two children.

Parameters

  t1 | The node of the first tree to visit.
  t2 | The node of the second tree to visit.
  treePath | The position of the node within the TypeTree.

## leaf()

template<typename T1, typename T2, typename TreePath>

void Dune::TypeTree::DefaultPairVisitor::leaf | ( | T1 && | ,
|  | T2 && | ,
|  | TreePath | ) const

inline

Method for leaf traversal.

This method gets called when encountering a leaf node within the pair of TypeTrees.

Attention
  Since the two TypeTrees are not required to be exactly identical, it is only guaranteed that at least one of the nodes is a leaf node, not both.

Parameters

  t1 | The node of the first tree to visit.
  t2 | The node of the second tree to visit.
  treePath | The position of the node within the TypeTree.

## post()

template<typename T1, typename T2, typename TreePath>

void Dune::TypeTree::DefaultPairVisitor::post | ( | T1 && | ,
|  | T2 && | ,
|  | TreePath | ) const

inline

Method for postfix traversal.

This method gets called after all children of a non-leaf node have been visited.

Parameters

  t1 | The node of the first tree to visit.
  t2 | The node of the second tree to visit.
  treePath | The position of the node within the TypeTree.

## pre()

template<typename T1, typename T2, typename TreePath>

void Dune::TypeTree::DefaultPairVisitor::pre | ( | T1 && | ,
|  | T2 && | ,
|  | TreePath | ) const

inline

Method for prefix tree traversal.

This method gets called when first encountering a non-leaf node and before visiting any of its children.

Parameters

  t1 | The node of the first tree to visit.
  t2 | The node of the second tree to visit.
  treePath | The position of the node within the TypeTree.

The documentation for this struct was generated from the following file:

- visitor.hh