4 #ifndef DUNE_TYPETREE_PAIRTRAVERSAL_HH
5 #define DUNE_TYPETREE_PAIRTRAVERSAL_HH
20 #ifndef DOXYGEN // these are all internals and not public API. Only access is using applyToTree().
22 template<TreePathType::Type tpType>
23 struct ApplyToTreePair<tpType,StartTag,StartTag,true>
26 #if HAVE_RVALUE_REFERENCES
28 template<
typename Node1,
typename Node2,
typename Visitor>
29 static void apply(Node1&& node1, Node2&& node2, Visitor&& visitor)
31 ApplyToTreePair<tpType,
32 typename remove_reference<Node1>::type::NodeTag,
33 typename remove_reference<Node2>::type::NodeTag
34 >::apply(std::forward<Node1>(node1),
35 std::forward<Node2>(node2),
36 std::forward<Visitor>(visitor),
37 TreePathFactory<tpType>::create(node1).mutablePath());
47 template<
typename Node1,
typename Node2,
typename Visitor>
49 typename enable_if<!(IsConst<Node1>::Value || IsConst<Node2>::Value)>::type
50 apply(Node1& node1, Node2& node2, Visitor& visitor)
52 ApplyToTreePair<tpType,
53 typename Node1::NodeTag,
54 typename Node2::NodeTag
58 TreePathFactory<tpType>::create(node1).mutablePath());
61 template<
typename Node1,
typename Node2,
typename Visitor>
62 static void apply(
const Node1& node1,
const Node2& node2, Visitor& visitor)
64 ApplyToTreePair<tpType,
65 typename Node1::NodeTag,
66 typename Node2::NodeTag
67 >::apply(const_cast<const Node1&>(node1),
68 const_cast<const Node2&>(node2),
70 TreePathFactory<tpType>::create(node1).mutablePath());
79 template<
typename Node1,
typename Node2,
typename Visitor>
81 typename enable_if<!(IsConst<Node1>::Value || IsConst<Node2>::Value)>::type
82 apply(Node1& node1, Node2& node2,
const Visitor& visitor)
84 ApplyToTreePair<tpType,
85 typename Node1::NodeTag,
86 typename Node2::NodeTag
90 TreePathFactory<tpType>::create(node1).mutablePath());
93 template<
typename Node1,
typename Node2,
typename Visitor>
94 static void apply(
const Node1& node1,
const Node2& node2,
const Visitor& visitor)
96 ApplyToTreePair<tpType,
97 typename Node1::NodeTag,
98 typename Node2::NodeTag
99 >::apply(const_cast<const Node1&>(node1),
100 const_cast<const Node2&>(node2),
102 TreePathFactory<tpType>::create(node1).mutablePath());
105 #endif // HAVE_RVALUE_REFERENCES
111 template<TreePathType::Type tpType,
typename Tag1,
typename Tag2>
112 struct ApplyToTreePair<tpType,Tag1,Tag2,false>
114 template<
typename Node1,
typename Node2,
typename Visitor,
typename TreePath>
115 static void apply(
const Node1& node1,
const Node2& node2,
const Visitor& visitor, TreePath treePath)
168 template<TreePathType::Type treePathType,
typename FirstTag,
typename SecondTag>
169 struct ApplyToTreePair<
treePathType,FirstTag,SecondTag,true>
170 :
public ApplyToGenericCompositeNodePair<treePathType>
181 struct ApplyToTreePair<TreePathType::
dynamic,PowerNodeTag,PowerNodeTag,true>
184 #if HAVE_RVALUE_REFERENCES
186 template<
typename N1,
typename N2,
typename V,
typename TreePath>
187 static void apply(N1&& n1, N2&& n2, V&& v, TreePath tp)
189 v.pre(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
190 typedef typename remove_reference<N1>::type Node1;
191 typedef typename remove_reference<N2>::type Node2;
194 dune_static_assert(Node1::CHILDREN == Node2::CHILDREN,
195 "non-leaf nodes with different numbers of children " \
196 "are not allowed during simultaneous grid traversal");
197 const bool visit = std::remove_reference<V>::type
199 for (std::size_t k = 0; k < Node1::CHILDREN; ++k)
201 v.beforeChild(std::forward<N1>(n1),n1.child(k),std::forward<N2>(n2),n2.child(k),tp.view(),k);
204 typename C1::NodeTag,
205 typename C2::NodeTag,
206 visit>::apply(n1.child(k),
211 v.afterChild(std::forward<N1>(n1),n1.child(k),std::forward<N2>(n2),n2.child(k),tp.view(),k);
212 if (k < Node1::CHILDREN-1)
213 v.in(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
215 v.post(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
220 template<
typename N1,
typename N2,
typename V,
typename TreePath>
221 static void apply(N1& n1, N2& n2, V& v, TreePath tp)
223 v.pre(n1,n2,tp.view());
226 dune_static_assert(N1::CHILDREN == N2::CHILDREN,
227 "non-leaf nodes with different numbers of children " \
228 "are not allowed during simultaneous grid traversal");
230 for (std::size_t k = 0; k < N1::CHILDREN; ++k)
232 v.beforeChild(n1,n1.child(k),n2,n2.child(k),tp.view(),k);
235 typename C1::NodeTag,
236 typename C2::NodeTag,
237 visit>::apply(n1.child(k),
242 v.afterChild(n1,n1.child(k),n2,n2.child(k),tp.view(),k);
243 if (k < N1::CHILDREN-1)
244 v.in(n1,n2,tp.view());
246 v.post(n1,n2,tp.view());
249 template<
typename N1,
typename N2,
typename V,
typename TreePath>
250 static void apply(
const N1& n1,
const N2& n2, V& v, TreePath tp)
252 v.pre(n1,n2,tp.view());
255 dune_static_assert(N1::CHILDREN == N2::CHILDREN,
256 "non-leaf nodes with different numbers of children " \
257 "are not allowed during simultaneous grid traversal");
258 const bool visit = V::template VisitChild<N1,C1,N2,C2,typename TreePath::ViewType>::value;
259 for (std::size_t k = 0; k < N1::CHILDREN; ++k)
261 v.beforeChild(n1,n1.child(k),n2,n2.child(k),tp.view(),k);
264 typename C1::NodeTag,
265 typename C2::NodeTag,
266 visit>::apply(n1.child(k),
271 v.afterChild(n1,n1.child(k),n2,n2.child(k),tp.view(),k);
272 if (k < N1::CHILDREN-1)
273 v.in(n1,n2,tp.view());
275 v.post(n1,n2,tp.view());
278 template<
typename N1,
typename N2,
typename V,
typename TreePath>
279 static void apply(N1& n1, N2& n2,
const V& v, TreePath tp)
281 v.pre(n1,n2,tp.view());
284 dune_static_assert(N1::CHILDREN == N2::CHILDREN,
285 "non-leaf nodes with different numbers of children " \
286 "are not allowed during simultaneous grid traversal");
287 const bool visit = V::template VisitChild<N1,C1,N2,C2,typename TreePath::ViewType>::value;
288 for (std::size_t k = 0; k < N1::CHILDREN; ++k)
290 v.beforeChild(n1,n1.child(k),n2,n2.child(k),tp.view(),k);
293 typename C1::NodeTag,
294 typename C2::NodeTag,
295 visit>::apply(n1.child(k),
300 v.afterChild(n1,n1.child(k),n2,n2.child(k),tp.view(),k);
301 if (k < N1::CHILDREN-1)
302 v.in(n1,n2,tp.view());
304 v.post(n1,n2,tp.view());
307 template<
typename N1,
typename N2,
typename V,
typename TreePath>
308 static void apply(
const N1& n1,
const N2& n2,
const V& v, TreePath tp)
310 v.pre(n1,n2,tp.view());
313 dune_static_assert(N1::CHILDREN == N2::CHILDREN,
314 "non-leaf nodes with different numbers of children " \
315 "are not allowed during simultaneous grid traversal");
316 const bool visit = V::template VisitChild<N1,C1,N2,C2,typename TreePath::ViewType>::value;
317 for (std::size_t k = 0; k < N1::CHILDREN; ++k)
319 v.beforeChild(n1,n1.child(k),n2,n2.child(k),tp.view(),k);
322 typename C1::NodeTag,
323 typename C2::NodeTag,
324 visit>::apply(n1.child(k),
329 v.afterChild(n1,n1.child(k),n2,n2.child(k),tp.view(),k);
330 if (k < N1::CHILDREN-1)
331 v.in(n1,n2,tp.view());
333 v.post(n1,n2,tp.view());
336 #endif // HAVE_RVALUE_REFERENCES
342 #if HAVE_RVALUE_REFERENCES || DOXYGEN
359 template<
typename Tree1,
typename Tree2,
typename Visitor>
363 std::forward<Tree2>(tree2),
364 std::forward<Visitor>(visitor));
369 template<
typename Tree1,
typename Tree2,
typename Visitor>
372 ApplyToTreePair<Visitor::treePathType>::apply(tree1,tree2,visitor);
375 template<
typename Tree1,
typename Tree2,
typename Visitor>
376 void applyToTreePair(
const Tree1& tree1,
const Tree2& tree2, Visitor& visitor)
378 ApplyToTreePair<Visitor::treePathType>::apply(tree1,tree2,visitor);
381 template<
typename Tree1,
typename Tree2,
typename Visitor>
382 void applyToTreePair(Tree1& tree1, Tree2& tree2,
const Visitor& visitor)
384 ApplyToTreePair<Visitor::treePathType>::apply(tree1,tree2,visitor);
387 template<
typename Tree1,
typename Tree2,
typename Visitor>
388 void applyToTreePair(
const Tree1& tree1,
const Tree2& tree2,
const Visitor& visitor)
390 ApplyToTreePair<Visitor::treePathType>::apply(tree1,tree2,visitor);
393 #endif // HAVE_RVALUE_REFERENCES || DOXYGEN
400 #endif // DUNE_TYPETREE_PAIRTRAVERSAL_HH
Definition: treepath.hh:26
static const TreePathType::Type treePathType
Definition: traversalutilities.hh:30
static const std::size_t value
Definition: compositenode.hh:38
Type
Definition: treepath.hh:26
void applyToTreePair(Tree1 &&tree1, Tree2 &&tree2, Visitor &&visitor)
Apply visitor to a pair of TypeTrees.
Definition: pairtraversal.hh:360