4#ifndef DUNE_TYPETREE_POWERNODE_HH
5#define DUNE_TYPETREE_POWERNODE_HH
12#include <dune/common/typetraits.hh>
13#include <dune/common/std/type_traits.hh>
32 template<
typename PowerNode,
typename T, std::
size_t k>
33 struct AssertPowerNodeChildCount
34 :
public std::enable_if<std::is_same<
35 typename PowerNode::ChildType,
37 PowerNode::degree() == k,
48 template<
typename T, std::
size_t k>
64 [[deprecated(
"Will be removed after release 2.9. Use degree()")]]
69 return std::integral_constant<std::size_t,k>{};
83 template<std::
size_t i>
87 static_assert((i <
degree()),
"child index out of range");
103 template<std::
size_t i>
106 static_assert((i <
degree()),
"child index out of range");
107 return *_children[i];
114 template<std::
size_t i>
115 const T&
child (index_constant<i> = {})
const
117 static_assert((i <
degree()),
"child index out of range");
118 return *_children[i];
125 template<std::
size_t i>
128 static_assert((i <
degree()),
"child index out of range");
136 template<std::
size_t i>
139 static_assert((i <
degree()),
"child index out of range");
144 template<std::
size_t i>
147 static_assert((i <
degree()),
"child index out of range");
148 _children[i] = stackobject_to_shared_ptr(t);
152 template<std::
size_t i>
155 static_assert((i <
degree()),
"child index out of range");
156 _children[i] = convert_arg(std::move(t));
160 template<std::
size_t i>
161 void setChild (std::shared_ptr<T> st, index_constant<i> = {})
163 static_assert((i <
degree()),
"child index out of range");
164 _children[i] = std::move(st);
179 assert(i <
degree() &&
"child index out of range");
180 return *_children[i];
187 const T&
child (std::size_t i)
const
189 assert(i <
degree() &&
"child index out of range");
190 return *_children[i];
199 assert(i <
degree() &&
"child index out of range");
209 assert(i <
degree() &&
"child index out of range");
216 assert(i <
degree() &&
"child index out of range");
217 _children[i] = stackobject_to_shared_ptr(t);
223 assert(i <
degree() &&
"child index out of range");
224 _children[i] = convert_arg(std::move(t));
228 void setChild (std::size_t i, std::shared_ptr<T> st)
230 assert(i <
degree() &&
"child index out of range");
231 _children[i] = std::move(st);
267 template<
typename... Indices>
268 ImplementationDefined&
child (Indices... indices)
270 template<
typename I0,
typename... I,
272 decltype(
auto)
child (I0 i0, I... i)
275 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
276 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
287 template<
typename... Indices>
288 const ImplementationDefined&
child (Indices... indices)
290 template<
typename I0,
typename... I,
292 decltype(
auto)
child (I0 i0, I... i)
const
295 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
296 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
322 : _children(children)
328 if (distinct_objects)
330 for (
typename NodeStorage::iterator it = _children.begin(); it != _children.end(); ++it)
331 *it = std::make_shared<T>(t);
335 std::shared_ptr<T> sp = stackobject_to_shared_ptr(t);
336 std::fill(_children.begin(),_children.end(),sp);
348 template<
typename... Children,
350 std::conjunction<std::is_same<ChildType, std::decay_t<Children>>...>::value
354 static_assert(
degree() ==
sizeof...(Children),
"PowerNode constructor is called with incorrect number of children");
355 _children =
NodeStorage{convert_arg(std::forward<Children>(children))...};
358 template<
typename... Children,
360 std::conjunction<std::is_same<ChildType, Children>...>::value
362 PowerNode (std::shared_ptr<Children>... children)
364 static_assert(
degree() ==
sizeof...(Children),
"PowerNode constructor is called with incorrect number of children");
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition childextraction.hh:126
Definition accumulate_static.hh:13
Tag designating a power node.
Definition nodetags.hh:19
Collect k instances of type T within a dune-typetree.
Definition powernode.hh:50
void setChild(T &t, index_constant< i >={})
Sets the i-th child to the passed-in value.
Definition powernode.hh:145
T & child(std::size_t i)
Returns the i-th child.
Definition powernode.hh:177
const T & child(index_constant< i >={}) const
Returns the i-th child (const version).
Definition powernode.hh:115
void setChild(std::shared_ptr< T > st, index_constant< i >={})
Sets the stored value representing the i-th child to the passed-in value.
Definition powernode.hh:161
std::shared_ptr< T > childStorage(index_constant< i >={})
Returns the storage of the i-th child.
Definition powernode.hh:126
PowerNode(T &t1, T &t2,...)
Initialize all children with the passed-in objects.
Definition powernode.hh:343
const NodeStorage & nodeStorage() const
Definition powernode.hh:234
std::array< std::shared_ptr< T >, k > NodeStorage
The type used for storing the children.
Definition powernode.hh:79
std::shared_ptr< const T > childStorage(index_constant< i >={}) const
Returns the storage of the i-th child (const version).
Definition powernode.hh:137
PowerNode(T &t, bool distinct_objects=true)
Initialize all children with copies of a storage object constructed from the parameter t.
Definition powernode.hh:326
PowerNodeTag NodeTag
The type tag that describes a PowerNode.
Definition powernode.hh:73
const T & child(std::size_t i) const
Returns the i-th child (const version).
Definition powernode.hh:187
static constexpr auto degree()
Definition powernode.hh:67
std::shared_ptr< const T > childStorage(std::size_t i) const
Returns the storage of the i-th child (const version).
Definition powernode.hh:207
static const std::size_t CHILDREN
The number of children.
Definition powernode.hh:65
void setChild(std::size_t i, std::shared_ptr< T > st)
Sets the stored value representing the i-th child to the passed-in value.
Definition powernode.hh:228
static const bool isComposite
Mark this class as a non composite in the dune-typetree.
Definition powernode.hh:61
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition powernode.hh:55
static const bool isPower
Mark this class as a power in the dune-typetree.
Definition powernode.hh:58
PowerNode(const NodeStorage &children)
Initialize the PowerNode with a copy of the passed-in storage type.
Definition powernode.hh:321
T ChildType
The type of each child.
Definition powernode.hh:76
T & child(index_constant< i >={})
Returns the i-th child.
Definition powernode.hh:104
ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition powernode.hh:268
void setChild(std::size_t i, T &&t)
Store the passed value in i-th child.
Definition powernode.hh:221
void setChild(T &&t, index_constant< i >={})
Store the passed value in i-th child.
Definition powernode.hh:153
PowerNode()
Default constructor.
Definition powernode.hh:317
const ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition powernode.hh:288
void setChild(std::size_t i, T &t)
Sets the i-th child to the passed-in value.
Definition powernode.hh:214
std::shared_ptr< T > childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition powernode.hh:197
Access to the type and storage type of the i-th child.
Definition powernode.hh:85
T type
The type of the child.
Definition powernode.hh:93
T Type
The type of the child.
Definition powernode.hh:90
Check if type represents a tree path.
Definition typetraits.hh:182