Dune Core Modules (2.9.0)

proxynode.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_TYPETREE_PROXYNODE_HH
5#define DUNE_TYPETREE_PROXYNODE_HH
6
7#include <type_traits>
8#include <dune/typetree/nodeinterface.hh>
9#include <dune/typetree/nodetags.hh>
11#include <dune/common/indices.hh>
12#include <dune/common/std/type_traits.hh>
13
14namespace Dune {
15 namespace TypeTree {
16
22 template<typename Node>
23 class ProxyNode;
24
26 template<typename ProxiedNode>
28 {
29
30 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
31
32 template<std::size_t k>
33 struct lazy_enabled
34 {
35 static const bool value = !proxiedNodeIsConst;
36 };
37
39
40 template<bool enabled = !proxiedNodeIsConst>
41 typename std::enable_if<enabled,Node&>::type
42 node ()
43 {
44 return static_cast<Node&>(*this);
45 }
46
47 const Node& node () const
48 {
49 return static_cast<const Node&>(*this);
50 }
51
52 public:
53
55 template<std::size_t k>
56 struct Child
57 : public ProxiedNode::template Child<k>
58 {};
59
62
64
67 template<std::size_t k,
68 typename std::enable_if<lazy_enabled<k>::value, int>::type = 0>
69 auto& child (index_constant<k> = {})
70 {
71 return node().proxiedNode().template child<k>();
72 }
73
75
78 template<std::size_t k>
79 const auto& child (index_constant<k> = {}) const
80 {
81 return node().proxiedNode().template child<k>();
82 }
83
85
88 template<std::size_t k,
89 typename std::enable_if<lazy_enabled<k>::value, int>::type = 0>
90 auto childStorage (index_constant<k> = {})
91 {
92 return node().proxiedNode().template childStorage<k>();
93 }
94
96
102 template<std::size_t k>
103 auto childStorage (index_constant<k> = {}) const
104 {
105 return node().proxiedNode().template childStorage<k>();
106 }
107
109 template<std::size_t k, class ProxyChild>
110 void setChild (ProxyChild&& child, typename std::enable_if<lazy_enabled<k>::value,void*>::type = 0)
111 {
112 node().proxiedNode().template setChild<k>(std::forward<ProxyChild>(child));
113 }
114
115 const typename ProxiedNode::NodeStorage& nodeStorage () const
116 {
117 return node().proxiedNode().nodeStorage();
118 }
119
120 };
121
123
128 template<typename ProxiedNode>
130 : public StaticChildAccessors<ProxiedNode>
131 {
132
134
135 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
136
137 template<bool enabled = !proxiedNodeIsConst>
138 typename std::enable_if<enabled,Node&>::type
139 node ()
140 {
141 return static_cast<Node&>(*this);
142 }
143
144 const Node& node () const
145 {
146 return static_cast<const Node&>(*this);
147 }
148
149 public:
150
153
155
158 template<bool enabled = !proxiedNodeIsConst,
159 typename std::enable_if<enabled, int>::type = 0>
160 auto& child (std::size_t i)
161 {
162 return node().proxiedNode().child(i);
163 }
164
166
169 const auto& child (std::size_t i) const
170 {
171 return node().proxiedNode().child(i);
172 }
173
175
178 template<bool enabled = !proxiedNodeIsConst,
179 typename std::enable_if<enabled, int>::type = 0>
180 auto childStorage (std::size_t i)
181 {
182 return node().proxiedNode().childStorage(i);
183 }
184
186
192 auto childStorage (std::size_t i) const
193 {
194 return node().proxiedNode().childStorage(i);
195 }
196
198 template<class ProxyChild, bool enabled = !proxiedNodeIsConst>
199 void setChild (std::size_t i, ProxyChild&& child, typename std::enable_if<enabled,void*>::type = 0)
200 {
201 node().proxiedNode().setChild(i, std::forward<ProxyChild>(child));
202 }
203
204 };
205
207 template<typename Node, typename NodeTag>
209
211 template<typename Node>
213 {
214 };
215
217 template<typename Node>
219 : public StaticChildAccessors<Node>
220 {
221 typedef typename Node::ChildTypes ChildTypes;
222 typedef typename Node::NodeStorage NodeStorage;
223 };
224
226 template<typename Node>
228 : public DynamicChildAccessors<Node>
229 {
230 typedef typename Node::ChildType ChildType;
231 typedef typename Node::NodeStorage NodeStorage;
232 };
233
235 template<typename Node>
237 : public DynamicChildAccessors<Node>
238 {
239 typedef typename Node::ChildType ChildType;
240 typedef typename Node::NodeStorage NodeStorage;
241 };
242
244
250 template<typename Node>
252 : public ProxyNodeBase<Node,NodeTag<Node>>
253 {
254 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
255
256 template <class N>
257 using HasStaticDegree = index_constant<N::degree()>;
258
259 template <class N>
260 static constexpr bool hasStaticDegree = Std::is_detected<HasStaticDegree, N>::value;
261
262 // accessor mixins need to be friends for access to proxiedNode()
263 friend class StaticChildAccessors<Node>;
264 friend class DynamicChildAccessors<Node>;
265
266 public:
267
268 typedef Node ProxiedNode;
269
271
273 static const bool isLeaf = Node::isLeaf;
274
276 static const bool isPower = Node::isPower;
277
279 static const bool isComposite = Node::isComposite;
280
282 [[deprecated("Will be removed after release 2.9. Use degree()")]]
283 static const std::size_t CHILDREN = Dune::Std::detected_or_t<
286 Node
287 >::value;
288
289 template <class N = Node,
290 std::enable_if_t<hasStaticDegree<N>, int> = 0>
291 static constexpr auto degree ()
292 {
293 return N::degree();
294 }
295
296 template <class N = Node,
297 std::enable_if_t<not hasStaticDegree<N>, int> = 0>
298 auto degree () const
299 {
300 return proxiedNode().degree();
301 }
302
303
304 protected:
305
308
310 template<bool enabled = !proxiedNodeIsConst>
311 typename std::enable_if<enabled,Node&>::type
313 {
314 return *_node;
315 }
316
318 const Node& proxiedNode () const
319 {
320 return *_node;
321 }
322
324 template<bool enabled = !proxiedNodeIsConst>
325 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
327 {
328 return _node;
329 }
330
332 std::shared_ptr<const Node> proxiedNodeStorage () const
333 {
334 return _node;
335 }
336
338
341
342 ProxyNode (Node& node)
343 : _node(stackobject_to_shared_ptr(node))
344 {}
345
346 ProxyNode (std::shared_ptr<Node> node)
347 : _node(std::move(node))
348 {}
349
351
352 private:
353
354 std::shared_ptr<Node> _node;
355 };
356
358
359 } // namespace TypeTree
360} //namespace Dune
361
362#endif // DUNE_TYPETREE_PROXYNODE_HH
Mixin class providing methods for child access with run-time parameter.
Definition: proxynode.hh:131
auto & child(std::size_t i)
Returns the i-th child.
Definition: proxynode.hh:160
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
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
Base class for nodes acting as a proxy for an existing node.
Definition: proxynode.hh:253
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:312
static const std::size_t CHILDREN
The number of children.
Definition: proxynode.hh:283
std::shared_ptr< const Node > proxiedNodeStorage() const
Returns the storage of the proxied node (const version).
Definition: proxynode.hh:332
std::enable_if< enabled, std::shared_ptr< Node > >::type proxiedNodeStorage()
Returns the storage of the proxied node.
Definition: proxynode.hh:326
const Node & proxiedNode() const
Returns the proxied node (const version).
Definition: proxynode.hh:318
Mixin class providing methods for child access with compile-time parameter.
Definition: proxynode.hh:28
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
auto childStorage(index_constant< k >={})
Returns the storage of the i-th child.
Definition: proxynode.hh:90
const auto & child(index_constant< k >={}) const
Returns the i-th child (const version).
Definition: proxynode.hh:79
auto childStorage(index_constant< k >={}) const
Returns the storage of the i-th child (const version).
Definition: proxynode.hh:103
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:30
typename detected_or< Default, Op, Args... >::type detected_or_t
Returns Op<Args...> if that is valid; otherwise returns the fallback type Default.
Definition: type_traits.hh:185
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition: type_traits.hh:141
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
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
STL namespace.
This file implements several utilities related to std::shared_ptr.
Tag designating a composite node.
Definition: nodetags.hh:25
Tag designating a power node with runtime degree.
Definition: nodetags.hh:22
Tag designating a leaf node.
Definition: nodetags.hh:16
Tag designating a power node.
Definition: nodetags.hh:19
Tag-based dispatch to appropriate base class that provides necessary functionality.
Definition: proxynode.hh:208
Access to the type and storage type of the i-th child.
Definition: proxynode.hh:58
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)