dune-typetree  2.3.1
childextraction.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_TYPETREE_CHILDEXTRACTION_HH
5 #define DUNE_TYPETREE_CHILDEXTRACTION_HH
6 
7 #include <dune/common/documentation.hh>
8 #include <dune/common/static_assert.hh>
9 #include <dune/common/typetraits.hh>
10 #include <dune/common/shared_ptr.hh>
11 
13 
14 
15 namespace Dune {
16  namespace TypeTree {
17 
18 
23 
25  template<typename Node, typename TreePath>
27  {
28 
30  typedef typename extract_child_type<
34 
36  typedef typename extract_child_type<
40 
42  typedef typename extract_child_type<
46 
47 
48  };
49 
50 #ifndef DOXYGEN
51 
52 #if HAVE_VARIADIC_TEMPLATES
53 
54  // end of recursion
55  template<typename Node>
56  struct extract_child_type<Node,TypeTree::TreePath<> >
57  {
58  typedef Node type;
59  typedef shared_ptr<Node> storage_type;
60  typedef shared_ptr<const Node> const_storage_type;
61  };
62 
63 #else // HAVE_VARIADIC_TEMPLATES
64 
65 
66  // end of recursion
67  template<typename Node>
68  struct extract_child_type<Node,
69  TypeTree::TreePath<
70  noChildIndex,noChildIndex,
71  noChildIndex,noChildIndex,
72  noChildIndex,noChildIndex,
73  noChildIndex,noChildIndex,
74  noChildIndex,noChildIndex
75  >
76  >
77  {
78  typedef Node type;
79  typedef shared_ptr<Node> storage_type;
80  typedef shared_ptr<const Node> const_storage_type;
81  };
82 
83 #endif // HAVE_VARIADIC_TEMPLATES
84 
85 #endif // DOXYGEN
86 
87 
88 
89 #ifdef DOXYGEN
90 
92 
115  template<typename Node, typename TreePath>
116  ImplementationDefined& extract_child(Node& node, Treepath tp)
117  {}
118 
120 
143  template<typename Node, typename TreePath>
144  const ImplementationDefined& extract_child(const Node& node, Treepath tp)
145  {}
146 
147 #else // DOXYGEN
148 
149  // ********************************************************************************
150  // non-const implementation
151  // ********************************************************************************
152 
153  template<typename Node, typename TreePath>
154  typename enable_if<
156  typename extract_child_type<Node,TreePath>::type&
157  >::type
158  extract_child(Node& node, TreePath tp)
159  {
160  return extract_child(node.template child<TypeTree::TreePathFront<TreePath>::value>(),
162  }
163 
164  template<typename Node, typename TreePath>
165  typename enable_if<
168  >::type
169  extract_child(Node& node, TreePath tp)
170  {
171  return node.template child<TypeTree::TreePathFront<TreePath>::value>();
172  }
173 
174  template<typename Node, typename TreePath>
175  typename enable_if<
177  Node&
178  >::type
179  extract_child(Node& node, TreePath tp)
180  {
181  return node;
182  }
183 
184  // ********************************************************************************
185  // const implementation
186  // ********************************************************************************
187 
188  template<typename Node, typename TreePath>
189  typename enable_if<
191  const typename extract_child_type<Node,TreePath>::type&
192  >::type
193  extract_child(const Node& node, TreePath tp)
194  {
195  return extract_child(node.template child<TypeTree::TreePathFront<TreePath>::value>(),
196  typename TypeTree::TreePathPopFront<TreePath>::type());
197  }
198 
199  template<typename Node, typename TreePath>
200  typename enable_if<
202  const typename Node::template Child<TypeTree::TreePathFront<TreePath>::value>::Type&
203  >::type
204  extract_child(const Node& node, TreePath tp)
205  {
206  return node.template child<TypeTree::TreePathFront<TreePath>::value>();
207  }
208 
209  template<typename Node, typename TreePath>
210  typename enable_if<
212  const Node&
213  >::type
214  extract_child(const Node& node, TreePath tp)
215  {
216  return node;
217  }
218 
219 
220 #endif // DOXYGEN
221 
222 
223 
224 #ifdef DOXYGEN
225 
228 
251  template<typename Node, typename TreePath>
252  ImplementationDefined extract_child_storage(Node& node, Treepath tp)
253  {}
254 
257 
280  template<typename Node, typename TreePath>
281  ImplementationDefined extract_child_storage(const Node& node, Treepath tp)
282  {}
283 
284 #else // DOXYGEN
285 
286  // ********************************************************************************
287  // non-const implementation
288  // ********************************************************************************
289 
290  template<typename Node, typename TreePath>
291  typename enable_if<
293  typename extract_child_type<Node,TreePath>::storage_type
294  >::type
295  extract_child_storage(Node& node, TreePath tp)
296  {
299  }
300 
301  template<typename Node, typename TreePath>
302  typename enable_if<
304  typename Node::template Child<TypeTree::TreePathFront<TreePath>::value>::Storage&
305  >::type
306  extract_child_storage(Node& node, TreePath tp)
307  {
309  }
310 
311  template<typename Node, typename TreePath>
312  typename enable_if<
314  >::type
315  extract_child_storage(Node& node, TreePath tp)
316  {
317  dune_static_assert((Dune::AlwaysFalse<Node>::value),
318  "extract_child_storage only works for real children, not the node itself.");
319  }
320 
321  // ********************************************************************************
322  // const implementation
323  // ********************************************************************************
324 
325  template<typename Node, typename TreePath>
326  typename enable_if<
328  typename extract_child_type<Node,TreePath>::const_storage_type
329  >::type
330  extract_child_storage(const Node& node, TreePath tp)
331  {
333  typename TypeTree::TreePathPopFront<TreePath>::type());
334  }
335 
336  template<typename Node, typename TreePath>
337  typename enable_if<
339  typename Node::template Child<TypeTree::TreePathFront<TreePath>::value>::ConstStorage
340  >::type
341  extract_child_storage(const Node& node, TreePath tp)
342  {
344  }
345 
346  template<typename Node, typename TreePath>
347  typename enable_if<
349  >::type
350  extract_child_storage(const Node& node, TreePath tp)
351  {
352  dune_static_assert((Dune::AlwaysFalse<Node>::value),
353  "extract_child_storage only works for real children, not the node itself.");
354  }
355 
356 
357 #endif // DOXYGEN
358 
359 
361 
362  } // namespace TypeTree
363 } //namespace Dune
364 
365 #endif // DUNE_TYPETREE_CHILDEXTRACTION_HH
Definition: treepath.hh:32
ImplementationDefined & extract_child(Node &node, Treepath tp)
Extract the child of a node located at tp (non-const version).
Definition: childextraction.hh:116
extract_child_type< typename Node::template Child< TypeTree::TreePathFront< TreePath >::value >::Type, typename TypeTree::TreePathPopFront< TreePath >::type >::storage_type storage_type
The storage type of the child.
Definition: childextraction.hh:39
extract_child_type< typename Node::template Child< TypeTree::TreePathFront< TreePath >::value >::Type, typename TypeTree::TreePathPopFront< TreePath >::type >::type type
The type of the child.
Definition: childextraction.hh:33
extract_child_type< typename Node::template Child< TypeTree::TreePathFront< TreePath >::value >::Type, typename TypeTree::TreePathPopFront< TreePath >::type >::const_storage_type const_storage_type
The const storage type of the child.
Definition: childextraction.hh:45
Definition: treepath.hh:39
Extract the type of the child of Node at position TreePath.
Definition: childextraction.hh:26
static const std::size_t value
Definition: compositenode.hh:38
Type
Definition: treepath.hh:26
Definition: treepath.hh:84
Definition: treepath.hh:109
ImplementationDefined extract_child_storage(Node &node, Treepath tp)
Definition: childextraction.hh:252