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>
29 template<
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);
82 template<
class T,
template<
class>
class ND,
bool LO>
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);
141 template<
typename Node,
typename TreePath>
142 void apply(Node& node, TreePath treePath)
144 auto&& index = node.treeIndex();
147 data_[index] =
nullptr;
161 template<
typename Node,
typename TreePath>
162 void apply(Node& node, TreePath treePath)
Definition: polynomial.hh:10
Mixin for visitors that should apply the same action on all nodes.
Definition: treedata.hh:33
void pre(Node &node, TreePath treePath)
Definition: treedata.hh:39
void leaf(Node &node, TreePath treePath)
Definition: treedata.hh:50
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
const Tree * tree_
Definition: treedata.hh:242
void destroy()
Destroy data.
Definition: treedata.hh:212
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
std::vector< void * > RawContainer
Definition: treedata.hh:102
typename Tree::size_type size_type
Type used for indices and size information.
Definition: treedata.hh:92
NodeData< Node > & operator[](const Node &node)
Get mutable reference to data associated to given node.
Definition: treedata.hh:228
const NodeData< Node > & operator[](const Node &node) const
Get reference to data associated to given node.
Definition: treedata.hh:235
RawContainer data_
Definition: treedata.hh:243
Definition: treedata.hh:116
InitVisitor(RawContainer &data)
Definition: treedata.hh:117
void apply(Node &node, TreePath treePath)
Definition: treedata.hh:122
RawContainer & data_
Definition: treedata.hh:131
Definition: treedata.hh:136
RawContainer & data_
Definition: treedata.hh:150
DestroyVisitor(RawContainer &data)
Definition: treedata.hh:137
void apply(Node &node, TreePath treePath)
Definition: treedata.hh:142
Definition: treedata.hh:155
CopyVisitor(TreeData &thisTD, const TreeData &otherTD)
Definition: treedata.hh:156
void apply(Node &node, TreePath treePath)
Definition: treedata.hh:162
TreeData & thisTD_
Definition: treedata.hh:167
const TreeData & otherTD_
Definition: treedata.hh:168