6#ifndef DUNE_TYPETREE_PROXYNODE_HH
7#define DUNE_TYPETREE_PROXYNODE_HH
12#include <dune/common/shared_ptr.hh>
13#include <dune/common/indices.hh>
14#include <dune/common/std/type_traits.hh>
24 template<
typename Node>
28 template<
typename ProxiedNode>
32 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
34 template<std::
size_t k>
37 static const bool value = !proxiedNodeIsConst;
42 template<
bool enabled = !proxiedNodeIsConst>
43 typename std::enable_if<enabled,Node&>::type
46 return static_cast<Node&
>(*this);
49 const Node& node ()
const
51 return static_cast<const Node&
>(*this);
57 template<std::
size_t k>
59 :
public ProxiedNode::template
Child<k>
69 template<std::size_t k,
70 typename std::enable_if<lazy_enabled<k>::value,
int>::type = 0>
71 auto&
child (index_constant<k> = {})
73 return node().proxiedNode().template child<k>();
80 template<std::
size_t k>
81 const auto&
child (index_constant<k> = {})
const
83 return node().proxiedNode().template child<k>();
90 template<std::size_t k,
91 typename std::enable_if<lazy_enabled<k>::value,
int>::type = 0>
94 return node().proxiedNode().template childStorage<k>();
104 template<std::
size_t k>
107 return node().proxiedNode().template childStorage<k>();
111 template<std::
size_t k,
class ProxyChild>
112 void setChild (ProxyChild&&
child,
typename std::enable_if<lazy_enabled<k>::value,
void*>::type = 0)
114 node().proxiedNode().template setChild<k>(std::forward<ProxyChild>(
child));
119 return node().proxiedNode().nodeStorage();
130 template<
typename ProxiedNode>
137 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
139 template<
bool enabled = !proxiedNodeIsConst>
140 typename std::enable_if<enabled,Node&>::type
143 return static_cast<Node&
>(*this);
146 const Node& node ()
const
148 return static_cast<const Node&
>(*this);
160 template<
bool enabled = !proxiedNodeIsConst,
161 typename std::enable_if<enabled, int>::type = 0>
164 return node().proxiedNode().child(i);
171 const auto&
child (std::size_t i)
const
173 return node().proxiedNode().child(i);
180 template<
bool enabled = !proxiedNodeIsConst,
181 typename std::enable_if<enabled, int>::type = 0>
184 return node().proxiedNode().childStorage(i);
196 return node().proxiedNode().childStorage(i);
200 template<
class ProxyChild,
bool enabled = !proxiedNodeIsConst>
201 void setChild (std::size_t i, ProxyChild&&
child,
typename std::enable_if<enabled,void*>::type = 0)
203 node().proxiedNode().setChild(i, std::forward<ProxyChild>(
child));
209 template<
typename Node,
typename NodeTag>
213 template<
typename Node>
219 template<
typename Node>
228 template<
typename Node>
237 template<
typename Node>
252 template<
typename Node>
256 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
259 using HasStaticDegree = index_constant<N::degree()>;
262 static constexpr bool hasStaticDegree = Std::is_detected<HasStaticDegree, N>::value;
283 template <
class N = Node,
284 std::enable_if_t<hasStaticDegree<N>,
int> = 0>
290 template <
class N = Node,
291 std::enable_if_t<not hasStaticDegree<N>,
int> = 0>
304 template<
bool enabled = !proxiedNodeIsConst>
305 typename std::enable_if<enabled,Node&>::type
318 template<
bool enabled = !proxiedNodeIsConst>
319 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
337 : _node(stackobject_to_shared_ptr(node))
341 : _node(std::move(node))
348 std::shared_ptr<Node> _node;
typename std::decay_t< Node >::NodeTag NodeTag
Returns the node tag of the given Node.
Definition nodeinterface.hh:70
Definition accumulate_static.hh:16
Tag designating a leaf node.
Definition nodetags.hh:18
Tag designating a power node.
Definition nodetags.hh:21
Tag designating a power node with runtime degree.
Definition nodetags.hh:24
Tag designating a composite node.
Definition nodetags.hh:27
Base class for nodes acting as a proxy for an existing node.
Definition proxynode.hh:255
ProxyNode(Node &node)
Definition proxynode.hh:336
Dune::TypeTree::NodeTag< Node > NodeTag
Definition proxynode.hh:272
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition proxynode.hh:281
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition proxynode.hh:275
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition proxynode.hh:278
auto degree() const
Definition proxynode.hh:292
std::enable_if< enabled, Node & >::type proxiedNode()
Returns the proxied node.
Definition proxynode.hh:306
std::shared_ptr< const Node > proxiedNodeStorage() const
Returns the storage of the proxied node (const version).
Definition proxynode.hh:326
Node ProxiedNode
Definition proxynode.hh:270
std::enable_if< enabled, std::shared_ptr< Node > >::type proxiedNodeStorage()
Returns the storage of the proxied node.
Definition proxynode.hh:320
static constexpr auto degree()
Definition proxynode.hh:285
ProxyNode(std::shared_ptr< Node > node)
Definition proxynode.hh:340
const Node & proxiedNode() const
Returns the proxied node (const version).
Definition proxynode.hh:312
Mixin class providing methods for child access with compile-time parameter.
Definition proxynode.hh:30
auto & child(index_constant< k >={})
Returns the i-th child.
Definition proxynode.hh:71
void setChild(ProxyChild &&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:112
const ProxiedNode::NodeStorage & nodeStorage() const
Definition proxynode.hh:117
auto childStorage(index_constant< k >={})
Returns the storage of the i-th child.
Definition proxynode.hh:92
const auto & child(index_constant< k >={}) const
Returns the i-th child (const version).
Definition proxynode.hh:81
auto childStorage(index_constant< k >={}) const
Returns the storage of the i-th child (const version).
Definition proxynode.hh:105
Access to the type and storage type of the i-th child.
Definition proxynode.hh:60
Mixin class providing methods for child access with run-time parameter.
Definition proxynode.hh:133
auto & child(std::size_t i)
Returns the i-th child.
Definition proxynode.hh:162
auto childStorage(std::size_t i) const
Returns the storage of the i-th child (const version).
Definition proxynode.hh:194
void setChild(std::size_t i, ProxyChild &&child, typename std::enable_if< enabled, void * >::type=0)
Sets the i-th child to the passed-in value.
Definition proxynode.hh:201
const auto & child(std::size_t i) const
Returns the i-th child (const version).
Definition proxynode.hh:171
auto childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition proxynode.hh:182
Tag-based dispatch to appropriate base class that provides necessary functionality.
Definition proxynode.hh:210
Node::NodeStorage NodeStorage
Definition proxynode.hh:224
Node::ChildTypes ChildTypes
Definition proxynode.hh:223
Node::NodeStorage NodeStorage
Definition proxynode.hh:233
Node::ChildType ChildType
Definition proxynode.hh:232
Node::NodeStorage NodeStorage
Definition proxynode.hh:242
Node::ChildType ChildType
Definition proxynode.hh:241