Loading...
Searching...
No Matches
traversalutilities.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-PDELab-exception
#ifndef DUNE_TYPETREE_TRAVERSALUTILITIES_HH
#define DUNE_TYPETREE_TRAVERSALUTILITIES_HH
#include <dune/typetree/traversal.hh>
namespace Dune {
namespace TypeTree {
namespace {
template<typename F, typename R, typename ResultType>
struct LeafReductionVisitor
: public TypeTree::TreeVisitor
{
static const TreePathType::Type treePathType = TreePathType::dynamic;
template<typename Node, typename TreePath>
void leaf(const Node& node, TreePath treePath)
{
_value = _reduction(_value,_functor(node,treePath));
}
LeafReductionVisitor(F functor, R reduction, ResultType startValue)
: _functor(functor)
, _reduction(reduction)
, _value(startValue)
{}
ResultType result() { return _value; }
F _functor;
R _reduction;
ResultType _value;
};
} // anonymous namespace
template<typename ResultType, typename Tree, typename F, typename R>
ResultType reduceOverLeafs(const Tree& tree, F functor, R reduction, ResultType startValue)
{
LeafReductionVisitor<F,R,ResultType> visitor(functor,reduction,startValue);
TypeTree::applyToTree(tree,visitor);
return visitor.result();
}
} // namespace TypeTree
} //namespace Dune
#endif // DUNE_TYPETREE_TRAVERSALUTILITIES_HH
traversal.hh
Dune::TypeTree::reduceOverLeafs
ResultType reduceOverLeafs(const Tree &tree, F functor, R reduction, ResultType startValue)
Calculate a quantity as a reduction over the leaf nodes of a TypeTree.
Definition traversalutilities.hh:83
Dune::TypeTree::applyToTree
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition traversal.hh:184
Dune
Definition accumulate_static.hh:17
Dune::TypeTree
Definition accumulate_static.hh:18
Dune::TypeTree::TreePathType::Type
Type
Definition treepath.hh:108
Dune::TypeTree::TreePathType::dynamic
@ dynamic
Definition treepath.hh:108