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>
12 #include <dune/common/std/type_traits.hh>
22 template<
typename Node>
26 template<
typename ProxiedNode>
30 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
32 template<std::
size_t k>
35 static const bool value = !proxiedNodeIsConst;
40 template<
bool enabled = !proxiedNodeIsConst>
41 typename std::enable_if<enabled,Node&>::type
44 return static_cast<Node&
>(*this);
47 const Node& node ()
const
49 return static_cast<const Node&
>(*this);
55 template<std::
size_t k>
57 :
public ProxiedNode::template
Child<k>
67 template<std::size_t k,
68 typename std::enable_if<lazy_enabled<k>::value,
int>::type = 0>
69 auto&
child (index_constant<k> = {})
71 return node().proxiedNode().template child<k>();
78 template<std::
size_t k>
79 const auto&
child (index_constant<k> = {})
const
81 return node().proxiedNode().template child<k>();
88 template<std::size_t k,
89 typename std::enable_if<lazy_enabled<k>::value,
int>::type = 0>
92 return node().proxiedNode().template childStorage<k>();
102 template<std::
size_t k>
105 return node().proxiedNode().template childStorage<k>();
109 template<std::
size_t k,
class ProxyChild>
110 void setChild (ProxyChild&&
child,
typename std::enable_if<lazy_enabled<k>::value,
void*>::type = 0)
112 node().proxiedNode().template setChild<k>(std::forward<ProxyChild>(
child));
117 return node().proxiedNode().nodeStorage();
128 template<
typename ProxiedNode>
135 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
137 template<
bool enabled = !proxiedNodeIsConst>
138 typename std::enable_if<enabled,Node&>::type
141 return static_cast<Node&
>(*this);
144 const Node& node ()
const
146 return static_cast<const Node&
>(*this);
158 template<
bool enabled = !proxiedNodeIsConst,
159 typename std::enable_if<enabled, int>::type = 0>
162 return node().proxiedNode().child(i);
169 const auto&
child (std::size_t i)
const
171 return node().proxiedNode().child(i);
178 template<
bool enabled = !proxiedNodeIsConst,
179 typename std::enable_if<enabled, int>::type = 0>
182 return node().proxiedNode().childStorage(i);
194 return node().proxiedNode().childStorage(i);
198 template<
class ProxyChild,
bool enabled = !proxiedNodeIsConst>
199 void setChild (std::size_t i, ProxyChild&&
child,
typename std::enable_if<enabled,void*>::type = 0)
201 node().proxiedNode().setChild(i, std::forward<ProxyChild>(
child));
207 template<
typename Node,
typename NodeTag>
211 template<
typename Node>
217 template<
typename Node>
226 template<
typename Node>
235 template<
typename Node>
250 template<
typename Node>
254 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
257 using HasStaticDegree = index_constant<
N::degree()>;
260 static constexpr
bool hasStaticDegree = Std::is_detected<HasStaticDegree, N>::value;
282 [[deprecated(
"Will be removed after release 2.9. Use degree()")]]
283 static const std::size_t
CHILDREN = Dune::Std::detected_or_t<
284 std::integral_constant<std::size_t,std::numeric_limits<std::size_t>::max()>,
289 template <
class N = Node,
290 std::enable_if_t<hasStaticDegree<N>,
int> = 0>
296 template <
class N = Node,
297 std::enable_if_t<not hasStaticDegree<N>,
int> = 0>
310 template<
bool enabled = !proxiedNodeIsConst>
311 typename std::enable_if<enabled,Node&>::type
324 template<
bool enabled = !proxiedNodeIsConst>
325 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
343 : _node(stackobject_to_shared_ptr(node))
347 : _node(std::move(node))
354 std::shared_ptr<Node> _node;
std::size_t degree(const Node &node)
Returns the degree of node as run time information.
Definition: nodeinterface.hh:85
typename std::decay_t< Node >::NodeTag NodeTag
Returns the node tag of the given Node.
Definition: nodeinterface.hh:76
decltype(Node::degree()) StaticDegree
Returns the statically known degree of the given Node type as a std::integral_constant.
Definition: nodeinterface.hh:113
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 power node with runtime degree.
Definition: nodetags.hh:22
Tag designating a composite node.
Definition: nodetags.hh:25
Base class for nodes acting as a proxy for an existing node.
Definition: proxynode.hh:253
ProxyNode(Node &node)
Definition: proxynode.hh:342
const Node & proxiedNode() const
Returns the proxied node (const version).
Definition: proxynode.hh:318
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
auto degree() const
Definition: proxynode.hh:298
std::enable_if< enabled, Node & >::type proxiedNode()
Returns the proxied node.
Definition: proxynode.hh:312
static const std::size_t CHILDREN
The number of children.
Definition: proxynode.hh:283
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:332
static constexpr auto degree()
Definition: proxynode.hh:291
std::enable_if< enabled, std::shared_ptr< Node > >::type proxiedNodeStorage()
Returns the storage of the proxied node.
Definition: proxynode.hh:326
ProxyNode(std::shared_ptr< Node > node)
Definition: proxynode.hh:346
Mixin class providing methods for child access with compile-time parameter.
Definition: proxynode.hh:28
const ProxiedNode::NodeStorage & nodeStorage() const
Definition: proxynode.hh:115
auto & child(index_constant< k >={})
Returns the i-th child.
Definition: proxynode.hh:69
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:110
const auto & child(index_constant< k >={}) const
Returns the i-th child (const version).
Definition: proxynode.hh:79
auto childStorage(index_constant< k >={})
Returns the storage of the i-th child.
Definition: proxynode.hh:90
auto childStorage(index_constant< k >={}) const
Returns the storage of the i-th child (const version).
Definition: proxynode.hh:103
Access to the type and storage type of the i-th child.
Definition: proxynode.hh:58
Mixin class providing methods for child access with run-time parameter.
Definition: proxynode.hh:131
auto childStorage(std::size_t i) const
Returns the storage of the i-th child (const version).
Definition: proxynode.hh:192
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:199
auto & child(std::size_t i)
Returns the i-th child.
Definition: proxynode.hh:160
const auto & child(std::size_t i) const
Returns the i-th child (const version).
Definition: proxynode.hh:169
auto childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition: proxynode.hh:180
Tag-based dispatch to appropriate base class that provides necessary functionality.
Definition: proxynode.hh:208
Node::NodeStorage NodeStorage
Definition: proxynode.hh:222
Node::ChildTypes ChildTypes
Definition: proxynode.hh:221
Node::NodeStorage NodeStorage
Definition: proxynode.hh:231
Node::ChildType ChildType
Definition: proxynode.hh:230
Node::NodeStorage NodeStorage
Definition: proxynode.hh:240
Node::ChildType ChildType
Definition: proxynode.hh:239