3#ifndef DUNE_FUNCTIONS_COMMON_TREEDATA_HH
4#define DUNE_FUNCTIONS_COMMON_TREEDATA_HH
10#include <dune/typetree/pairtraversal.hh>
12#include <dune/functions/gridfunctions/gridviewentityset.hh>
13#include <dune/functions/gridfunctions/gridfunction.hh>
29template<
class SimpleNodeVisitorImp,
bool leafOnly>
37 template<
typename Node,
typename TreePath,
38 typename std::enable_if<(not leafOnly) and (not Node::isLeaf),
int>::type = 0>
39 void pre(Node& node, TreePath
treePath)
41 static_cast<SimpleNodeVisitorImp*
>(
this)->
apply(node,
treePath);
44 template<
typename Node,
typename TreePath,
45 typename std::enable_if<(leafOnly) and (not Node::isLeaf),
int>::type = 0>
46 void pre(Node& node, TreePath
treePath)
49 template<
typename Node,
typename TreePath>
50 void leaf(Node& node, TreePath
treePath)
52 static_cast<SimpleNodeVisitorImp*
>(
this)->
apply(node,
treePath);
82template<
class T,
template<
class>
class ND,
bool LO>
102 using RawContainer = std::vector<void*>;
117 InitVisitor(RawContainer& data) :
121 template<
typename Node,
typename TreePath>
124 auto&& index = node.treeIndex();
125 if (data_.size() < index+1)
126 data_.resize(index+1,
nullptr);
134 struct DestroyVisitor :
137 DestroyVisitor(RawContainer& data) :
141 template<
typename Node,
typename TreePath>
144 auto&& index = node.treeIndex();
145 auto p = (NodeData<Node>*)(data_[index]);
147 data_[index] =
nullptr;
154 public UniformNodeVisitor<CopyVisitor, leafOnly>
161 template<
typename Node,
typename TreePath>
164 thisTD_[node] = otherTD_[node];
Container allowing to attach data to each node of a tree.
Definition: treedata.hh:84
TreeData(const TreeData &other)
Copy constructor.
Definition: treedata.hh:194
void init(const Tree &tree)
Initialize from tree.
Definition: treedata.hh:185
static const bool leafOnly
Set if data should only be associated to the leafs.
Definition: treedata.hh:95
T Tree
Type of tree the data is associated with.
Definition: treedata.hh:89
void destroy()
Destroy data.
Definition: treedata.hh:212
const NodeData< Node > & operator[](const Node &node) const
Get reference to data associated to given node.
Definition: treedata.hh:235
TreeData & operator=(const TreeData &other)
Copy assignment.
Definition: treedata.hh:202
~TreeData()
Destructor.
Definition: treedata.hh:220
ND< Node > NodeData
Template to determine the data type for given node type.
Definition: treedata.hh:99
TreeData()
Default constructor.
Definition: treedata.hh:174
NodeData< Node > & operator[](const Node &node)
Get mutable reference to data associated to given node.
Definition: treedata.hh:228
typename Tree::size_type size_type
Type used for indices and size information.
Definition: treedata.hh:92
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:46
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:213
Dune namespace.
Definition: alignedallocator.hh:14
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Mixin base class for visitors that only need a dynamic TreePath during traversal.
Definition: visitor.hh:324
Convenience base class for visiting the entire tree.
Definition: visitor.hh:333