4 #ifndef DUNE_TYPETREE_APPLYTOCHILDRENTREEPAIR_HH 5 #define DUNE_TYPETREE_APPLYTOCHILDRENTREEPAIR_HH 7 #include <dune/common/typetraits.hh> 23 #ifndef DOXYGEN // these are all internals and not public API. Only access is using applyToTree(). 26 template<TreePathType::Type tpType,
typename tag1 = StartTag,
typename tag2 = StartTag,
bool doApply = true>
27 struct ApplyToTreePair;
34 template<std::
size_t inverse_k, std::
size_t count>
35 struct apply_to_children_pair_fully_static
38 template<
typename N1,
typename N2,
typename V,
typename TreePath>
39 static void apply(N1&& n1, N2&& n2, V&& v, TreePath tp)
41 typedef typename remove_reference<N1>::type::template
Child<count-inverse_k>
::Type C1;
42 typedef typename remove_reference<N2>::type::template
Child<count-inverse_k>
::Type C2;
43 typedef typename TreePathPushBack<TreePath,count-inverse_k>::type ChildTreePath;
44 const bool visit = std::remove_reference<V>::type
45 ::template VisitChild<typename remove_reference<N1>::type,
47 typename remove_reference<N2>::type,
49 ChildTreePath>::value;
50 v.beforeChild(std::forward<N1>(n1),n1.template child<count-inverse_k>(),
51 std::forward<N2>(n2),n2.template child<count-inverse_k>(),
52 tp,integral_constant<std::size_t,count-inverse_k>());
56 visit>::apply(n1.template child<count-inverse_k>(),
57 n2.template child<count-inverse_k>(),
60 v.afterChild(std::forward<N1>(n1),n1.template child<count-inverse_k>(),
61 std::forward<N2>(n2),n2.template child<count-inverse_k>(),
62 tp,integral_constant<std::size_t,count-inverse_k>());
63 v.in(std::forward<N1>(n1),std::forward<N2>(n2),tp);
64 apply_to_children_pair_fully_static<inverse_k-1,count>::apply(std::forward<N1>(n1),
74 template<std::
size_t count>
75 struct apply_to_children_pair_fully_static<1,count>
78 template<
typename N1,
typename N2,
typename V,
typename TreePath>
79 static void apply(N1&& n1, N2&& n2, V&& v, TreePath tp)
81 typedef typename remove_reference<N1>::type::template
Child<count-1>
::Type C1;
82 typedef typename remove_reference<N2>::type::template
Child<count-1>
::Type C2;
83 typedef typename TreePathPushBack<TreePath,count-1>::type ChildTreePath;
84 const bool visit = std::remove_reference<V>::type
85 ::template VisitChild<typename remove_reference<N1>::type,
87 typename remove_reference<N2>::type,
89 ChildTreePath>::value;
90 v.beforeChild(std::forward<N1>(n1),n1.template child<count-1>(),
91 std::forward<N2>(n2),n2.template child<count-1>(),
92 tp,integral_constant<std::size_t,count-1>());
96 visit>::apply(n1.template child<count-1>(),
97 n2.template child<count-1>(),
100 v.afterChild(std::forward<N1>(n1),n1.template child<count-1>(),
101 std::forward<N2>(n2),n2.template child<count-1>(),
102 tp,integral_constant<std::size_t,count-1>());
109 struct apply_to_children_pair_fully_static<0,0>
112 template<
typename N1,
typename N2,
typename V,
typename TreePath>
113 static void apply(N1&& n1, N2&& n2, V&& v, TreePath tp) {}
122 template<std::
size_t inverse_k, std::
size_t count>
123 struct apply_to_children_pair_dynamic
126 template<
typename N1,
typename N2,
typename V,
typename TreePath>
127 static void apply(N1&& n1, N2&& n2, V&& v, TreePath tp)
129 typedef typename remove_reference<N1>::type::template
Child<count-inverse_k>
::Type C1;
130 typedef typename remove_reference<N2>::type::template
Child<count-inverse_k>
::Type C2;
131 const bool visit = std::remove_reference<V>::type
132 ::template VisitChild<typename remove_reference<N1>::type,
134 typename remove_reference<N2>::type,
137 v.beforeChild(std::forward<N1>(n1),n1.template child<count-inverse_k>(),
138 std::forward<N2>(n2),n2.template child<count-inverse_k>(),
139 tp.view(),count-inverse_k);
140 tp.push_back(count-inverse_k);
142 typename C1::NodeTag,
143 typename C2::NodeTag,
144 visit>::apply(n1.template child<count-inverse_k>(),
145 n2.template child<count-inverse_k>(),
149 v.afterChild(std::forward<N1>(n1),n1.template child<count-inverse_k>(),
150 std::forward<N2>(n2),n2.template child<count-inverse_k>(),
151 tp.view(),count-inverse_k);
152 v.in(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
153 apply_to_children_pair_dynamic<inverse_k-1,count>::apply(std::forward<N1>(n1),
154 std::forward<N2>(n2),
163 template<std::
size_t count>
164 struct apply_to_children_pair_dynamic<1,count>
167 template<
typename N1,
typename N2,
typename V,
typename TreePath>
168 static void apply(N1&& n1, N2&& n2, V&& v, TreePath tp)
170 typedef typename remove_reference<N1>::type::template
Child<count-1>
::Type C1;
171 typedef typename remove_reference<N2>::type::template
Child<count-1>
::Type C2;
172 const bool visit = std::remove_reference<V>::type
173 ::template VisitChild<typename remove_reference<N1>::type,
175 typename remove_reference<N2>::type,
178 v.beforeChild(std::forward<N1>(n1),n1.template child<count-1>(),
179 std::forward<N2>(n2),n2.template child<count-1>(),
181 tp.push_back(count-1);
183 typename C1::NodeTag,
184 typename C2::NodeTag,
185 visit>::apply(n1.template child<count-1>(),
186 n2.template child<count-1>(),
190 v.afterChild(std::forward<N1>(n1),n1.template child<count-1>(),
191 std::forward<N2>(n2),n2.template child<count-1>(),
199 struct apply_to_children_pair_dynamic<0,0>
202 template<
typename N1,
typename N2,
typename V,
typename TreePath>
203 static void apply(N1&& n1, N2&& n2, V&& v, TreePath tp) {}
209 template<TreePathType::Type treePathType, std::
size_t CHILDREN>
210 struct apply_to_children_pair;
212 template<std::
size_t CHILDREN>
213 struct apply_to_children_pair<TreePathType::
fullyStatic,CHILDREN>
214 :
public apply_to_children_pair_fully_static<CHILDREN,CHILDREN>
217 template<std::
size_t CHILDREN>
218 struct apply_to_children_pair<TreePathType::
dynamic,CHILDREN>
219 :
public apply_to_children_pair_dynamic<CHILDREN,CHILDREN>
227 template<TreePathType::Type treePathType>
228 struct ApplyToGenericCompositeNodePair
232 template<
typename N1,
typename N2,
typename V,
typename TreePath>
233 static typename enable_if<(remove_reference<N1>::type::isLeaf || remove_reference<N2>::type::isLeaf)>::type
234 apply(N1&& n1, N2&& n2, V&& v, TreePath tp)
236 v.leaf(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
240 template<
typename N1,
typename N2,
typename V,
typename TreePath>
241 static typename enable_if<!(remove_reference<N1>::type::isLeaf || remove_reference<N2>::type::isLeaf)>::type
242 apply(N1&& n1, N2&& n2, V&& v, TreePath tp)
244 v.pre(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
245 typedef typename remove_reference<N1>::type Node1;
246 typedef typename remove_reference<N2>::type Node2;
249 static_assert(Node1::CHILDREN == Node2::CHILDREN,
250 "non-leaf nodes with different numbers of children " \
251 "are not allowed during simultaneous grid traversal");
252 apply_to_children_pair<treePathType,Node1::CHILDREN>::apply(std::forward<N1>(n1),
253 std::forward<N2>(n2),
256 v.post(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
269 #endif // DUNE_TYPETREE_APPLYTOCHILDRENTREEPAIR_HH TreePath ViewType
Definition: treepath.hh:36
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:568
Definition: treepath.hh:26
Type
Definition: treepath.hh:26
static const TreePathType::Type treePathType
Definition: traversalutilities.hh:30
Definition: accumulate_static.hh:12
Definition: treepath.hh:26