4 #ifndef DUNE_TYPETREE_PROXYNODE_HH
5 #define DUNE_TYPETREE_PROXYNODE_HH
10 #include <dune/common/shared_ptr.hh>
11 #include <dune/common/indices.hh>
21 template<
typename Node>
25 template<
typename ProxiedNode>
29 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
31 template<std::
size_t k>
34 static const bool value = !proxiedNodeIsConst;
39 template<
bool enabled = !proxiedNodeIsConst>
40 typename std::enable_if<enabled,Node&>::type
43 return static_cast<Node&
>(*this);
46 const Node& node()
const
48 return static_cast<const Node&
>(*this);
54 template<std::
size_t k>
56 :
public ProxiedNode::template
Child<k>
66 template<std::
size_t k>
67 typename std::enable_if<lazy_enabled<k>::value,
typename Child<k>::Type&>::type
68 child(Dune::index_constant<k> = {})
70 return node().proxiedNode().template child<k>();
77 template<std::
size_t k>
80 return node().proxiedNode().template child<k>();
87 template<std::
size_t k>
88 typename std::enable_if<lazy_enabled<k>::value,
typename Child<k>::Storage>::type
91 return node().proxiedNode().template childStorage<k>();
101 template<std::
size_t k>
104 return node().proxiedNode().template childStorage<k>();
108 template<std::
size_t k>
111 node().proxiedNode().template childStorage<k>() = stackobject_to_shared_ptr(
child);
115 template<std::
size_t k>
118 node().proxiedNode().template childStorage<k>() =
child;
123 return node().proxiedNode().nodeStorage();
134 template<
typename ProxiedNode>
141 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
143 template<
bool enabled = !proxiedNodeIsConst>
144 typename std::enable_if<enabled,Node&>::type
147 return static_cast<Node&
>(*this);
150 const Node& node()
const
152 return static_cast<const Node&
>(*this);
164 template<
bool enabled = !proxiedNodeIsConst>
165 typename std::enable_if<enabled,typename ProxiedNode::ChildType&>::type
168 return node().proxiedNode().child(i);
175 const typename ProxiedNode::ChildType&
child (std::size_t i)
const
177 return node().proxiedNode().child(i);
184 template<
bool enabled = !proxiedNodeIsConst>
185 typename std::enable_if<enabled,typename ProxiedNode::ChildStorageType>::type
188 return node().proxiedNode().childStorage(i);
198 typename ProxiedNode::ChildConstStorageType
childStorage (std::size_t i)
const
200 return node().proxiedNode().childStorage(i);
204 template<
bool enabled = !proxiedNodeIsConst>
205 void setChild (std::size_t i,
typename ProxiedNode::ChildType& t,
typename std::enable_if<enabled,void*>::type = 0)
207 node().proxiedNode().childStorage(i) = stackobject_to_shared_ptr(t);
211 template<
bool enabled = !proxiedNodeIsConst>
212 void setChild (std::size_t i,
typename ProxiedNode::ChildStorageType st,
typename std::enable_if<enabled,void*>::type = 0)
214 node().proxiedNode().childStorage(i) = st;
220 template<
typename Node,
typename NodeTag>
224 template<
typename Node>
230 template<
typename Node>
239 template<
typename Node>
255 template<
typename Node>
260 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
296 template<
bool enabled = !proxiedNodeIsConst>
297 typename std::enable_if<enabled,Node&>::type
310 template<
bool enabled = !proxiedNodeIsConst>
311 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
329 : _node(stackobject_to_shared_ptr(node))
340 std::shared_ptr<Node> _node;
typename std::decay_t< Node >::NodeTag NodeTag
Returns the node tag of the given Node.
Definition: nodeinterface.hh:62
std::integral_constant< std::size_t, degree(static_cast< std::decay_t< Node > * >(nullptr), NodeTag< std::decay_t< Node > >()) > StaticDegree
Returns the statically known degree of the given Node type as a std::integral_constant.
Definition: nodeinterface.hh:105
Definition: accumulate_static.hh:13
Tag designating a leaf node.
Definition: nodetags.hh:16
Tag designating a power node.
Definition: nodetags.hh:19
Tag designating a composite node.
Definition: nodetags.hh:22
Base class for nodes acting as a proxy for an existing node.
Definition: proxynode.hh:258
ProxyNode(Node &node)
Definition: proxynode.hh:328
const Node & proxiedNode() const
Returns the proxied node (const version).
Definition: proxynode.hh:304
static constexpr std::size_t degree()
Definition: proxynode.hh:284
Dune::TypeTree::NodeTag< Node > NodeTag
Definition: proxynode.hh:270
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: proxynode.hh:279
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: proxynode.hh:273
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: proxynode.hh:276
std::enable_if< enabled, Node & >::type proxiedNode()
Returns the proxied node.
Definition: proxynode.hh:298
static const std::size_t CHILDREN
The number of children.
Definition: proxynode.hh:282
Node ProxiedNode
Definition: proxynode.hh:268
std::shared_ptr< const Node > proxiedNodeStorage() const
Returns the storage of the proxied node (const version).
Definition: proxynode.hh:318
std::enable_if< enabled, std::shared_ptr< Node > >::type proxiedNodeStorage()
Returns the storage of the proxied node.
Definition: proxynode.hh:312
ProxyNode(std::shared_ptr< Node > node)
Definition: proxynode.hh:332
Mixin class providing methods for child access with compile-time parameter.
Definition: proxynode.hh:27
void setChild(typename Child< k >::storage_type child, typename std::enable_if< lazy_enabled< k >::value, void * >::type=0)
Sets the storage of the i-th child to the passed-in value.
Definition: proxynode.hh:116
const ProxiedNode::NodeStorage & nodeStorage() const
Definition: proxynode.hh:121
void setChild(typename Child< k >::type &child, typename std::enable_if< lazy_enabled< k >::value, void * >::type=0)
Sets the i-th child to the passed-in value.
Definition: proxynode.hh:109
std::enable_if< lazy_enabled< k >::value, typename Child< k >::Type & >::type child(Dune::index_constant< k >={})
Returns the i-th child.
Definition: proxynode.hh:68
std::enable_if< lazy_enabled< k >::value, typename Child< k >::Storage >::type childStorage()
Returns the storage of the i-th child.
Definition: proxynode.hh:89
Child< k >::ConstStorage childStorage() const
Returns the storage of the i-th child (const version).
Definition: proxynode.hh:102
const Child< k >::Type & child(Dune::index_constant< k >={}) const
Returns the i-th child (const version).
Definition: proxynode.hh:78
Access to the type and storage type of the i-th child.
Definition: proxynode.hh:57
Mixin class providing methods for child access with run-time parameter.
Definition: proxynode.hh:137
void setChild(std::size_t i, typename ProxiedNode::ChildStorageType st, typename std::enable_if< enabled, void * >::type=0)
Sets the stored value representing the i-th child to the passed-in value.
Definition: proxynode.hh:212
std::enable_if< enabled, typename ProxiedNode::ChildType & >::type child(std::size_t i)
Returns the i-th child.
Definition: proxynode.hh:166
const ProxiedNode::ChildType & child(std::size_t i) const
Returns the i-th child (const version).
Definition: proxynode.hh:175
void setChild(std::size_t i, typename ProxiedNode::ChildType &t, typename std::enable_if< enabled, void * >::type=0)
Sets the i-th child to the passed-in value.
Definition: proxynode.hh:205
ProxiedNode::ChildConstStorageType childStorage(std::size_t i) const
Returns the storage of the i-th child (const version).
Definition: proxynode.hh:198
std::enable_if< enabled, typename ProxiedNode::ChildStorageType >::type childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition: proxynode.hh:186
Tag-based dispatch to appropriate base class that provides necessary functionality.
Definition: proxynode.hh:221
Node::NodeStorage NodeStorage
Definition: proxynode.hh:235
Node::ChildTypes ChildTypes
Definition: proxynode.hh:234
Node::NodeStorage NodeStorage
Definition: proxynode.hh:244
Node::ChildType ChildType
Definition: proxynode.hh:243