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 template<
typename Node,
typename Visitor>
39 static void apply(Node&& node, Visitor&& visitor)
41 ApplyToTree<tpType,NodeTag<Node>>::apply(std::forward<Node>(node),
42 std::forward<Visitor>(visitor),
43 TreePathFactory<tpType>::create(node).mutablePath());
50 template<TreePathType::Type tpType,
typename NodeTag>
51 struct ApplyToTree<tpType,
NodeTag,false>
56 template<
typename Node,
typename Visitor,
typename TreePath>
57 static void apply(
const Node& node,
const Visitor& visitor, TreePath treePath)
69 template<TreePathType::Type tpType>
70 struct ApplyToTree<tpType,LeafNodeTag,true>
73 template<
typename N,
typename V,
typename TreePath>
74 static void apply(N&& n, V&& v, TreePath tp)
76 v.leaf(std::forward<N>(n),tp.view());
90 struct ApplyToTree<TreePathType::
fullyStatic,PowerNodeTag,true>
91 :
public ApplyToGenericCompositeNode
99 struct ApplyToTree<TreePathType::
dynamic,PowerNodeTag,true>
102 template<
typename N,
typename V,
typename TreePath>
103 static void apply(N&& n, V&& v, TreePath tp)
106 v.pre(std::forward<N>(n),tp.view());
109 typedef typename std::remove_reference<N>::type Node;
110 typedef typename std::remove_reference<V>::type Visitor;
118 const bool visit = Visitor::template VisitChild<Node,C,typename TreePath::ViewType>::value;
121 for (std::size_t k = 0; k <
degree(n); ++k)
124 v.beforeChild(std::forward<N>(n),n.child(k),tp.view(),k);
130 ApplyToTree<Visitor::treePathType,NodeTag<C>,visit>::apply(n.child(k),std::forward<V>(v),tp);
136 v.afterChild(std::forward<N>(n),n.child(k),tp.view(),k);
140 v.in(std::forward<N>(n),tp.view());
144 v.post(std::forward<N>(n),tp.view());
156 template<TreePathType::Type treePathType>
158 :
public ApplyToGenericCompositeNode
166 template<
class PreFunc,
class LeafFunc,
class PostFunc>
178 template<
typename Node,
typename TreePath>
181 preFunc_(node, treePath);
184 template<
typename Node,
typename TreePath>
187 leafFunc_(node, treePath);
190 template<
typename Node,
typename TreePath>
193 postFunc_(node, treePath);
202 template<
class PreFunc,
class LeafFunc,
class PostFunc>
230 template<
typename Tree,
typename Visitor>
234 std::forward<Visitor>(visitor));
248 template<
class Tree,
class PreFunc,
class LeafFunc,
class PostFunc>
249 void forEachNode(Tree&& tree, PreFunc&& preFunc, LeafFunc&& leafFunc, PostFunc&& postFunc)
264 template<
class Tree,
class InnerFunc,
class LeafFunc>
265 void forEachNode(Tree&& tree, InnerFunc&& innerFunc, LeafFunc&& leafFunc)
267 auto nop = [](
auto&&... args) {};
280 template<
class Tree,
class NodeFunc>
295 template<
class Tree,
class LeafFunc>
298 auto nop = [](
auto&&... args) {};
307 #endif // DUNE_TYPETREE_TRAVERSAL_HH Definition: treepath.hh:26
Definition: treepath.hh:26
static const TreePathType::Type treePathType
Definition: traversalutilities.hh:30
void pre(Node &&node, TreePath treePath)
Definition: traversal.hh:179
Convenience base class for visiting the entire tree.
Definition: visitor.hh:330
Type
Definition: treepath.hh:26
Definition: accumulate_static.hh:13
void forEachNode(Tree &&tree, PreFunc &&preFunc, LeafFunc &&leafFunc, PostFunc &&postFunc)
Traverse tree and visit each node.
Definition: traversal.hh:249
void leaf(Node &&node, TreePath treePath)
Definition: traversal.hh:185
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:231
std::size_t degree(const Node &node)
Returns the degree of node as run time information.
Definition: nodeinterface.hh:71
auto callbackVisitor(PreFunc &preFunc, LeafFunc &leafFunc, PostFunc &postFunc)
Definition: traversal.hh:203
CallbackVisitor(PreFunc &preFunc, LeafFunc &leafFunc, PostFunc &postFunc)
Definition: traversal.hh:172
void forEachLeafNode(Tree &&tree, LeafFunc &&leafFunc)
Traverse tree and visit each leaf node.
Definition: traversal.hh:296
Definition: traversal.hh:167
typename std::decay_t< Node >::NodeTag NodeTag
Returns the node tag of the given Node.
Definition: nodeinterface.hh:62
Mixin base class for visitors that only need a dynamic TreePath during traversal. ...
Definition: visitor.hh:323
Definition: treepath.hh:30
void post(Node &&node, TreePath treePath)
Definition: traversal.hh:191