4 #ifndef DUNE_TYPETREE_TRAVERSAL_HH
5 #define DUNE_TYPETREE_TRAVERSAL_HH
7 #if HAVE_RVALUE_REFERENCES
25 #ifndef DOXYGEN // these are all internals and not public API. Only access is using applyToTree().
34 template<TreePathType::Type tpType,
bool doApply>
35 struct ApplyToTree<tpType,StartTag,doApply>
38 #if HAVE_RVALUE_REFERENCES
40 template<
typename Node,
typename Visitor>
41 static void apply(Node&& node, Visitor&& visitor)
43 ApplyToTree<tpType,typename remove_reference<Node>::type::NodeTag>::apply(std::forward<Node>(node),
44 std::forward<Visitor>(visitor),
45 TreePathFactory<tpType>::create(node).mutablePath());
50 template<
typename Node,
typename Visitor>
51 static void apply(Node& node, Visitor& visitor)
53 ApplyToTree<tpType,typename Node::NodeTag>::apply(node,visitor,TreePathFactory<tpType>::create(node).mutablePath());
56 template<
typename Node,
typename Visitor>
57 static void apply(
const Node& node, Visitor& visitor)
59 ApplyToTree<tpType,typename Node::NodeTag>::apply(node,visitor,TreePathFactory<tpType>::create(node).mutablePath());
62 template<
typename Node,
typename Visitor>
63 static void apply(Node& node,
const Visitor& visitor)
65 ApplyToTree<tpType,typename Node::NodeTag>::apply(node,visitor,TreePathFactory<tpType>::create(node).mutablePath());
68 template<
typename Node,
typename Visitor>
69 static void apply(
const Node& node,
const Visitor& visitor)
71 ApplyToTree<tpType,typename Node::NodeTag>::apply(node,visitor,TreePathFactory<tpType>::create(node).mutablePath());
74 #endif // HAVE_RVALUE_REFERENCES
80 template<TreePathType::Type tpType,
typename NodeTag>
81 struct ApplyToTree<tpType,NodeTag,false>
86 template<
typename Node,
typename Visitor,
typename TreePath>
87 static void apply(
const Node& node,
const Visitor& visitor, TreePath treePath)
99 template<TreePathType::Type tpType>
100 struct ApplyToTree<tpType,LeafNodeTag,true>
103 #if HAVE_RVALUE_REFERENCES
105 template<
typename N,
typename V,
typename TreePath>
106 static void apply(N&& n, V&& v, TreePath tp)
108 v.leaf(std::forward<N>(n),tp.view());
113 template<
typename N,
typename V,
typename TreePath>
114 static void apply(N& n, V& v, TreePath tp)
119 template<
typename N,
typename V,
typename TreePath>
120 static void apply(
const N& n, V& v, TreePath tp)
125 template<
typename N,
typename V,
typename TreePath>
126 static void apply(N& n,
const V& v, TreePath tp)
131 template<
typename N,
typename V,
typename TreePath>
132 static void apply(
const N& n,
const V& v, TreePath tp)
137 #endif // HAVE_RVALUE_REFERENCES
150 struct ApplyToTree<TreePathType::
fullyStatic,PowerNodeTag,true>
151 :
public ApplyToGenericCompositeNode
159 struct ApplyToTree<TreePathType::
dynamic,PowerNodeTag,true>
162 #if HAVE_RVALUE_REFERENCES
164 template<
typename N,
typename V,
typename TreePath>
165 static void apply(N&& n, V&& v, TreePath tp)
168 v.pre(std::forward<N>(n),tp.view());
171 typedef typename remove_reference<N>::type Node;
172 typedef typename remove_reference<V>::type Visitor;
183 for (std::size_t k = 0; k < Node::CHILDREN; ++k)
186 v.beforeChild(std::forward<N>(n),n.child(k),tp.view(),k);
192 ApplyToTree<Visitor::treePathType,typename C::NodeTag,visit>::apply(n.child(k),std::forward<V>(v),tp);
198 v.afterChild(std::forward<N>(n),n.child(k),tp.view(),k);
201 if (k < Node::CHILDREN-1)
202 v.in(std::forward<N>(n),tp.view());
206 v.post(std::forward<N>(n),tp.view());
212 template<
typename N,
typename V,
typename TreePath>
213 static void apply(N& n, V& v, TreePath tp)
218 for (std::size_t k = 0; k < N::CHILDREN; ++k)
220 v.beforeChild(n,n.child(k),tp.view(),k);
222 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.child(k),v,tp);
224 v.afterChild(n,n.child(k),tp.view(),k);
225 if (k < N::CHILDREN-1)
232 template<
typename N,
typename V,
typename TreePath>
233 static void apply(
const N& n, V& v, TreePath tp)
237 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
238 for (std::size_t k = 0; k < N::CHILDREN; ++k)
240 v.beforeChild(n,n.child(k),tp.view(),k);
242 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.child(k),v,tp);
244 v.afterChild(n,n.child(k),tp.view(),k);
245 if (k < N::CHILDREN-1)
252 template<
typename N,
typename V,
typename TreePath>
253 static void apply(N& n,
const V& v, TreePath tp)
257 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
258 for (std::size_t k = 0; k < N::CHILDREN; ++k)
260 v.beforeChild(n,n.child(k),tp.view(),k);
262 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.child(k),v,tp);
264 v.afterChild(n,n.child(k),tp.view(),k);
265 if (k < N::CHILDREN-1)
272 template<
typename N,
typename V,
typename TreePath>
273 static void apply(
const N& n,
const V& v, TreePath tp)
277 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
278 for (std::size_t k = 0; k < N::CHILDREN; ++k)
280 v.beforeChild(n,n.child(k),tp.view(),k);
282 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.child(k),v,tp);
284 v.afterChild(n,n.child(k),tp.view(),k);
285 if (k < N::CHILDREN-1)
291 #endif // HAVE_RVALUE_REFERENCES
302 template<TreePathType::Type treePathType>
304 :
public ApplyToGenericCompositeNode
310 template<TreePathType::Type treePathType>
311 struct ApplyToTree<
treePathType,VariadicCompositeNodeTag,true>
312 :
public ApplyToGenericCompositeNode
324 #if HAVE_RVALUE_REFERENCES || DOXYGEN
341 template<
typename Tree,
typename Visitor>
345 std::forward<Visitor>(visitor));
350 template<
typename Tree,
typename Visitor>
353 ApplyToTree<Visitor::treePathType>::apply(tree,visitor);
356 template<
typename Tree,
typename Visitor>
357 void applyToTree(
const Tree& tree, Visitor& visitor)
359 ApplyToTree<Visitor::treePathType>::apply(tree,visitor);
362 template<
typename Tree,
typename Visitor>
363 void applyToTree(Tree& tree,
const Visitor& visitor)
365 ApplyToTree<Visitor::treePathType>::apply(tree,visitor);
368 template<
typename Tree,
typename Visitor>
369 void applyToTree(
const Tree& tree,
const Visitor& visitor)
371 ApplyToTree<Visitor::treePathType>::apply(tree,visitor);
374 #endif // HAVE_RVALUE_REFERENCES || DOXYGEN
381 #endif // DUNE_TYPETREE_TRAVERSAL_HH
Definition: treepath.hh:26
Definition: treepath.hh:26
static const TreePathType::Type treePathType
Definition: traversalutilities.hh:30
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:342
static const std::size_t value
Definition: compositenode.hh:38
Type
Definition: treepath.hh:26