3 #ifndef DUNE_FUNCTIONS_COMMON_TREEDATA_HH 4 #define DUNE_FUNCTIONS_COMMON_TREEDATA_HH 8 #include <dune/common/shared_ptr.hh> 27 template<
class SimpleNodeVisitorImp,
bool leafOnly>
29 public TypeTree::TreeVisitor,
30 public TypeTree::DynamicTraversal
35 template<
typename Node,
typename TreePath,
36 typename std::enable_if<(not leafOnly) and (not Node::isLeaf), int>::type = 0>
37 void pre(Node& node, TreePath treePath)
39 static_cast<SimpleNodeVisitorImp*
>(
this)->apply(node, treePath);
42 template<
typename Node,
typename TreePath,
43 typename std::enable_if<(leafOnly) and (not Node::isLeaf), int>::type = 0>
44 void pre(Node& node, TreePath treePath)
47 template<
typename Node,
typename TreePath>
48 void leaf(Node& node, TreePath treePath)
50 static_cast<SimpleNodeVisitorImp*
>(
this)->apply(node, treePath);
80 template<
class T,
template<
class>
class ND,
bool LO>
93 static const bool leafOnly = LO;
119 template<
typename Node,
typename TreePath>
120 void apply(Node& node, TreePath treePath)
122 auto&& index = node.treeIndex();
123 if (data_.size() < index+1)
124 data_.resize(index+1,
nullptr);
139 template<
typename Node,
typename TreePath>
140 void apply(Node& node, TreePath treePath)
142 auto&& index = node.treeIndex();
145 data_[index] =
nullptr;
159 template<
typename Node,
typename TreePath>
160 void apply(Node& node, TreePath treePath)
162 thisTD_[node] = otherTD_[node];
188 TypeTree::applyToTree(*tree_, InitVisitor(data_));
195 TypeTree::applyToTree(*tree_, InitVisitor(data_));
196 TypeTree::applyToTree(*tree_, CopyVisitor(*
this, other));
203 TypeTree::applyToTree(*tree_, DestroyVisitor(data_));
205 TypeTree::applyToTree(*tree_, CopyVisitor(*
this, other));
213 TypeTree::applyToTree(*tree_, DestroyVisitor(data_));
221 TypeTree::applyToTree(*tree_, DestroyVisitor(data_));
249 #endif // DUNE_FUNCTIONS_COMMON_TREEDATA_HH NodeData< Node > & operator[](const Node &node)
Get mutable reference to data associated to given node.
Definition: treedata.hh:226
InitVisitor(RawContainer &data)
Definition: treedata.hh:115
const Tree * tree_
Definition: treedata.hh:240
RawContainer data_
Definition: treedata.hh:241
Definition: treedata.hh:132
Mixin for visitors that should apply the same action on all nodes.
Definition: treedata.hh:28
RawContainer & data_
Definition: treedata.hh:148
void init(const Tree &tree)
Initialize from tree.
Definition: treedata.hh:183
void destroy()
Destroy data.
Definition: treedata.hh:210
Definition: treedata.hh:112
void apply(Node &node, TreePath treePath)
Definition: treedata.hh:120
void apply(Node &node, TreePath treePath)
Definition: treedata.hh:140
const TreeData & otherTD_
Definition: treedata.hh:166
NodeData< Node > NodeData
Template to determine the data type for given node type.
Definition: treedata.hh:97
Definition: treedata.hh:151
TreeData & operator=(const TreeData &other)
Copy assignment.
Definition: treedata.hh:200
TreeData & thisTD_
Definition: treedata.hh:165
RawContainer & data_
Definition: treedata.hh:129
void apply(Node &node, TreePath treePath)
Definition: treedata.hh:160
TreeData()
Default constructor.
Definition: treedata.hh:172
void pre(Node &node, TreePath treePath)
Definition: treedata.hh:37
const NodeData< Node > & operator[](const Node &node) const
Get reference to data associated to given node.
Definition: treedata.hh:233
typename Tree::size_type size_type
Type used for indices and size information.
Definition: treedata.hh:90
std::vector< void *> RawContainer
Definition: treedata.hh:100
Definition: polynomial.hh:7
TreeData(const TreeData &other)
Copy constructor.
Definition: treedata.hh:192
~TreeData()
Destructor.
Definition: treedata.hh:218
SubTree Tree
Type of tree the data is associated with.
Definition: treedata.hh:87
DestroyVisitor(RawContainer &data)
Definition: treedata.hh:135
CopyVisitor(TreeData &thisTD, const TreeData &otherTD)
Definition: treedata.hh:154
Container allowing to attach data to each node of a tree.
Definition: treedata.hh:81
void leaf(Node &node, TreePath treePath)
Definition: treedata.hh:48