4 #ifndef DUNE_TYPETREE_APPLYTOCHILDRENSINGLETREE_HH
5 #define DUNE_TYPETREE_APPLYTOCHILDRENSINGLETREE_HH
7 #include <dune/common/typetraits.hh>
21 #ifndef DOXYGEN // these are all internals and not public API.
24 template<TreePathType::Type tpType,
typename tag = StartTag,
bool doApply = true>
44 template<std::
size_t inverse_k, std::
size_t count>
45 struct apply_to_children_fully_static
48 #if HAVE_RVALUE_REFERENCES
50 template<
typename N,
typename V,
typename TreePath>
51 static void apply(N&& n, V&& v, TreePath tp)
54 typedef typename remove_reference<N>::type Node;
55 typedef typename remove_reference<V>::type Visitor;
58 typedef typename Node::template Child<count-inverse_k>
::Type C;
61 typedef typename TreePathPushBack<TreePath,count-inverse_k>::type ChildTreePath;
67 v.beforeChild(std::forward<N>(n),n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
70 ApplyToTree<Visitor::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),
75 v.afterChild(std::forward<N>(n),n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
78 v.in(std::forward<N>(n),tp);
81 apply_to_children_fully_static<inverse_k-1,count>::apply(std::forward<N>(n),
89 template<
typename N,
typename V,
typename TreePath>
90 static void apply(N& n, V& v, TreePath tp)
92 typedef typename N::template Child<count-inverse_k>
::Type C;
93 typedef typename TreePathPushBack<TreePath,count-inverse_k>::type ChildTreePath;
95 v.beforeChild(n,n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
96 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),v,ChildTreePath());
97 v.afterChild(n,n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
99 apply_to_children_fully_static<inverse_k-1,count>::apply(n,v,tp);
103 template<
typename N,
typename V,
typename TreePath>
104 static void apply(
const N& n, V& v, TreePath tp)
106 typedef typename N::template Child<count-inverse_k>
::Type C;
107 typedef typename TreePathPushBack<TreePath,count-inverse_k>::type ChildTreePath;
108 const bool visit = V::template VisitChild<N,C,ChildTreePath>::value;
109 v.beforeChild(n,n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
110 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),v,ChildTreePath());
111 v.afterChild(n,n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
113 apply_to_children_fully_static<inverse_k-1,count>::apply(n,v,tp);
117 template<
typename N,
typename V,
typename TreePath>
118 static void apply(N& n,
const V& v, TreePath tp)
120 typedef typename N::template Child<count-inverse_k>
::Type C;
121 typedef typename TreePathPushBack<TreePath,count-inverse_k>::type ChildTreePath;
122 const bool visit = V::template VisitChild<N,C,ChildTreePath>::value;
123 v.beforeChild(n,n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
124 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),v,ChildTreePath());
125 v.afterChild(n,n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
127 apply_to_children_fully_static<inverse_k-1,count>::apply(n,v,tp);
131 template<
typename N,
typename V,
typename TreePath>
132 static void apply(
const N& n,
const V& v, TreePath tp)
134 typedef typename N::template Child<count-inverse_k>
::Type C;
135 typedef typename TreePathPushBack<TreePath,count-inverse_k>::type ChildTreePath;
136 const bool visit = V::template VisitChild<N,C,ChildTreePath>::value;
137 v.beforeChild(n,n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
138 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),v,ChildTreePath());
139 v.afterChild(n,n.template child<count-inverse_k>(),tp,integral_constant<std::size_t,count-inverse_k>());
141 apply_to_children_fully_static<inverse_k-1,count>::apply(n,v,tp);
144 #endif // HAVE_RVALUE_REFERENCES
150 template<std::
size_t count>
151 struct apply_to_children_fully_static<1,count>
154 #if HAVE_RVALUE_REFERENCES
156 template<
typename N,
typename V,
typename TreePath>
157 static void apply(N&& n, V&& v, TreePath tp)
159 typedef typename remove_reference<N>::type Node;
160 typedef typename remove_reference<V>::type Visitor;
161 typedef typename Node::template Child<count-1>
::Type C;
162 typedef typename TreePathPushBack<TreePath,count-1>::type ChildTreePath;
163 const bool visit = Visitor::template VisitChild<Node,C,ChildTreePath>::value;
164 v.beforeChild(std::forward<N>(n),n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
165 ApplyToTree<Visitor::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),
168 v.afterChild(std::forward<N>(n),n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
174 template<
typename N,
typename V,
typename TreePath>
175 static void apply(N& n, V& v, TreePath tp)
177 typedef typename N::template Child<count-1>
::Type C;
178 typedef typename TreePathPushBack<TreePath,count-1>::type ChildTreePath;
179 const bool visit = V::template VisitChild<N,C,ChildTreePath>::value;
180 v.beforeChild(n,n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
181 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),v,ChildTreePath());
182 v.afterChild(n,n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
186 template<
typename N,
typename V,
typename TreePath>
187 static void apply(
const N& n, V& v, TreePath tp)
189 typedef typename N::template Child<count-1>
::Type C;
190 typedef typename TreePathPushBack<TreePath,count-1>::type ChildTreePath;
191 const bool visit = V::template VisitChild<N,C,ChildTreePath>::value;
192 v.beforeChild(n,n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
193 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),v,ChildTreePath());
194 v.afterChild(n,n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
198 template<
typename N,
typename V,
typename TreePath>
199 static void apply(N& n,
const V& v, TreePath tp)
201 typedef typename N::template Child<count-1>
::Type C;
202 typedef typename TreePathPushBack<TreePath,count-1>::type ChildTreePath;
203 const bool visit = V::template VisitChild<N,C,ChildTreePath>::value;
204 v.beforeChild(n,n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
205 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),v,ChildTreePath());
206 v.afterChild(n,n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
210 template<
typename N,
typename V,
typename TreePath>
211 static void apply(
const N& n,
const V& v, TreePath tp)
213 typedef typename N::template Child<count-1>
::Type C;
214 typedef typename TreePathPushBack<TreePath,count-1>::type ChildTreePath;
215 const bool visit = V::template VisitChild<N,C,ChildTreePath>::value;
216 v.beforeChild(n,n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
217 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),v,ChildTreePath());
218 v.afterChild(n,n.template child<count-1>(),tp,integral_constant<std::size_t,count-1>());
221 #endif // HAVE_RVALUE_REFERENCES
226 struct apply_to_children_fully_static<0,0>
229 #if HAVE_RVALUE_REFERENCES
231 template<
typename N,
typename V,
typename TreePath>
232 static void apply(N&& n, V&& v, TreePath tp) {}
236 template<
typename N,
typename V,
typename TreePath>
237 static void apply(N& n, V& v, TreePath tp) {}
239 template<
typename N,
typename V,
typename TreePath>
240 static void apply(
const N& n, V& v, TreePath tp) {}
242 template<
typename N,
typename V,
typename TreePath>
243 static void apply(N& n,
const V& v, TreePath tp) {}
245 template<
typename N,
typename V,
typename TreePath>
246 static void apply(
const N& n,
const V& v, TreePath tp) {}
248 #endif // HAVE_RVALUE_REFERENCES
259 template<std::
size_t inverse_k, std::
size_t count>
260 struct apply_to_children_dynamic
263 #if HAVE_RVALUE_REFERENCES
265 template<
typename N,
typename V,
typename TreePath>
266 static void apply(N&& n, V&& v, TreePath tp)
268 typedef typename remove_reference<N>::type Node;
269 typedef typename remove_reference<V>::type Visitor;
270 typedef typename Node::template Child<count-inverse_k>
::Type C;
272 v.beforeChild(std::forward<N>(n),n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
273 tp.push_back(count-inverse_k);
274 ApplyToTree<Visitor::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),
278 v.afterChild(std::forward<N>(n),n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
279 v.in(std::forward<N>(n),tp.view());
280 apply_to_children_dynamic<inverse_k-1,count>::apply(std::forward<N>(n),
287 template<
typename N,
typename V,
typename TreePath>
288 static void apply(N& n, V& v, TreePath tp)
290 typedef typename N::template Child<count-inverse_k>
::Type C;
292 v.beforeChild(n,n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
293 tp.push_back(count-inverse_k);
294 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),
298 v.afterChild(n,n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
300 apply_to_children_dynamic<inverse_k-1,count>::apply(n,v,tp);
303 template<
typename N,
typename V,
typename TreePath>
304 static void apply(
const N& n, V& v, TreePath tp)
306 typedef typename N::template Child<count-inverse_k>
::Type C;
307 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
308 v.beforeChild(n,n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
309 tp.push_back(count-inverse_k);
310 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),
314 v.afterChild(n,n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
316 apply_to_children_dynamic<inverse_k-1,count>::apply(n,v,tp);
319 template<
typename N,
typename V,
typename TreePath>
320 static void apply(N& n,
const V& v, TreePath tp)
322 typedef typename N::template Child<count-inverse_k>
::Type C;
323 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
324 v.beforeChild(n,n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
325 tp.push_back(count-inverse_k);
326 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),
330 v.afterChild(n,n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
332 apply_to_children_dynamic<inverse_k-1,count>::apply(n,v,tp);
335 template<
typename N,
typename V,
typename TreePath>
336 static void apply(
const N& n,
const V& v, TreePath tp)
338 typedef typename N::template Child<count-inverse_k>
::Type C;
339 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
340 v.beforeChild(n,n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
341 tp.push_back(count-inverse_k);
342 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-inverse_k>(),
346 v.afterChild(n,n.template child<count-inverse_k>(),tp.view(),count-inverse_k);
348 apply_to_children_dynamic<inverse_k-1,count>::apply(n,v,tp);
351 #endif // HAVE_RVALUE_REFERENCES
357 template<std::
size_t count>
358 struct apply_to_children_dynamic<1,count>
361 #if HAVE_RVALUE_REFERENCES
363 template<
typename N,
typename V,
typename TreePath>
364 static void apply(N&& n, V&& v, TreePath tp)
366 typedef typename remove_reference<N>::type Node;
367 typedef typename remove_reference<V>::type Visitor;
368 typedef typename Node::template Child<count-1>
::Type C;
369 const bool visit = Visitor::template VisitChild<Node,C,typename TreePath::ViewType>::value;
370 v.beforeChild(std::forward<N>(n),n.template child<count-1>(),tp.view(),count-1);
371 tp.push_back(count-1);
372 ApplyToTree<Visitor::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),
376 v.afterChild(std::forward<N>(n),n.template child<count-1>(),tp.view(),count-1);
381 template<
typename N,
typename V,
typename TreePath>
382 static void apply(N& n, V& v, TreePath tp)
384 typedef typename N::template Child<count-1>
::Type C;
385 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
386 v.beforeChild(n,n.template child<count-1>(),tp.view(),count-1);
387 tp.push_back(count-1);
388 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),
392 v.afterChild(n,n.template child<count-1>(),tp.view(),count-1);
395 template<
typename N,
typename V,
typename TreePath>
396 static void apply(
const N& n, V& v, TreePath tp)
398 typedef typename N::template Child<count-1>
::Type C;
399 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
400 v.beforeChild(n,n.template child<count-1>(),tp.view(),count-1);
401 tp.push_back(count-1);
402 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),
406 v.afterChild(n,n.template child<count-1>(),tp.view(),count-1);
409 template<
typename N,
typename V,
typename TreePath>
410 static void apply(N& n,
const V& v, TreePath tp)
412 typedef typename N::template Child<count-1>
::Type C;
413 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
414 v.beforeChild(n,n.template child<count-1>(),tp.view(),count-1);
415 tp.push_back(count-1);
416 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),
420 v.afterChild(n,n.template child<count-1>(),tp.view(),count-1);
423 template<
typename N,
typename V,
typename TreePath>
424 static void apply(
const N& n,
const V& v, TreePath tp)
426 typedef typename N::template Child<count-1>
::Type C;
427 const bool visit = V::template VisitChild<N,C,typename TreePath::ViewType>::value;
428 v.beforeChild(n,n.template child<count-1>(),tp.view(),count-1);
429 tp.push_back(count-1);
430 ApplyToTree<V::treePathType,typename C::NodeTag,visit>::apply(n.template child<count-1>(),
434 v.afterChild(n,n.template child<count-1>(),tp.view(),count-1);
437 #endif // HAVE_RVALUE_REFERENCES
442 struct apply_to_children_dynamic<0,0>
445 #if HAVE_RVALUE_REFERENCES
447 template<
typename N,
typename V,
typename TreePath>
448 static void apply(N&& n, V&& v, TreePath tp) {}
452 template<
typename N,
typename V,
typename TreePath>
453 static void apply(N& n, V& v, TreePath tp) {}
455 template<
typename N,
typename V,
typename TreePath>
456 static void apply(
const N& n, V& v, TreePath tp) {}
458 template<
typename N,
typename V,
typename TreePath>
459 static void apply(N& n,
const V& v, TreePath tp) {}
461 template<
typename N,
typename V,
typename TreePath>
462 static void apply(
const N& n,
const V& v, TreePath tp) {}
464 #endif // HAVE_RVALUE_REFERENCES
471 template<TreePathType::Type treePathType, std::
size_t CHILDREN>
472 struct apply_to_children;
474 template<std::
size_t CHILDREN>
475 struct apply_to_children<TreePathType::
fullyStatic,CHILDREN>
476 :
public apply_to_children_fully_static<CHILDREN,CHILDREN>
479 template<std::
size_t CHILDREN>
480 struct apply_to_children<TreePathType::
dynamic,CHILDREN>
481 :
public apply_to_children_dynamic<CHILDREN,CHILDREN>
494 struct ApplyToGenericCompositeNode
497 #if HAVE_RVALUE_REFERENCES
499 template<
typename N,
typename V,
typename TreePath>
500 static void apply(N&& n, V&& v, TreePath tp)
502 v.pre(std::forward<N>(n),tp);
503 typedef typename remove_reference<N>::type Node;
504 typedef typename remove_reference<V>::type Visitor;
505 apply_to_children<Visitor::treePathType,Node::CHILDREN>::apply(std::forward<N>(n),
508 v.post(std::forward<N>(n),tp);
513 template<
typename N,
typename V,
typename TreePath>
514 static void apply(N& n, V& v, TreePath tp)
517 apply_to_children<V::treePathType,N::CHILDREN>::apply(n,v,tp);
521 template<
typename N,
typename V,
typename TreePath>
522 static void apply(
const N& n, V& v, TreePath tp)
525 apply_to_children<V::treePathType,N::CHILDREN>::apply(n,v,tp);
529 template<
typename N,
typename V,
typename TreePath>
530 static void apply(N& n,
const V& v, TreePath tp)
533 apply_to_children<V::treePathType,N::CHILDREN>::apply(n,v,tp);
537 template<
typename N,
typename V,
typename TreePath>
538 static void apply(
const N& n,
const V& v, TreePath tp)
541 apply_to_children<V::treePathType,N::CHILDREN>::apply(n,v,tp);
545 #endif // HAVE_RVALUE_REFERENCES
556 #endif // DUNE_TYPETREE_APPLYTOCHILDRENSINGLETREE_HH
Definition: treepath.hh:26
Definition: treepath.hh:26
static const std::size_t value
Definition: compositenode.hh:38
Type
Definition: treepath.hh:26