dune-typetree  2.3.1
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 
48 #if HAVE_RVALUE_REFERENCES || DOXYGEN
49 
51 
58  template<typename T, typename TreePath>
59  void pre(T&& t, TreePath treePath) const {}
60 
62 
70  template<typename T, typename TreePath>
71  void in(T&& t, TreePath treePath) const {}
72 
74 
81  template<typename T, typename TreePath>
82  void post(T&& t, TreePath treePath) const {}
83 
85 
91  template<typename T, typename TreePath>
92  void leaf(T&& t, TreePath treePath) const {}
93 
95 
105  template<typename T, typename Child, typename TreePath, typename ChildIndex>
106  void beforeChild(T&& t, Child&& child, TreePath treePath, ChildIndex childIndex) const {}
107 
109 
120  template<typename T, typename Child, typename TreePath, typename ChildIndex>
121  void afterChild(T&& t, Child&& child, TreePath treePath, ChildIndex childIndex) const {}
122 
123 #else // HAVE_RVALUE_REFERENCES
124 
125  // These are just a repeat of the above if the compiler does not support
126  // rvalue references. Since our methods are all empty, we only need methods
127  // which take the node as const reference.
128 
129  // Method for prefix traversal
130  template<typename T, typename TreePath>
131  void pre(const T& t, TreePath treePath) const {}
132 
133  // Method for infix traversal
134  template<typename T, typename TreePath>
135  void in(const T& t, TreePath treePath) const {}
136 
137  // Method for postfix traversal
138  template<typename T, typename TreePath>
139  void post(const T& t, TreePath treePath) const {}
140 
141  // Method for leaf traversal
142  template<typename T, typename TreePath>
143  void leaf(const T& t, TreePath treePath) const {}
144 
145  // Method for parent-child traversal
146  template<typename T, typename Child, typename TreePath, typename ChildIndex>
147  void beforeChild(const T& t, const Child& child, TreePath treePath, ChildIndex childIndex) const {}
148 
149  // Method for child-parent traversal
150  template<typename T, typename Child, typename TreePath, typename ChildIndex>
151  void afterChild(const T& t, const Child& child, TreePath treePath, ChildIndex childIndex) const {}
152 
153 #endif // HAVE_RVALUE_REFERENCES || DOXYGEN
154 
155  };
156 
157 
159 
195  {
196 
197 #if HAVE_RVALUE_REFERENCES || DOXYGEN
198 
200 
208  template<typename T1, typename T2, typename TreePath>
209  void pre(T1&& t1, T2&& t2, TreePath treePath) const {}
210 
212 
221  template<typename T1, typename T2, typename TreePath>
222  void in(T1&& t1, T2&& t2, TreePath treePath) const {}
223 
225 
233  template<typename T1, typename T2, typename TreePath>
234  void post(T1&& t1, T2&& t2, TreePath treePath) const {}
235 
237 
248  template<typename T1, typename T2, typename TreePath>
249  void leaf(T1&& t1, T2&& t2, TreePath treePath) const {}
250 
252 
264  template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
265  void beforeChild(T1&& t1, Child1&& child1, T2&& t2, Child2&& child2, TreePath treePath, ChildIndex childIndex) const {}
266 
268 
280  template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
281  void afterChild(T1&& t1, Child1&& child1, T2&& t2, Child2&& child2, TreePath treePath, ChildIndex childIndex) const {}
282 
283 #else // HAVE_RVALUE_REFERENCES
284 
285  // These are just a repeat of the above if the compiler does not support
286  // rvalue references. In this case, we need variants for const and non-const
287  // nodes.
288 
289  // Method for prefix traversal
290  template<typename T1, typename T2, typename TreePath>
291  void pre(T1& t1, T2& t2, TreePath treePath) const {}
292 
293  // Method for infix traversal
294  template<typename T1, typename T2, typename TreePath>
295  void in(T1& t1, T2& t2, TreePath treePath) const {}
296 
297  // Method for postfix traversal
298  template<typename T1, typename T2, typename TreePath>
299  void post(T1& t1, T2& t2, TreePath treePath) const {}
300 
301  // Method for leaf traversal
302  template<typename T1, typename T2, typename TreePath>
303  void leaf(T1& t1, T2& t2, TreePath treePath) const {}
304 
305  template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
306  void beforeChild(T1& t1, Child1& child1,
307  T2& t2, Child2& child2,
308  TreePath treePath,
309  ChildIndex childIndex) const {}
310 
311  template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
312  void afterChild(T1& t1, Child1& child1,
313  T2& t2, Child2& child2,
314  TreePath treePath,
315  ChildIndex childIndex) const {}
316 
317  // Method for prefix traversal
318  template<typename T1, typename T2, typename TreePath>
319  void pre(const T1& t1, const T2& t2, TreePath treePath) const {}
320 
321  // Method for infix traversal
322  template<typename T1, typename T2, typename TreePath>
323  void in(const T1& t1, const T2& t2, TreePath treePath) const {}
324 
325  // Method for postfix traversal
326  template<typename T1, typename T2, typename TreePath>
327  void post(const T1& t1, const T2& t2, TreePath treePath) const {}
328 
329  // Method for leaf traversal
330  template<typename T1, typename T2, typename TreePath>
331  void leaf(const T1& t1, const T2& t2, TreePath treePath) const {}
332 
333  template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
334  void beforeChild(const T1& t1, const Child1& child1,
335  const T2& t2, const Child2& child2,
336  TreePath treePath,
337  ChildIndex childIndex) const {}
338 
339  template<typename T1, typename Child1, typename T2, typename Child2, typename TreePath, typename ChildIndex>
340  void afterChild(const T1& t1, const Child1& child1,
341  const T2& t2, const Child2& child2,
342  TreePath treePath,
343  ChildIndex childIndex) const {}
344 
345 #endif // HAVE_RVALUE_REFERENCES || DOXYGEN
346 
347  };
348 
350 
356  {
357 
358  // the little trick with the default template arguments
359  // makes the class usable for both single-tree visitors
360  // and visitors for pairs of trees
362  template<typename Node1,
363  typename Child1,
364  typename Node2,
365  typename Child2 = void,
366  typename TreePath = void>
367  struct VisitChild
368  {
370  static const bool value = false;
371  };
372 
373  };
374 
375 
377 
381  struct VisitTree
382  {
383 
384  // the little trick with the default template arguments
385  // makes the class usable for both single-tree visitors
386  // and visitors for pairs of trees
388  template<typename Node1,
389  typename Child1,
390  typename Node2,
391  typename Child2 = void,
392  typename TreePath = void>
393  struct VisitChild
394  {
396  static const bool value = true;
397  };
398 
399  };
400 
402 
410  {
413  };
414 
416 
424  {
427  };
428 
430  struct TreeVisitor
431  : public DefaultVisitor
432  , public VisitTree
433  {};
434 
437  : public DefaultVisitor
438  , public VisitDirectChildren
439  {};
440 
443  : public DefaultPairVisitor
444  , public VisitTree
445  {};
446 
449  : public DefaultPairVisitor
450  , public VisitDirectChildren
451  {};
452 
454 
455  } // namespace TypeTree
456 } //namespace Dune
457 
458 #endif // DUNE_TYPETREE_VISITOR_HH
Convenience base class for visiting the direct children of a node pair.
Definition: visitor.hh:448
Definition: treepath.hh:26
Convenience base class for visiting the entire tree.
Definition: visitor.hh:430
Definition: treepath.hh:32
void afterChild(T &&t, Child &&child, TreePath treePath, ChildIndex childIndex) const
Method for child-parent traversal.
Definition: visitor.hh:121
Template struct for determining whether or not to visit a given child.
Definition: visitor.hh:367
static const bool value
Do not visit any child.
Definition: visitor.hh:370
void post(T1 &&t1, T2 &&t2, TreePath treePath) const
Method for postfix traversal.
Definition: visitor.hh:234
Convenience base class for visiting the direct children of a node.
Definition: visitor.hh:436
Visitor interface and base class for TypeTree visitors.
Definition: visitor.hh:45
void in(T &&t, TreePath treePath) const
Method for infix tree traversal.
Definition: visitor.hh:71
void in(T1 &&t1, T2 &&t2, TreePath treePath) const
Method for infix tree traversal.
Definition: visitor.hh:222
Mixin base class for visitors that want to visit the complete tree.
Definition: visitor.hh:381
void leaf(T1 &&t1, T2 &&t2, TreePath treePath) const
Method for leaf traversal.
Definition: visitor.hh:249
void pre(T1 &&t1, T2 &&t2, TreePath treePath) const
Method for prefix tree traversal.
Definition: visitor.hh:209
void afterChild(T1 &&t1, Child1 &&child1, T2 &&t2, Child2 &&child2, TreePath treePath, ChildIndex childIndex) const
Method for child-parent traversal.
Definition: visitor.hh:281
void beforeChild(T1 &&t1, Child1 &&child1, T2 &&t2, Child2 &&child2, TreePath treePath, ChildIndex childIndex) const
Method for parent-child traversal.
Definition: visitor.hh:265
Convenience base class for visiting an entire tree pair.
Definition: visitor.hh:442
Mixin base class for visitors that only want to visit the direct children of a node.
Definition: visitor.hh:355
void pre(T &&t, TreePath treePath) const
Method for prefix tree traversal.
Definition: visitor.hh:59
static const bool value
Visit any child.
Definition: visitor.hh:396
Visitor interface and base class for visitors of pairs of TypeTrees.
Definition: visitor.hh:194
Mixin base class for visitors that only need a dynamic TreePath during traversal. ...
Definition: visitor.hh:423
void leaf(T &&t, TreePath treePath) const
Method for leaf traversal.
Definition: visitor.hh:92
void post(T &&t, TreePath treePath) const
Method for postfix tree traversal.
Definition: visitor.hh:82
void beforeChild(T &&t, Child &&child, TreePath treePath, ChildIndex childIndex) const
Method for parent-child traversal.
Definition: visitor.hh:106
Template struct for determining whether or not to visit a given child.
Definition: visitor.hh:393
Type
Definition: treepath.hh:26
static const TreePathType::Type treePathType
Use the dynamic tree traversal algorithm.
Definition: visitor.hh:426
static const TreePathType::Type treePathType
Use the static tree traversal algorithm.
Definition: visitor.hh:412
Mixin base class for visitors that require a static TreePath during traversal.
Definition: visitor.hh:409