4 #ifndef DUNE_TYPETREE_COMPOSITENODE_HH
5 #define DUNE_TYPETREE_COMPOSITENODE_HH
9 #include <dune/common/typetraits.hh>
10 #include <dune/common/tuples.hh>
11 #include <dune/common/static_assert.hh>
12 #include <dune/common/exceptions.hh>
30 template<
typename Children, std::
size_t i, std::
size_t n,
bool atEnd = false>
34 static const bool emptyNode = is_same<typename tuple_element<i,Children>::type,EmptyNode>
::value;
36 dune_static_assert(atEnd ?
emptyNode :
true,
"invalid child structure (EmptyNode followed by real node)");
43 template<
typename Children, std::
size_t n,
bool atEnd>
44 struct count_children<Children,n,n,atEnd>
47 static const std::size_t
value = 0;
84 dune_static_assert((
AlwaysFalse<T>::value),
"You must provide a constructor parameter for every non-empty child!");
85 DUNE_THROW(NotImplemented,
"You must provide a constructor parameter for every non-empty child!");
93 struct OptionalChild<EmptyNode>
95 typedef EmptyNode
type;
115 template<
typename C0,
typename C1 = EmptyNode,
typename C2 = EmptyNode,
typename C3 = EmptyNode,
typename C4 = EmptyNode,
116 typename C5 = EmptyNode,
typename C6 = EmptyNode,
typename C7 = EmptyNode,
typename C8 = EmptyNode,
typename C9 = EmptyNode>
123 typedef tuple<shared_ptr<C0>,
151 static const std::size_t
CHILDREN = implementation-defined;
158 template<std::
size_t k>
162 typedef typename tuple_element<k,ChildTypes>::type
Type;
165 typedef typename tuple_element<k,ChildTypes>::type
type;
168 typedef typename tuple_element<k,NodeStorage>::type
Storage;
171 typedef shared_ptr<const typename tuple_element<k,ChildTypes>::type>
ConstStorage;
182 template<std::
size_t k>
185 dune_static_assert((k <
CHILDREN),
"child index out of range");
186 return *get<k>(_children);
193 template<std::
size_t k>
196 dune_static_assert((k <
CHILDREN),
"child index out of range");
197 return *get<k>(_children);
207 template<std::
size_t k>
210 dune_static_assert((k < 10),
"child index out of range");
211 return get<k>(_children);
218 template<std::
size_t k>
221 dune_static_assert((k < 10),
"child index out of range");
222 return get<k>(_children);
226 template<std::
size_t k>
229 dune_static_assert((k <
CHILDREN),
"child index out of range");
230 get<k>(_children) = stackobject_to_shared_ptr(child);
234 template<std::
size_t k>
237 dune_static_assert((k <
CHILDREN),
"child index out of range");
238 get<k>(_children) = child;
256 static shared_ptr<T> guarded_wrap_object(T& t)
258 return stackobject_to_shared_ptr(t);
266 static shared_ptr<EmptyNode> guarded_wrap_object(EmptyNode& en)
296 : _children(stackobject_to_shared_ptr(c0),
297 guarded_wrap_object(c1),
298 guarded_wrap_object(c2),
299 guarded_wrap_object(c3),
300 guarded_wrap_object(c4),
301 guarded_wrap_object(c5),
302 guarded_wrap_object(c6),
303 guarded_wrap_object(c7),
304 guarded_wrap_object(c8),
305 guarded_wrap_object(c9))
319 : _children(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9)
324 : _children(children)
336 #endif // DUNE_TYPETREE_COMPOSITENODE_HH
T & type
The correct child type.
Definition: compositenode.hh:79
tuple< shared_ptr< C0 >, shared_ptr< C1 >, shared_ptr< C2 >, shared_ptr< C3 >, shared_ptr< C4 >, shared_ptr< C5 >, shared_ptr< C6 >, shared_ptr< C7 >, shared_ptr< C8 >, shared_ptr< C9 > > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:133
Child< k >::Storage childStorage()
Returns the storage of the i-th child.
Definition: compositenode.hh:219
void setChild(typename Child< k >::Type &child)
Sets the i-th child to the passed-in value.
Definition: compositenode.hh:227
static const bool isComposite
Mark this class as a composite in the TypeTree.
Definition: compositenode.hh:142
tuple< C0, C1, C2, C3, C4, C5, C6, C7, C8, C9 > ChildTypes
The types of all children.
Definition: compositenode.hh:136
Implementation Helper for constructors of composite nodes.
Definition: compositenode.hh:76
Base class for composite nodes combining children of different types within a TypeTree.
Definition: compositenode.hh:117
CompositeNode(const NodeStorage &children)
Initializes the CompositeNode from the passed-in NodeStorage object.
Definition: compositenode.hh:323
void setChild(typename Child< k >::Storage child)
Sets the stored value representing the i-th child to the passed-in value.
Definition: compositenode.hh:235
Child< k >::Type & child()
Returns the i-th child.
Definition: compositenode.hh:194
Access to the type and storage type of the i-th child.
Definition: compositenode.hh:159
CompositeNode(C0 &c0, typename OptionalChild< C1 >::type c1=OptionalChild< C1 >::default_value(), typename OptionalChild< C2 >::type c2=OptionalChild< C2 >::default_value(), typename OptionalChild< C3 >::type c3=OptionalChild< C3 >::default_value(), typename OptionalChild< C4 >::type c4=OptionalChild< C4 >::default_value(), typename OptionalChild< C5 >::type c5=OptionalChild< C5 >::default_value(), typename OptionalChild< C6 >::type c6=OptionalChild< C6 >::default_value(), typename OptionalChild< C7 >::type c7=OptionalChild< C7 >::default_value(), typename OptionalChild< C8 >::type c8=OptionalChild< C8 >::default_value(), typename OptionalChild< C9 >::type c9=OptionalChild< C9 >::default_value())
Initializes the CompositeNode with the passed-in child objects.
Definition: compositenode.hh:286
static const std::size_t CHILDREN
The number of children of the CompositeNode.
Definition: compositenode.hh:152
tuple_element< k, NodeStorage >::type Storage
The storage type of the child.
Definition: compositenode.hh:168
const shared_ptr< EmptyNode > & emptyNodePtr()
Reference to a pointer to an empty node that is used for all empty slots.
Definition: utility.cc:12
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition: compositenode.hh:148
static T default_value()
Method providing a default value for empty children.
Definition: compositenode.hh:82
static const bool isLeaf
Mark this class as non leaf in the TypeTree.
Definition: compositenode.hh:139
tuple_element< k, ChildTypes >::type Type
The type of the child.
Definition: compositenode.hh:162
shared_ptr< const typename tuple_element< k, ChildTypes >::type > ConstStorage
The const storage type of the child.
Definition: compositenode.hh:171
CompositeNode(shared_ptr< C0 > c0, shared_ptr< C1 > c1, shared_ptr< C2 > c2, shared_ptr< C3 > c3, shared_ptr< C4 > c4, shared_ptr< C5 > c5, shared_ptr< C6 > c6, shared_ptr< C7 > c7, shared_ptr< C8 > c8, shared_ptr< C9 > c9)
Initializes the CompositeNode with copies of the passed-in storage objects.
Definition: compositenode.hh:309
static const bool isPower
Mark this class as a non power in the typeTree.
Definition: compositenode.hh:145
static const std::size_t value
Definition: compositenode.hh:38
const NodeStorage & nodeStorage() const
Definition: compositenode.hh:241
tuple_element< k, ChildTypes >::type type
The type of the child.
Definition: compositenode.hh:165
const Child< k >::Type & child() const
Returns the i-th child (const version).
Definition: compositenode.hh:183
Tag designating a composite node.
Definition: nodetags.hh:22
static const bool emptyNode
Definition: compositenode.hh:34
Child< k >::ConstStorage childStorage() const
Returns the storage of the i-th child (const version).
Definition: compositenode.hh:208
CompositeNode()
Default constructor.
Definition: compositenode.hh:282