Go to the documentation of this file.
4 #ifndef DUNE_TYPETREE_POWERNODE_HH
5 #define DUNE_TYPETREE_POWERNODE_HH
10 #include <type_traits>
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::CHILDREN == k,
48 template<
typename T, std::
size_t k>
66 static constexpr std::size_t
degree()
88 template<std::
size_t i>
92 static_assert((i <
CHILDREN),
"child index out of range");
114 template<std::
size_t i>
117 static_assert((i <
CHILDREN),
"child index out of range");
118 return *_children[i];
125 template<std::
size_t i>
126 const T&
child (index_constant<i> = {})
const
128 static_assert((i <
CHILDREN),
"child index out of range");
129 return *_children[i];
136 template<std::
size_t i>
139 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");
158 template<std::
size_t i>
161 static_assert((i <
CHILDREN),
"child index out of range");
162 _children[i] = stackobject_to_shared_ptr(t);
166 template<std::
size_t i>
169 static_assert((i <
CHILDREN),
"child index out of range");
170 _children[i] = convert_arg(std::move(t));
174 template<std::
size_t i>
177 static_assert((i <
CHILDREN),
"child index out of range");
193 assert(i <
CHILDREN &&
"child index out of range");
194 return *_children[i];
201 const T&
child (std::size_t i)
const
203 assert(i <
CHILDREN &&
"child index out of range");
204 return *_children[i];
213 assert(i <
CHILDREN &&
"child index out of range");
226 assert(i <
CHILDREN &&
"child index out of range");
227 return (_children[i]);
233 assert(i <
CHILDREN &&
"child index out of range");
234 _children[i] = stackobject_to_shared_ptr(t);
240 assert(i <
CHILDREN &&
"child index out of range");
241 _children[i] = convert_arg(std::move(t));
247 assert(i <
CHILDREN &&
"child index out of range");
284 template<
typename... Indices>
285 ImplementationDefined&
child(Indices... indices)
287 template<
typename I0,
typename... I,
289 decltype(
auto)
child(I0 i0, I... i)
292 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
293 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
304 template<
typename... Indices>
305 const ImplementationDefined&
child(Indices... indices)
307 template<
typename I0,
typename... I,
309 decltype(
auto)
child(I0 i0, I... i) const
312 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
313 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
339 : _children(children)
345 if (distinct_objects)
347 for (
typename NodeStorage::iterator it = _children.begin(); it != _children.end(); ++it)
348 *it = std::make_shared<T>(t);
352 std::shared_ptr<T> sp = stackobject_to_shared_ptr(t);
353 std::fill(_children.begin(),_children.end(),sp);
365 template<
typename... Children,
367 Dune::Std::conjunction<std::is_same<ChildType, std::decay_t<Children>>...>::value
371 static_assert(
CHILDREN ==
sizeof...(Children),
"PowerNode constructor is called with incorrect number of children");
372 _children =
NodeStorage{convert_arg(std::forward<Children>(children))...};
375 template<
typename... Children,
377 Dune::Std::conjunction<std::is_same<ChildType, Children>...>::value
379 PowerNode (std::shared_ptr<Children>... children)
381 static_assert(
CHILDREN ==
sizeof...(Children),
"PowerNode constructor is called with incorrect number of children");
398 #endif // DUNE_TYPETREE_POWERNODE_HH
ChildConstStorageType childStorage(index_constant< i >={}) const
Returns the storage of the i-th child (const version).
Definition: powernode.hh:151
Access to the type and storage type of the i-th child.
Definition: powernode.hh:89
void setChild(ChildStorageType st, index_constant< i >={})
Sets the stored value representing the i-th child to the passed-in value.
Definition: powernode.hh:175
Tag designating a power node.
Definition: nodetags.hh:19
PowerNode()
Default constructor.
Definition: powernode.hh:334
void setChild(T &t, index_constant< i >={})
Sets the i-th child to the passed-in value.
Definition: powernode.hh:159
Collect k instances of type T within a dune-typetree.
Definition: powernode.hh:49
PowerNode(T &t, bool distinct_objects=true)
Initialize all children with copies of a storage object constructed from the parameter t.
Definition: powernode.hh:343
PowerNode(const NodeStorage &children)
Initialize the PowerNode with a copy of the passed-in storage type.
Definition: powernode.hh:338
T Type
The type of the child.
Definition: powernode.hh:92
T & child(index_constant< i >={})
Returns the i-th child.
Definition: powernode.hh:115
std::array< ChildStorageType, k > NodeStorage
The type used for storing the children.
Definition: powernode.hh:84
ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition: powernode.hh:285
PowerNodeTag NodeTag
The type tag that describes a PowerNode.
Definition: powernode.hh:72
T ChildType
The type of each child.
Definition: powernode.hh:75
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: powernode.hh:55
PowerNode(T &t1, T &t2,...)
Initialize all children with the passed-in objects.
Definition: powernode.hh:360
const T & child(index_constant< i >={}) const
Returns the i-th child (const version).
Definition: powernode.hh:126
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:245
static const bool isPower
Mark this class as a power in the dune-typetree.
Definition: powernode.hh:58
const ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition: powernode.hh:305
static const bool isComposite
Mark this class as a non composite in the dune-typetree.
Definition: powernode.hh:61
void setChild(std::size_t i, T &&t)
Store the passed value in i-th child.
Definition: powernode.hh:238
const NodeStorage & nodeStorage() const
Definition: powernode.hh:251
ChildStorageType childStorage(index_constant< i >={})
Returns the storage of the i-th child.
Definition: powernode.hh:137
ChildStorageType Storage
The storage type of the child.
Definition: powernode.hh:101
std::shared_ptr< const T > ChildConstStorageType
The const version of the storage type of each child.
Definition: powernode.hh:81
static constexpr std::size_t degree()
Definition: powernode.hh:66
const T & child(std::size_t i) const
Returns the i-th child (const version).
Definition: powernode.hh:201
void setChild(std::size_t i, T &t)
Sets the i-th child to the passed-in value.
Definition: powernode.hh:231
void setChild(T &&t, index_constant< i >={})
Store the passed value in i-th child.
Definition: powernode.hh:167
ChildConstStorageType childStorage(std::size_t i) const
Returns the storage of the i-th child (const version).
Definition: powernode.hh:224
Definition: accumulate_static.hh:13
ChildStorageType childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition: powernode.hh:211
ChildConstStorageType ConstStorage
The const storage type of the child.
Definition: powernode.hh:104
T & child(std::size_t i)
Returns the i-th child.
Definition: powernode.hh:191
static const std::size_t CHILDREN
The number of children.
Definition: powernode.hh:64
T type
The type of the child.
Definition: powernode.hh:98
std::shared_ptr< T > ChildStorageType
The storage type of each child.
Definition: powernode.hh:78
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:179
Check if type represents a tree path.
Definition: typetraits.hh:188