6#ifndef DUNE_TYPETREE_COMPOSITENODE_HH
7#define DUNE_TYPETREE_COMPOSITENODE_HH
26 template<
typename... Children>
36 typedef std::tuple<std::shared_ptr<Children>... >
NodeStorage;
52 return std::integral_constant<std::size_t,
sizeof...(Children)>{};
56 template<std::
size_t k>
59 static_assert((k <
degree()),
"child index out of range");
62 typedef typename std::tuple_element<k,ChildTypes>::type
Type;
65 typedef typename std::tuple_element<k,ChildTypes>::type
type;
75 template<std::
size_t k>
78 return *std::get<k>(_children);
85 template<std::
size_t k>
88 return *std::get<k>(_children);
95 template<std::
size_t k>
96 std::shared_ptr<typename Child<k>::Type>
childStorage (index_constant<k> = {})
98 return std::get<k>(_children);
105 template<std::
size_t k>
106 std::shared_ptr<const typename Child<k>::Type>
childStorage (index_constant<k> = {})
const
108 return std::get<k>(_children);
112 template<std::
size_t k>
115 std::get<k>(_children) = stackobject_to_shared_ptr(
child);
119 template<std::
size_t k>
122 std::get<k>(_children) = convert_arg(std::move(
child));
126 template<std::
size_t k>
129 std::get<k>(_children) = std::move(
child);
165 template<
typename... Indices>
166 ImplementationDefined&
child (Indices... indices)
168 template<
typename I0,
typename... I,
170 decltype(
auto)
child (I0 i0, I... i)
173 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
174 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
185 template<
typename... Indices>
186 const ImplementationDefined&
child (Indices... indices)
188 template<
typename I0,
typename... I,
190 decltype(
auto)
child (I0 i0, I... i)
const
193 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
194 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
218 template<
typename... Args,
typename =
typename std::enable_if<(
sizeof...(Args) ==
degree())>::type>
220 : _children(convert_arg(std::forward<Args>(args))...)
225 : _children(std::move(children)...)
230 : _children(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
Base class for composite nodes based on variadic templates.
Definition compositenode.hh:28
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition compositenode.hh:42
ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition compositenode.hh:166
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition compositenode.hh:48
CompositeNode()
Default constructor.
Definition compositenode.hh:214
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition compositenode.hh:33
void setChild(typename Child< k >::Type &child, index_constant< k >={})
Sets the k-th child to the passed-in value.
Definition compositenode.hh:113
void setChild(typename Child< k >::Type &&child, index_constant< k >={})
Store the passed value in k-th child.
Definition compositenode.hh:120
static constexpr auto degree()
Definition compositenode.hh:50
const NodeStorage & nodeStorage() const
Definition compositenode.hh:132
CompositeNode(std::shared_ptr< Children >... children)
Initialize the CompositeNode with copies of the passed in Storage objects.
Definition compositenode.hh:224
std::shared_ptr< typename Child< k >::Type > childStorage(index_constant< k >={})
Returns the storage of the k-th child.
Definition compositenode.hh:96
std::tuple< Children... > ChildTypes
A tuple storing the types of all children.
Definition compositenode.hh:39
void setChild(std::shared_ptr< typename Child< k >::Type > child, index_constant< k >={})
Sets the storage of the k-th child to the passed-in value.
Definition compositenode.hh:127
const ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition compositenode.hh:186
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition compositenode.hh:45
std::shared_ptr< const typename Child< k >::Type > childStorage(index_constant< k >={}) const
Returns the storage of the k-th child (const version).
Definition compositenode.hh:106
Child< k >::Type & child(index_constant< k >={})
Returns the k-th child.
Definition compositenode.hh:76
CompositeNode(const NodeStorage &children)
Initialize the CompositeNode with a copy of the passed-in storage type.
Definition compositenode.hh:229
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition compositenode.hh:36
const Child< k >::Type & child(index_constant< k >={}) const
Returns the k-th child (const version).
Definition compositenode.hh:86
Access to the type and storage type of the i-th child.
Definition compositenode.hh:57
std::tuple_element< k, ChildTypes >::type Type
The type of the child.
Definition compositenode.hh:62
std::tuple_element< k, ChildTypes >::type type
The type of the child.
Definition compositenode.hh:65
Tag designating a composite node.
Definition nodetags.hh:27
Check if type represents a tree path.
Definition typetraits.hh:184