4 #ifndef DUNE_TYPETREE_POWERNODE_HH
5 #define DUNE_TYPETREE_POWERNODE_HH
10 #include <dune/common/typetraits.hh>
28 template<
typename T,
typename It,
typename... Args>
29 void assign_reference_pack_to_shared_ptr_array_unpack(It it, Args&&... args) {}
31 template<
typename T,
typename It,
typename Arg,
typename... Args>
32 void assign_reference_pack_to_shared_ptr_array_unpack(It it, Arg&& arg, Args&&... args)
34 static_assert(is_same<T,
typename remove_const<
typename remove_reference<Arg>::type>::type>::value,
"type mismatch during array conversion");
35 *it = convert_arg(std::forward<Arg>(arg));
36 assign_reference_pack_to_shared_ptr_array_unpack<T>(++it,std::forward<Args>(args)...);
39 template<
typename T, std::size_t n,
typename... Args>
40 void assign_reference_pack_to_shared_ptr_array(std::array<shared_ptr<T>,n>& res, Args&&... args)
42 static_assert(
sizeof...(Args) == n,
"invalid number of arguments");
43 return assign_reference_pack_to_shared_ptr_array_unpack<T>(res.begin(),std::forward<Args>(args)...);
48 template<
typename T,
typename It,
typename... Args>
49 void assign_shared_ptr_pack_to_shared_ptr_array_unpack(It it, Args&&... args) {}
51 template<
typename T,
typename It,
typename Arg,
typename... Args>
52 void assign_shared_ptr_pack_to_shared_ptr_array_unpack(It it, Arg&& arg, Args&&... args)
54 static_assert(is_same<T,
typename std::remove_reference<Arg>::type::element_type>::value,
"type mismatch during array conversion");
56 assign_shared_ptr_pack_to_shared_ptr_array_unpack<T>(++it,args...);
59 template<
typename T, std::size_t n,
typename... Args>
60 void assign_shared_ptr_pack_to_shared_ptr_array(std::array<shared_ptr<T>,n>& res, Args&&... args)
62 static_assert(
sizeof...(Args) == n,
"invalid number of arguments");
63 return assign_shared_ptr_pack_to_shared_ptr_array_unpack<T>(res.begin(),args...);
73 template<
typename PowerNode,
typename T, std::
size_t k>
74 struct AssertPowerNodeChildCount
75 :
public enable_if<is_same<
76 typename PowerNode::ChildType,
78 PowerNode::CHILDREN == k,
89 template<
typename T, std::
size_t k>
124 template<std::
size_t i>
128 static_assert((i < CHILDREN),
"child index out of range");
150 template<std::
size_t i>
153 static_assert((i < CHILDREN),
"child index out of range");
154 return *_children[i];
161 template<std::
size_t i>
164 static_assert((i < CHILDREN),
"child index out of range");
165 return *_children[i];
172 template<std::
size_t i>
175 static_assert((i < CHILDREN),
"child index out of range");
186 template<std::
size_t i>
189 static_assert((i < CHILDREN),
"child index out of range");
194 template<std::
size_t i>
197 static_assert((i < CHILDREN),
"child index out of range");
198 _children[i] = stackobject_to_shared_ptr(t);
202 template<std::
size_t i>
205 static_assert((i < CHILDREN),
"child index out of range");
221 assert(i < CHILDREN &&
"child index out of range");
222 return *_children[i];
229 const T&
child (std::size_t i)
const
231 assert(i < CHILDREN &&
"child index out of range");
232 return *_children[i];
241 assert(i < CHILDREN &&
"child index out of range");
254 assert(i < CHILDREN &&
"child index out of range");
255 return (_children[i]);
261 assert(i < CHILDREN &&
"child index out of range");
262 _children[i] = stackobject_to_shared_ptr(t);
268 assert(i < CHILDREN &&
"child index out of range");
298 : _children(children)
304 if (distinct_objects)
306 for (
typename NodeStorage::iterator it = _children.begin(); it != _children.end(); ++it)
307 *it = make_shared<T>(t);
311 shared_ptr<T> sp = stackobject_to_shared_ptr(t);
312 std::fill(_children.begin(),_children.end(),sp);
335 template<
typename C0,
typename C1,
typename... Children>
336 PowerNode (C0&& c0, C1&& c1, Children&&... children)
338 assign_reference_pack_to_shared_ptr_array(_children,std::forward<C0>(c0),std::forward<C1>(c1),std::forward<Children>(children)...);
342 template<
typename C0,
typename C1,
typename... Children>
343 PowerNode (shared_ptr<C0> c0, shared_ptr<C1> c1, shared_ptr<Children>... children)
345 assign_shared_ptr_pack_to_shared_ptr_array(_children,c0,c1,children...);
353 NodeStorage _children;
361 #endif // DUNE_TYPETREE_POWERNODE_HH
PowerNode(const NodeStorage &children)
Initialize the PowerNode with a copy of the passed-in storage type.
Definition: powernode.hh:297
T & child()
Returns the i-th child.
Definition: powernode.hh:151
static const std::size_t CHILDREN
The number of children.
Definition: powernode.hh:105
Access to the type and storage type of the i-th child.
Definition: powernode.hh:125
ChildStorageType childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition: powernode.hh:239
Definition: accumulate_static.hh:12
T & child(std::size_t i)
Returns the i-th child.
Definition: powernode.hh:219
const T & child(std::size_t i) const
Returns the i-th child (const version).
Definition: powernode.hh:229
const NodeStorage & nodeStorage() const
Definition: powernode.hh:272
PowerNode(T &t, bool distinct_objects=true)
Initialize all children with copies of a storage object constructed from the parameter t...
Definition: powernode.hh:302
Collect k instances of type T within a dune-typetree.
Definition: powernode.hh:90
void setChild(std::size_t i, T &t)
Sets the i-th child to the passed-in value.
Definition: powernode.hh:259
ChildConstStorageType ConstStorage
The const storage type of the child.
Definition: powernode.hh:140
void setChild(ChildStorageType st)
Sets the stored value representing the i-th child to the passed-in value.
Definition: powernode.hh:203
static const bool isComposite
Mark this class as a non composite in the dune-typetree.
Definition: powernode.hh:102
ChildStorageType Storage
The storage type of the child.
Definition: powernode.hh:137
const T & child() const
Returns the i-th child (const version).
Definition: powernode.hh:162
T ChildType
The type of each child.
Definition: powernode.hh:111
PowerNodeTag NodeTag
The type tag that describes a PowerNode.
Definition: powernode.hh:108
ChildConstStorageType childStorage(std::size_t i) const
Returns the storage of the i-th child (const version).
Definition: powernode.hh:252
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: powernode.hh:96
PowerNode(T &t1, T &t2,...)
Initialize all children with the passed-in objects.
Definition: powernode.hh:329
shared_ptr< const T > ChildConstStorageType
The const version of the storage type of each child.
Definition: powernode.hh:117
static const bool isPower
Mark this class as a power in the dune-typetree.
Definition: powernode.hh:99
ChildStorageType childStorage()
Returns the storage of the i-th child.
Definition: powernode.hh:173
std::array< ChildStorageType, k > NodeStorage
The type used for storing the children.
Definition: powernode.hh:120
T type
The type of the child.
Definition: powernode.hh:134
T Type
The type of the child.
Definition: powernode.hh:128
void setChild(T &t)
Sets the i-th child to the passed-in value.
Definition: powernode.hh:195
shared_ptr< T > ChildStorageType
The storage type of each child.
Definition: powernode.hh:114
ChildConstStorageType childStorage() const
Returns the storage of the i-th child (const version).
Definition: powernode.hh:187
PowerNode()
Default constructor.
Definition: powernode.hh:293
void setChild(std::size_t i, ChildStorageType st)
Sets the stored value representing the i-th child to the passed-in value.
Definition: powernode.hh:266
Tag designating a power node.
Definition: nodetags.hh:19