6#ifndef DUNE_TYPETREE_POWERNODE_HH
7#define DUNE_TYPETREE_POWERNODE_HH
14#include <dune/common/typetraits.hh>
15#include <dune/common/std/type_traits.hh>
34 template<
typename PowerNode,
typename T, std::
size_t k>
35 struct AssertPowerNodeChildCount
36 :
public std::enable_if<std::is_same<
37 typename PowerNode::ChildType,
39 PowerNode::degree() == k,
50 template<
typename T, std::
size_t k>
67 return std::integral_constant<std::size_t,k>{};
81 template<std::
size_t i>
85 static_assert((i <
degree()),
"child index out of range");
101 template<std::
size_t i>
104 static_assert((i <
degree()),
"child index out of range");
105 return *_children[i];
112 template<std::
size_t i>
113 const T&
child (index_constant<i> = {})
const
115 static_assert((i <
degree()),
"child index out of range");
116 return *_children[i];
123 template<std::
size_t i>
126 static_assert((i <
degree()),
"child index out of range");
134 template<std::
size_t i>
137 static_assert((i <
degree()),
"child index out of range");
142 template<std::
size_t i>
145 static_assert((i <
degree()),
"child index out of range");
146 _children[i] = stackobject_to_shared_ptr(t);
150 template<std::
size_t i>
153 static_assert((i <
degree()),
"child index out of range");
154 _children[i] = convert_arg(std::move(t));
158 template<std::
size_t i>
159 void setChild (std::shared_ptr<T> st, index_constant<i> = {})
161 static_assert((i <
degree()),
"child index out of range");
162 _children[i] = std::move(st);
177 assert(i <
degree() &&
"child index out of range");
178 return *_children[i];
185 const T&
child (std::size_t i)
const
187 assert(i <
degree() &&
"child index out of range");
188 return *_children[i];
197 assert(i <
degree() &&
"child index out of range");
207 assert(i <
degree() &&
"child index out of range");
214 assert(i <
degree() &&
"child index out of range");
215 _children[i] = stackobject_to_shared_ptr(t);
221 assert(i <
degree() &&
"child index out of range");
222 _children[i] = convert_arg(std::move(t));
226 void setChild (std::size_t i, std::shared_ptr<T> st)
228 assert(i <
degree() &&
"child index out of range");
229 _children[i] = std::move(st);
265 template<
typename... Indices>
266 ImplementationDefined&
child (Indices... indices)
268 template<
typename I0,
typename... I,
270 decltype(
auto)
child (I0 i0, I... i)
273 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
274 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
285 template<
typename... Indices>
286 const ImplementationDefined&
child (Indices... indices)
288 template<
typename I0,
typename... I,
290 decltype(
auto)
child (I0 i0, I... i)
const
293 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
294 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
320 : _children(children)
326 if (distinct_objects)
328 for (
typename NodeStorage::iterator it = _children.begin(); it != _children.end(); ++it)
329 *it = std::make_shared<T>(t);
333 std::shared_ptr<T> sp = stackobject_to_shared_ptr(t);
334 std::fill(_children.begin(),_children.end(),sp);
346 template<
typename... Children,
348 std::conjunction<std::is_same<ChildType, std::decay_t<Children>>...>::value
352 static_assert(
degree() ==
sizeof...(Children),
"PowerNode constructor is called with incorrect number of children");
353 _children =
NodeStorage{convert_arg(std::forward<Children>(children))...};
356 template<
typename... Children,
358 std::conjunction<std::is_same<ChildType, Children>...>::value
360 PowerNode (std::shared_ptr<Children>... children)
362 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:128
Definition accumulate_static.hh:16
Tag designating a power node.
Definition nodetags.hh:21
Collect k instances of type T within a dune-typetree.
Definition powernode.hh:52
void setChild(T &t, index_constant< i >={})
Sets the i-th child to the passed-in value.
Definition powernode.hh:143
T & child(std::size_t i)
Returns the i-th child.
Definition powernode.hh:175
const T & child(index_constant< i >={}) const
Returns the i-th child (const version).
Definition powernode.hh:113
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:159
std::shared_ptr< T > childStorage(index_constant< i >={})
Returns the storage of the i-th child.
Definition powernode.hh:124
PowerNode(T &t1, T &t2,...)
Initialize all children with the passed-in objects.
Definition powernode.hh:341
const NodeStorage & nodeStorage() const
Definition powernode.hh:232
std::array< std::shared_ptr< T >, k > NodeStorage
The type used for storing the children.
Definition powernode.hh:77
std::shared_ptr< const T > childStorage(index_constant< i >={}) const
Returns the storage of the i-th child (const version).
Definition powernode.hh:135
PowerNode(T &t, bool distinct_objects=true)
Initialize all children with copies of a storage object constructed from the parameter t.
Definition powernode.hh:324
PowerNodeTag NodeTag
The type tag that describes a PowerNode.
Definition powernode.hh:71
const T & child(std::size_t i) const
Returns the i-th child (const version).
Definition powernode.hh:185
static constexpr auto degree()
Definition powernode.hh:65
std::shared_ptr< const T > childStorage(std::size_t i) const
Returns the storage of the i-th child (const version).
Definition powernode.hh:205
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:226
static const bool isComposite
Mark this class as a non composite in the dune-typetree.
Definition powernode.hh:63
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition powernode.hh:57
static const bool isPower
Mark this class as a power in the dune-typetree.
Definition powernode.hh:60
PowerNode(const NodeStorage &children)
Initialize the PowerNode with a copy of the passed-in storage type.
Definition powernode.hh:319
T ChildType
The type of each child.
Definition powernode.hh:74
T & child(index_constant< i >={})
Returns the i-th child.
Definition powernode.hh:102
ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition powernode.hh:266
void setChild(std::size_t i, T &&t)
Store the passed value in i-th child.
Definition powernode.hh:219
void setChild(T &&t, index_constant< i >={})
Store the passed value in i-th child.
Definition powernode.hh:151
PowerNode()
Default constructor.
Definition powernode.hh:315
const ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition powernode.hh:286
void setChild(std::size_t i, T &t)
Sets the i-th child to the passed-in value.
Definition powernode.hh:212
std::shared_ptr< T > childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition powernode.hh:195
Access to the type and storage type of the i-th child.
Definition powernode.hh:83
T type
The type of the child.
Definition powernode.hh:91
T Type
The type of the child.
Definition powernode.hh:88
Check if type represents a tree path.
Definition typetraits.hh:184