DUNE PDELab (2.7)

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
13namespace Dune {
14 namespace TypeTree {
15
21 template<typename Node>
22 class ProxyNode;
23
25 template<typename ProxiedNode>
27 {
28
29 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
30
31 template<std::size_t k>
32 struct lazy_enabled
33 {
34 static const bool value = !proxiedNodeIsConst;
35 };
36
38
39 template<bool enabled = !proxiedNodeIsConst>
40 typename std::enable_if<enabled,Node&>::type
41 node()
42 {
43 return static_cast<Node&>(*this);
44 }
45
46 const Node& node() const
47 {
48 return static_cast<const Node&>(*this);
49 }
50
51 public:
52
54 template<std::size_t k>
55 struct Child
56 : public ProxiedNode::template Child<k>
57 {};
58
61
63
66 template<std::size_t k>
67 typename std::enable_if<lazy_enabled<k>::value,typename Child<k>::Type&>::type
69 {
70 return node().proxiedNode().template child<k>();
71 }
72
74
77 template<std::size_t k>
78 const typename Child<k>::Type& child(Dune::index_constant<k> = {}) const
79 {
80 return node().proxiedNode().template child<k>();
81 }
82
84
87 template<std::size_t k>
88 typename std::enable_if<lazy_enabled<k>::value,typename Child<k>::Storage>::type
90 {
91 return node().proxiedNode().template childStorage<k>();
92 }
93
95
101 template<std::size_t k>
103 {
104 return node().proxiedNode().template childStorage<k>();
105 }
106
108 template<std::size_t k>
109 void setChild(typename Child<k>::type& child, typename std::enable_if<lazy_enabled<k>::value,void*>::type = 0)
110 {
111 node().proxiedNode().template childStorage<k>() = stackobject_to_shared_ptr(child);
112 }
113
115 template<std::size_t k>
116 void setChild(typename Child<k>::storage_type child, typename std::enable_if<lazy_enabled<k>::value,void*>::type = 0)
117 {
118 node().proxiedNode().template childStorage<k>() = child;
119 }
120
121 const typename ProxiedNode::NodeStorage& nodeStorage() const
122 {
123 return node().proxiedNode().nodeStorage();
124 }
125
126 };
127
129
134 template<typename ProxiedNode>
136 : public StaticChildAccessors<ProxiedNode>
137 {
138
140
141 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<ProxiedNode>::type>::value;
142
143 template<bool enabled = !proxiedNodeIsConst>
144 typename std::enable_if<enabled,Node&>::type
145 node()
146 {
147 return static_cast<Node&>(*this);
148 }
149
150 const Node& node() const
151 {
152 return static_cast<const Node&>(*this);
153 }
154
155 public:
156
159
161
164 template<bool enabled = !proxiedNodeIsConst>
165 typename std::enable_if<enabled,typename ProxiedNode::ChildType&>::type
166 child (std::size_t i)
167 {
168 return node().proxiedNode().child(i);
169 }
170
172
175 const typename ProxiedNode::ChildType& child (std::size_t i) const
176 {
177 return node().proxiedNode().child(i);
178 }
179
181
184 template<bool enabled = !proxiedNodeIsConst>
185 typename std::enable_if<enabled,typename ProxiedNode::ChildStorageType>::type
186 childStorage(std::size_t i)
187 {
188 return node().proxiedNode().childStorage(i);
189 }
190
192
198 typename ProxiedNode::ChildConstStorageType childStorage (std::size_t i) const
199 {
200 return node().proxiedNode().childStorage(i);
201 }
202
204 template<bool enabled = !proxiedNodeIsConst>
205 void setChild (std::size_t i, typename ProxiedNode::ChildType& t, typename std::enable_if<enabled,void*>::type = 0)
206 {
207 node().proxiedNode().childStorage(i) = stackobject_to_shared_ptr(t);
208 }
209
211 template<bool enabled = !proxiedNodeIsConst>
212 void setChild (std::size_t i, typename ProxiedNode::ChildStorageType st, typename std::enable_if<enabled,void*>::type = 0)
213 {
214 node().proxiedNode().childStorage(i) = st;
215 }
216
217 };
218
220 template<typename Node, typename NodeTag>
222
224 template<typename Node>
226 {
227 };
228
230 template<typename Node>
232 : public StaticChildAccessors<Node>
233 {
234 typedef typename Node::ChildTypes ChildTypes;
235 typedef typename Node::NodeStorage NodeStorage;
236 };
237
239 template<typename Node>
241 : public DynamicChildAccessors<Node>
242 {
243 typedef typename Node::ChildType ChildType;
244 typedef typename Node::NodeStorage NodeStorage;
245 };
246
247
249
255 template<typename Node>
257 : public ProxyNodeBase<Node,NodeTag<Node>>
258 {
259
260 static const bool proxiedNodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::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 static const std::size_t CHILDREN = StaticDegree<Node>::value;
283
284 static constexpr std::size_t degree()
285 {
287 }
288
289
290 protected:
291
294
296 template<bool enabled = !proxiedNodeIsConst>
297 typename std::enable_if<enabled,Node&>::type
299 {
300 return *_node;
301 }
302
304 const Node& proxiedNode() const
305 {
306 return *_node;
307 }
308
310 template<bool enabled = !proxiedNodeIsConst>
311 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
313 {
314 return _node;
315 }
316
318 std::shared_ptr<const Node> proxiedNodeStorage() const
319 {
320 return _node;
321 }
322
324
327
328 ProxyNode(Node& node)
329 : _node(stackobject_to_shared_ptr(node))
330 {}
331
332 ProxyNode(std::shared_ptr<Node> node)
333 : _node(node)
334 {}
335
337
338 private:
339
340 std::shared_ptr<Node> _node;
341 };
342
344
345 } // namespace TypeTree
346} //namespace Dune
347
348#endif // DUNE_TYPETREE_PROXYNODE_HH
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
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
std::enable_if< enabled, typenameProxiedNode::ChildStorageType >::type childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition: proxynode.hh:186
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, typenameProxiedNode::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
Base class for nodes acting as a proxy for an existing node.
Definition: proxynode.hh:258
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
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
const Node & proxiedNode() const
Returns the proxied node (const version).
Definition: proxynode.hh:304
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
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
const Child< k >::Type & child(Dune::index_constant< k >={}) const
Returns the i-th child (const version).
Definition: proxynode.hh:78
Child< k >::ConstStorage childStorage() const
Returns the storage of the i-th child (const version).
Definition: proxynode.hh:102
std::enable_if< lazy_enabled< k >::value, typenameChild< k >::Storage >::type childStorage()
Returns the storage of the i-th child.
Definition: proxynode.hh:89
std::enable_if< lazy_enabled< k >::value, typenameChild< k >::Type & >::type child(Dune::index_constant< k >={})
Returns the i-th child.
Definition: proxynode.hh:68
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:28
std::size_t degree(const Node &node)
Returns the degree of node as run time information.
Definition: nodeinterface.hh:71
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
Dune namespace.
Definition: alignedallocator.hh:14
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Tag designating a composite node.
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:221
Access to the type and storage type of the i-th child.
Definition: proxynode.hh:57
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)