4 #ifndef DUNE_TYPETREE_COMPOSITENODE_HH 5 #define DUNE_TYPETREE_COMPOSITENODE_HH 21 template<
typename... Children>
32 typedef std::tuple<std::shared_ptr<Children>... >
NodeStorage;
47 static const std::size_t
CHILDREN =
sizeof...(Children);
49 static constexpr std::size_t
degree()
51 return sizeof...(Children);
55 template<std::
size_t k>
58 static_assert((k < CHILDREN),
"child index out of range");
61 typedef typename std::tuple_element<k,ChildTypes>::type
Type;
64 typedef typename std::tuple_element<k,ChildTypes>::type
type;
67 typedef typename std::tuple_element<k,NodeStorage>::type
Storage;
70 typedef std::shared_ptr<const typename std::tuple_element<k,ChildTypes>::type>
ConstStorage;
80 template<std::
size_t k>
83 return *std::get<k>(_children);
90 template<std::
size_t k>
93 return *std::get<k>(_children);
100 template<std::
size_t k>
103 return std::get<k>(_children);
113 template<std::
size_t k>
116 return std::get<k>(_children);
120 template<std::
size_t k>
123 std::get<k>(_children) = stackobject_to_shared_ptr(child);
127 template<std::
size_t k>
130 std::get<k>(_children) = convert_arg(std::move(child));
134 template<std::
size_t k>
137 std::get<k>(_children) = child;
173 template<
typename... Indices>
174 ImplementationDefined&
child(Indices... indices)
176 template<
typename I0,
typename... I>
177 auto child(I0 i0, I... i)
178 ->
typename std::enable_if<
180 impl::_lazy_member_child_decltype<CompositeNode>
181 >::type::template evaluate<I0,I...>
::type 184 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
185 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead." 196 template<
typename... Indices>
197 const ImplementationDefined&
child(Indices... indices)
199 template<
typename I0,
typename... I>
200 auto child(I0 i0, I... i) const
201 -> typename
std::enable_if<
203 impl::_lazy_member_child_decltype<const CompositeNode>
204 >::type::template evaluate<I0,I...>
::type 207 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
208 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead." 232 template<
typename... Args,
typename =
typename std::enable_if<(
sizeof...(Args) == CHILDREN)>
::type>
234 : _children(convert_arg(
std::forward<Args>(args))...)
239 : _children(children...)
244 : _children(children)
258 #endif // DUNE_TYPETREE_COMPOSITENODE_HH const NodeStorage & nodeStorage() const
Definition: compositenode.hh:140
std::tuple_element< k, ChildTypes >::type Type
The type of the child.
Definition: compositenode.hh:58
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
std::tuple_element< k, ChildTypes >::type type
The type of the child.
Definition: compositenode.hh:64
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition: compositenode.hh:29
Tag designating a composite node.
Definition: nodetags.hh:22
ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition: compositenode.hh:174
CompositeNode()
Default constructor.
Definition: compositenode.hh:228
Child< k >::ConstStorage childStorage(index_constant< k >={}) const
Returns the storage of the i-th child (const version).
Definition: compositenode.hh:114
Definition: accumulate_static.hh:13
typename impl::_is_flat_index< std::decay_t< T >>::type is_flat_index
Type trait that determines whether T is a flat index in the context of child extraction.
Definition: childextraction.hh:366
void setChild(typename Child< k >::Storage child, index_constant< k >={})
Sets the storage of the i-th child to the passed-in value.
Definition: compositenode.hh:135
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: compositenode.hh:44
std::tuple< Children... > ChildTypes
A tuple storing the types of all children.
Definition: compositenode.hh:35
void setChild(typename Child< k >::Type &&child, index_constant< k >={})
Store the passed value in k-th child.
Definition: compositenode.hh:128
Child< k >::Type & child(index_constant< k >={})
Returns the i-th child.
Definition: compositenode.hh:81
CompositeNode(const NodeStorage &children)
Initialize the CompositeNode with a copy of the passed-in storage type.
Definition: compositenode.hh:243
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: compositenode.hh:41
CompositeNode(Args &&... args)
Initialize all children with the passed-in objects.
Definition: compositenode.hh:233
static const std::size_t CHILDREN
The number of children.
Definition: compositenode.hh:47
void setChild(typename Child< k >::Type &child, index_constant< k >={})
Sets the i-th child to the passed-in value.
Definition: compositenode.hh:121
const ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition: compositenode.hh:197
CompositeNode(std::shared_ptr< Children >... children)
Initialize the CompositeNode with copies of the passed in Storage objects.
Definition: compositenode.hh:238
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: compositenode.hh:38
Access to the type and storage type of the i-th child.
Definition: compositenode.hh:56
const Child< k >::Type & child(index_constant< k >={}) const
Returns the i-th child (const version).
Definition: compositenode.hh:91
Child< k >::Storage childStorage(index_constant< k >={})
Returns the storage of the i-th child.
Definition: compositenode.hh:101
std::tuple_element< k, NodeStorage >::type Storage
The storage type of the child.
Definition: compositenode.hh:67
static constexpr std::size_t degree()
Definition: compositenode.hh:49
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:23
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:32
std::shared_ptr< const typename std::tuple_element< k, ChildTypes >::type > ConstStorage
The const storage type of the child.
Definition: compositenode.hh:70