3#ifndef DUNE_FUNCTIONS_COMMON_TREEDATA_HH
4#define DUNE_FUNCTIONS_COMMON_TREEDATA_HH
8#include <dune/common/shared_ptr.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>
31 public TypeTree::TreeVisitor,
32 public TypeTree::DynamicTraversal
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>
122 void apply(Node& node, TreePath 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>
142 void apply(Node& node, TreePath 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>
162 void apply(Node& node, TreePath treePath)
164 thisTD_[node] = otherTD_[node];
190 TypeTree::applyToTree(*tree_, InitVisitor(data_));
197 TypeTree::applyToTree(*tree_, InitVisitor(data_));
198 TypeTree::applyToTree(*tree_, CopyVisitor(*
this, other));
205 TypeTree::applyToTree(*tree_, DestroyVisitor(data_));
207 TypeTree::applyToTree(*tree_, CopyVisitor(*
this, other));
215 TypeTree::applyToTree(*tree_, DestroyVisitor(data_));
223 TypeTree::applyToTree(*tree_, DestroyVisitor(data_));
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
Definition: polynomial.hh:10