dune-typetree  2.3.1
variadiccompositenode.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_TYPETREE_VARIADICCOMPOSITENODE_HH
5 #define DUNE_TYPETREE_VARIADICCOMPOSITENODE_HH
6 
7 #if !(HAVE_VARIADIC_TEMPLATES || DOXYGEN || HEADERCHECK)
8 #error The class VariadicCompositeNode requires compiler support for variadic templates, which your compiler lacks.
9 #endif
10 
11 #if (HAVE_VARIADIC_TEMPLATES || DOXYGEN)
13 #include <dune/common/tuples.hh>
14 #include <dune/common/shared_ptr.hh>
15 #include <dune/common/static_assert.hh>
16 
17 namespace Dune {
18  namespace TypeTree {
19 
25  template<typename... Children>
28  {
29 
30  public:
31 
34 
36  typedef tuple<shared_ptr<Children>... > NodeStorage;
37 
39  typedef tuple<Children...> ChildTypes;
40 
42  static const bool isLeaf = false;
43 
45  static const bool isPower = false;
46 
48  static const bool isComposite = true;
49 
51  static const std::size_t CHILDREN = sizeof...(Children);
52 
54  template<std::size_t k>
55  struct Child {
56 
57  dune_static_assert((k < CHILDREN), "child index out of range");
58 
60  typedef typename tuple_element<k,ChildTypes>::type Type;
61 
63  typedef typename tuple_element<k,ChildTypes>::type type;
64 
66  typedef typename tuple_element<k,NodeStorage>::type Storage;
67 
69  typedef shared_ptr<const typename tuple_element<k,ChildTypes>::type> ConstStorage;
70  };
71 
74 
76 
79  template<std::size_t k>
80  typename Child<k>::Type& child()
81  {
82  return *get<k>(_children);
83  }
84 
86 
89  template<std::size_t k>
90  const typename Child<k>::Type& child() const
91  {
92  return *get<k>(_children);
93  }
94 
96 
99  template<std::size_t k>
101  {
102  return get<k>(_children);
103  }
104 
106 
112  template<std::size_t k>
114  {
115  return get<k>(_children);
116  }
117 
119  template<std::size_t k>
120  void setChild(typename Child<k>::Type& child)
121  {
122  get<k>(_children) = stackobject_to_shared_ptr(child);
123  }
124 
126  template<std::size_t k>
128  {
129  get<k>(_children) = child;
130  }
131 
132  const NodeStorage& nodeStorage() const
133  {
134  return _children;
135  }
136 
138 
139  protected:
140 
143 
145 
153  {}
154 
155 #if HAVE_RVALUE_REFERENCES && HAVE_VARIADIC_CONSTRUCTOR_SFINAE
156  template<typename... Args, typename = typename enable_if<(sizeof...(Args) == CHILDREN)>::type>
158  VariadicCompositeNode(Args&&... args)
159  : _children(convert_arg(std::forward<Args>(args))...)
160  {}
161 
162 #else
163 
164  VariadicCompositeNode(Children&... children)
165  : _children(convert_arg(children)...)
166  {}
167 
168 #endif
169 
171  VariadicCompositeNode(shared_ptr<Children>... children)
172  : _children(children...)
173  {}
174 
177  : _children(children)
178  {}
179 
181 
182  private:
183  NodeStorage _children;
184  };
185 
187 
188  } // namespace TypeTree
189 } //namespace Dune
190 
191 #endif // (HAVE_VARIADIC_TEMPLATES || DOXYGEN)
192 
193 #endif // DUNE_TYPETREE_VARIADICCOMPOSITENODE_HH
tuple_element< k, ChildTypes >::type type
The type of the child.
Definition: variadiccompositenode.hh:63
const NodeStorage & nodeStorage() const
Definition: variadiccompositenode.hh:132
VariadicCompositeNodeTag NodeTag
The type tag that describes a VariadicCompositeNode.
Definition: variadiccompositenode.hh:33
static const std::size_t CHILDREN
The number of children.
Definition: variadiccompositenode.hh:51
shared_ptr< const typename tuple_element< k, ChildTypes >::type > ConstStorage
The const storage type of the child.
Definition: variadiccompositenode.hh:69
void setChild(typename Child< k >::Type &child)
Sets the i-th child to the passed-in value.
Definition: variadiccompositenode.hh:120
Child< k >::Storage childStorage()
Returns the storage of the i-th child.
Definition: variadiccompositenode.hh:100
tuple< shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: variadiccompositenode.hh:36
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: variadiccompositenode.hh:45
void setChild(typename Child< k >::Storage child)
Sets the storage of the i-th child to the passed-in value.
Definition: variadiccompositenode.hh:127
Child< k >::ConstStorage childStorage() const
Returns the storage of the i-th child (const version).
Definition: variadiccompositenode.hh:113
Child< k >::Type & child()
Returns the i-th child.
Definition: variadiccompositenode.hh:80
Tag designating a composite node that is based on variadic templates.
Definition: nodetags.hh:25
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: variadiccompositenode.hh:48
VariadicCompositeNode()
Default constructor.
Definition: variadiccompositenode.hh:152
tuple_element< k, NodeStorage >::type Storage
The storage type of the child.
Definition: variadiccompositenode.hh:66
VariadicCompositeNode(const NodeStorage &children)
Initialize the VariadicCompositeNode with a copy of the passed-in storage type.
Definition: variadiccompositenode.hh:176
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: variadiccompositenode.hh:42
Access to the type and storage type of the i-th child.
Definition: variadiccompositenode.hh:55
Base class for composite nodes based on variadic templates.
Definition: variadiccompositenode.hh:27
tuple< Children...> ChildTypes
A tuple storing the types of all children.
Definition: variadiccompositenode.hh:39
VariadicCompositeNode(Children &...children)
Definition: variadiccompositenode.hh:164
VariadicCompositeNode(shared_ptr< Children >...children)
Initialize the VariadicCompositeNode with copies of the passed in Storage objects.
Definition: variadiccompositenode.hh:171
tuple_element< k, ChildTypes >::type Type
The type of the child.
Definition: variadiccompositenode.hh:60
dune_static_assert((k< CHILDREN),"child index out of range")
const Child< k >::Type & child() const
Returns the i-th child (const version).
Definition: variadiccompositenode.hh:90