dune-typetree  3.0-dev
visitor.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_TYPETREE_VISITOR_HH
5 #define DUNE_TYPETREE_VISITOR_HH
6 
8 
9 namespace Dune {
10  namespace TypeTree {
11 
17 
46  {
47 
49 
56  template<typename T, typename TreePath>
57  void pre(T&& t, TreePath treePath) const {}
58 
60 
68  template<typename T, typename TreePath>
69  void in(T&& t, TreePath treePath) const {}
70 
72 
79  template<typename T, typename TreePath>
80  void post(T&& t, TreePath treePath) const {}
81 
83 
89  template<typename T, typename TreePath>
90  void leaf(T&& t, TreePath treePath) const {}
91 
93 
103  template<typename T, typename Child, typename TreePath, typename ChildIndex>
104  void beforeChild(T&& t, Child&& child, TreePath treePath, ChildIndex childIndex) const {}
105 
107 
118  template<typename T, typename Child, typename TreePath, typename ChildIndex>
119  void afterChild(T&& t, Child&& child, TreePath treePath, ChildIndex childIndex) const {}
120 
121  };
122 
123 
125 
161  {
162 
164 
172  template<typename T1, typename T2, typename TreePath>
173  void pre(T1&& t1, T2&& t2, TreePath treePath) const {}
174 
176 
185  template<typename T1, typename T2, typename TreePath>
186  void in(T1&& t1, T2&& t2, TreePath treePath) const {}
187 
189 
197  template<typename T1, typename T2, typename TreePath>
198  void post(T1&& t1, T2&& t2, TreePath treePath) const {}
199 
201 
212  template<typename T1, typename T2, typename TreePath>
213  void leaf(T1&& t1, T2&& t2, TreePath treePath) const {}
214 
216 
228  template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
229  void beforeChild(T1&& t1, Child1&& child1, T2&& t2, Child2&& child2, TreePath treePath, ChildIndex childIndex) const {}
230 
232 
244  template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
245  void afterChild(T1&& t1, Child1&& child1, T2&& t2, Child2&& child2, TreePath treePath, ChildIndex childIndex) const {}
246 
247  };
248 
250 
256  {
257 
258  // the little trick with the default template arguments
259  // makes the class usable for both single-tree visitors
260  // and visitors for pairs of trees
262  template<typename Node1,
263  typename Child1,
264  typename Node2,
265  typename Child2 = void,
266  typename TreePath = void>
267  struct VisitChild
268  {
270  static const bool value = false;
271  };
272 
273  };
274 
275 
277 
281  struct VisitTree
282  {
283 
284  // the little trick with the default template arguments
285  // makes the class usable for both single-tree visitors
286  // and visitors for pairs of trees
288  template<typename Node1,
289  typename Child1,
290  typename Node2,
291  typename Child2 = void,
292  typename TreePath = void>
293  struct VisitChild
294  {
296  static const bool value = true;
297  };
298 
299  };
300 
302 
310  {
313  };
314 
316 
324  {
327  };
328 
330  struct TreeVisitor
331  : public DefaultVisitor
332  , public VisitTree
333  {};
334 
337  : public DefaultVisitor
338  , public VisitDirectChildren
339  {};
340 
343  : public DefaultPairVisitor
344  , public VisitTree
345  {};
346 
349  : public DefaultPairVisitor
350  , public VisitDirectChildren
351  {};
352 
354 
355  } // namespace TypeTree
356 } //namespace Dune
357 
358 #endif // DUNE_TYPETREE_VISITOR_HH
treepath.hh
Dune::TypeTree::TreePathType::dynamic
Definition: treepath.hh:26
Dune::TypeTree::TreeVisitor
Convenience base class for visiting the entire tree.
Definition: visitor.hh:330
Dune::TypeTree::DefaultPairVisitor::leaf
void leaf(T1 &&t1, T2 &&t2, TreePath treePath) const
Method for leaf traversal.
Definition: visitor.hh:213
Dune::TypeTree::TreePathType::fullyStatic
Definition: treepath.hh:26
Dune::TypeTree::DefaultVisitor::in
void in(T &&t, TreePath treePath) const
Method for infix tree traversal.
Definition: visitor.hh:69
Dune::TypeTree::DefaultVisitor::post
void post(T &&t, TreePath treePath) const
Method for postfix tree traversal.
Definition: visitor.hh:80
Dune::TypeTree::VisitDirectChildren::VisitChild
Template struct for determining whether or not to visit a given child.
Definition: visitor.hh:267
Dune::TypeTree::Child
typename impl::_Child< Node, indices... >::type Child
Template alias for the type of a child node given by a list of child indices.
Definition: childextraction.hh:307
Dune::TypeTree::child
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:179
Dune::TypeTree::TreePathType::Type
Type
Definition: treepath.hh:26
Dune::TypeTree::VisitTree::VisitChild
Template struct for determining whether or not to visit a given child.
Definition: visitor.hh:293
Dune::TypeTree::DefaultPairVisitor::pre
void pre(T1 &&t1, T2 &&t2, TreePath treePath) const
Method for prefix tree traversal.
Definition: visitor.hh:173
Dune::TypeTree::DirectChildrenPairVisitor
Convenience base class for visiting the direct children of a node pair.
Definition: visitor.hh:348
Dune
Definition: accumulate_static.hh:13
Dune::TypeTree::DefaultPairVisitor::post
void post(T1 &&t1, T2 &&t2, TreePath treePath) const
Method for postfix traversal.
Definition: visitor.hh:198
Dune::TypeTree::DefaultVisitor::beforeChild
void beforeChild(T &&t, Child &&child, TreePath treePath, ChildIndex childIndex) const
Method for parent-child traversal.
Definition: visitor.hh:104
Dune::TypeTree::DefaultVisitor
Visitor interface and base class for TypeTree visitors.
Definition: visitor.hh:45
Dune::TypeTree::DefaultVisitor::leaf
void leaf(T &&t, TreePath treePath) const
Method for leaf traversal.
Definition: visitor.hh:90
Dune::TypeTree::DirectChildrenVisitor
Convenience base class for visiting the direct children of a node.
Definition: visitor.hh:336
Dune::TypeTree::StaticTraversal::treePathType
static const TreePathType::Type treePathType
Use the static tree traversal algorithm.
Definition: visitor.hh:312
Dune::TypeTree::DynamicTraversal
Mixin base class for visitors that only need a dynamic TreePath during traversal.
Definition: visitor.hh:323
Dune::TypeTree::VisitTree
Mixin base class for visitors that want to visit the complete tree.
Definition: visitor.hh:281
Dune::TypeTree::DefaultVisitor::pre
void pre(T &&t, TreePath treePath) const
Method for prefix tree traversal.
Definition: visitor.hh:57
Dune::TypeTree::DefaultPairVisitor::beforeChild
void beforeChild(T1 &&t1, Child1 &&child1, T2 &&t2, Child2 &&child2, TreePath treePath, ChildIndex childIndex) const
Method for parent-child traversal.
Definition: visitor.hh:229
Dune::TypeTree::VisitDirectChildren
Mixin base class for visitors that only want to visit the direct children of a node.
Definition: visitor.hh:255
Dune::TypeTree::DefaultVisitor::afterChild
void afterChild(T &&t, Child &&child, TreePath treePath, ChildIndex childIndex) const
Method for child-parent traversal.
Definition: visitor.hh:119
Dune::TypeTree::VisitDirectChildren::VisitChild::value
static const bool value
Do not visit any child.
Definition: visitor.hh:270
Dune::TypeTree::StaticTraversal
Mixin base class for visitors that require a static TreePath during traversal.
Definition: visitor.hh:309
Dune::TypeTree::TreePath
Definition: treepath.hh:30
Dune::TypeTree::DynamicTraversal::treePathType
static const TreePathType::Type treePathType
Use the dynamic tree traversal algorithm.
Definition: visitor.hh:326
Dune::TypeTree::DefaultPairVisitor
Visitor interface and base class for visitors of pairs of TypeTrees.
Definition: visitor.hh:160
Dune::TypeTree::DefaultPairVisitor::afterChild
void afterChild(T1 &&t1, Child1 &&child1, T2 &&t2, Child2 &&child2, TreePath treePath, ChildIndex childIndex) const
Method for child-parent traversal.
Definition: visitor.hh:245
Dune::TypeTree::DefaultPairVisitor::in
void in(T1 &&t1, T2 &&t2, TreePath treePath) const
Method for infix tree traversal.
Definition: visitor.hh:186
Dune::TypeTree::VisitTree::VisitChild::value
static const bool value
Visit any child.
Definition: visitor.hh:296
Dune::TypeTree::TreePairVisitor
Convenience base class for visiting an entire tree pair.
Definition: visitor.hh:342