4 #ifndef DUNE_TYPETREE_COMPOSITENODE_HH
5 #define DUNE_TYPETREE_COMPOSITENODE_HH
24 template<
typename... Children>
34 typedef std::tuple<std::shared_ptr<Children>... >
NodeStorage;
49 static const std::size_t
CHILDREN =
sizeof...(Children);
53 return std::integral_constant<std::size_t,
sizeof...(Children)>{};
57 template<std::
size_t k>
60 static_assert((k <
CHILDREN),
"child index out of range");
63 typedef typename std::tuple_element<k,ChildTypes>::type
Type;
66 typedef typename std::tuple_element<k,ChildTypes>::type
type;
76 template<std::
size_t k>
79 return *std::get<k>(_children);
86 template<std::
size_t k>
89 return *std::get<k>(_children);
96 template<std::
size_t k>
99 return std::get<k>(_children);
106 template<std::
size_t k>
109 return std::get<k>(_children);
113 template<std::
size_t k>
116 std::get<k>(_children) = stackobject_to_shared_ptr(
child);
120 template<std::
size_t k>
123 std::get<k>(_children) = convert_arg(std::move(
child));
127 template<std::
size_t k>
130 std::get<k>(_children) = std::move(
child);
166 template<
typename... Indices>
167 ImplementationDefined&
child (Indices... indices)
169 template<
typename I0,
typename... I,
171 decltype(
auto)
child (I0 i0, I... i)
174 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
175 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
186 template<
typename... Indices>
187 const ImplementationDefined&
child (Indices... indices)
189 template<
typename I0,
typename... I,
191 decltype(
auto)
child (I0 i0, I... i) const
194 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
195 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
219 template<
typename... Args,
typename =
typename std::enable_if<(
sizeof...(Args) ==
CHILDREN)>::type>
221 : _children(convert_arg(std::forward<Args>(args))...)
226 : _children(std::move(children)...)
231 : _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:126
Definition: accumulate_static.hh:13
Type
Definition: treepath.hh:30
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:26
CompositeNode(Args &&... args)
Initialize all children with the passed-in objects.
Definition: compositenode.hh:220
const NodeStorage & nodeStorage() const
Definition: compositenode.hh:133
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: compositenode.hh:40
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: compositenode.hh:46
static const std::size_t CHILDREN
The number of children.
Definition: compositenode.hh:49
CompositeNode()
Default constructor.
Definition: compositenode.hh:215
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition: compositenode.hh:31
void setChild(typename Child< k >::Type &child, index_constant< k >={})
Sets the k-th child to the passed-in value.
Definition: compositenode.hh:114
const Child< k >::Type & child(index_constant< k >={}) const
Returns the k-th child (const version).
Definition: compositenode.hh:87
void setChild(typename Child< k >::Type &&child, index_constant< k >={})
Store the passed value in k-th child.
Definition: compositenode.hh:121
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:107
static constexpr auto degree()
Definition: compositenode.hh:51
CompositeNode(std::shared_ptr< Children >... children)
Initialize the CompositeNode with copies of the passed in Storage objects.
Definition: compositenode.hh:225
std::tuple< Children... > ChildTypes
A tuple storing the types of all children.
Definition: compositenode.hh:37
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:128
Child< k >::Type & child(index_constant< k >={})
Returns the k-th child.
Definition: compositenode.hh:77
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: compositenode.hh:43
const ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition: compositenode.hh:187
std::shared_ptr< typename Child< k >::Type > childStorage(index_constant< k >={})
Returns the storage of the k-th child.
Definition: compositenode.hh:97
ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition: compositenode.hh:167
CompositeNode(const NodeStorage &children)
Initialize the CompositeNode with a copy of the passed-in storage type.
Definition: compositenode.hh:230
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:34
Access to the type and storage type of the i-th child.
Definition: compositenode.hh:58
std::tuple_element< k, ChildTypes >::type Type
The type of the child.
Definition: compositenode.hh:60
std::tuple_element< k, ChildTypes >::type type
The type of the child.
Definition: compositenode.hh:66
Tag designating a composite node.
Definition: nodetags.hh:25
Check if type represents a tree path.
Definition: typetraits.hh:190