4 #ifndef DUNE_TYPETREE_COMPOSITENODE_HH
5 #define DUNE_TYPETREE_COMPOSITENODE_HH
23 template<
typename... Children>
33 typedef std::tuple<std::shared_ptr<Children>... >
NodeStorage;
48 static const std::size_t
CHILDREN =
sizeof...(Children);
50 static constexpr std::size_t
degree()
52 return sizeof...(Children);
56 template<std::
size_t k>
59 static_assert((k <
CHILDREN),
"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;
68 typedef typename std::tuple_element<k,NodeStorage>::type
Storage;
71 typedef std::shared_ptr<const typename std::tuple_element<k,ChildTypes>::type>
ConstStorage;
81 template<std::
size_t k>
84 return *std::get<k>(_children);
91 template<std::
size_t k>
94 return *std::get<k>(_children);
101 template<std::
size_t k>
104 return std::get<k>(_children);
114 template<std::
size_t k>
117 return std::get<k>(_children);
121 template<std::
size_t k>
124 std::get<k>(_children) = stackobject_to_shared_ptr(
child);
128 template<std::
size_t k>
131 std::get<k>(_children) = convert_arg(std::move(
child));
135 template<std::
size_t k>
138 std::get<k>(_children) =
child;
174 template<
typename... Indices>
175 ImplementationDefined&
child(Indices... indices)
177 template<
typename I0,
typename... I,
179 decltype(
auto)
child(I0 i0, I... i)
182 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
183 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
194 template<
typename... Indices>
195 const ImplementationDefined&
child(Indices... indices)
197 template<
typename I0,
typename... I,
199 decltype(
auto)
child(I0 i0, I... i) const
202 static_assert(
sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
203 "You cannot use the member function child() with an empty TreePath, use the freestanding version child(node,treePath) instead."
227 template<
typename... Args,
typename =
typename std::enable_if<(
sizeof...(Args) ==
CHILDREN)>::type>
229 : _children(convert_arg(std::forward<Args>(args))...)
234 : _children(children...)
239 : _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:179
Definition: accumulate_static.hh:13
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:25
CompositeNode(Args &&... args)
Initialize all children with the passed-in objects.
Definition: compositenode.hh:228
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:136
const NodeStorage & nodeStorage() const
Definition: compositenode.hh:141
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: compositenode.hh:39
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: compositenode.hh:45
static const std::size_t CHILDREN
The number of children.
Definition: compositenode.hh:48
Child< k >::ConstStorage childStorage(index_constant< k >={}) const
Returns the storage of the i-th child (const version).
Definition: compositenode.hh:115
CompositeNode()
Default constructor.
Definition: compositenode.hh:223
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition: compositenode.hh:30
void setChild(typename Child< k >::Type &child, index_constant< k >={})
Sets the i-th child to the passed-in value.
Definition: compositenode.hh:122
const Child< k >::Type & child(index_constant< k >={}) const
Returns the i-th child (const version).
Definition: compositenode.hh:92
void setChild(typename Child< k >::Type &&child, index_constant< k >={})
Store the passed value in k-th child.
Definition: compositenode.hh:129
static constexpr std::size_t degree()
Definition: compositenode.hh:50
CompositeNode(std::shared_ptr< Children >... children)
Initialize the CompositeNode with copies of the passed in Storage objects.
Definition: compositenode.hh:233
std::tuple< Children... > ChildTypes
A tuple storing the types of all children.
Definition: compositenode.hh:36
Child< k >::Type & child(index_constant< k >={})
Returns the i-th child.
Definition: compositenode.hh:82
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: compositenode.hh:42
const ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition: compositenode.hh:195
Child< k >::Storage childStorage(index_constant< k >={})
Returns the storage of the i-th child.
Definition: compositenode.hh:102
ImplementationDefined & child(Indices... indices)
Returns the child given by the list of indices.
Definition: compositenode.hh:175
CompositeNode(const NodeStorage &children)
Initialize the CompositeNode with a copy of the passed-in storage type.
Definition: compositenode.hh:238
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:33
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:59
std::tuple_element< k, NodeStorage >::type Storage
The storage type of the child.
Definition: compositenode.hh:68
std::tuple_element< k, ChildTypes >::type type
The type of the child.
Definition: compositenode.hh:65
std::shared_ptr< const typename std::tuple_element< k, ChildTypes >::type > ConstStorage
The const storage type of the child.
Definition: compositenode.hh:71
Tag designating a composite node.
Definition: nodetags.hh:22
Check if type represents a tree path.
Definition: typetraits.hh:190