4 #ifndef DUNE_TYPETREE_TREEPATH_HH
5 #define DUNE_TYPETREE_TREEPATH_HH
9 #include <dune/common/documentation.hh>
10 #include <dune/common/static_assert.hh>
11 #include <dune/common/typetraits.hh>
25 namespace TreePathType {
29 #if HAVE_VARIADIC_TEMPLATES || DOXYGEN
31 template<std::size_t... i>
41 template<std::size_t... i>
43 :
public integral_constant<std::size_t, sizeof...(i)>
46 template<
typename,std::
size_t>
49 template<std::size_t k, std::size_t... i>
55 template<
typename,std::
size_t>
58 template<std::size_t k, std::size_t... i>
68 template<std::
size_t k>
70 :
public integral_constant<std::size_t,k>
78 template<std::size_t j, std::size_t k, std::size_t... l>
86 template<std::size_t k, std::size_t... i>
88 :
public integral_constant<std::size_t,k>
91 template<
typename, std::size_t...>
94 template<std::size_t k, std::size_t... i>
100 template<std::size_t j,
111 template<std::size_t k, std::size_t... i>
117 template<
typename,
typename>
120 template<std::size_t... i, std::size_t... k>
126 template<std::size_t... i>
130 template<std::size_t k, std::size_t... i>
137 template<std::size_t... i>
153 static const std::size_t noChildIndex = ~std::size_t(0);
171 template<std::size_t i0 = noChildIndex, std::size_t i1 = noChildIndex,
172 std::size_t i2 = noChildIndex, std::size_t i3 = noChildIndex,
173 std::size_t i4 = noChildIndex, std::size_t i5 = noChildIndex,
174 std::size_t i6 = noChildIndex, std::size_t i7 = noChildIndex,
175 std::size_t i8 = noChildIndex, std::size_t i9 = noChildIndex>
177 dune_static_assert(i0 == noChildIndex ? i1 == noChildIndex :
true,
178 "Only trailing indices my be noChildIndex");
179 dune_static_assert(i1 == noChildIndex ? i2 == noChildIndex :
true,
180 "Only trailing indices my be noChildIndex");
181 dune_static_assert(i2 == noChildIndex ? i3 == noChildIndex :
true,
182 "Only trailing indices my be noChildIndex");
183 dune_static_assert(i3 == noChildIndex ? i4 == noChildIndex :
true,
184 "Only trailing indices my be noChildIndex");
185 dune_static_assert(i4 == noChildIndex ? i5 == noChildIndex :
true,
186 "Only trailing indices my be noChildIndex");
187 dune_static_assert(i5 == noChildIndex ? i6 == noChildIndex :
true,
188 "Only trailing indices my be noChildIndex");
189 dune_static_assert(i6 == noChildIndex ? i7 == noChildIndex :
true,
190 "Only trailing indices my be noChildIndex");
191 dune_static_assert(i7 == noChildIndex ? i8 == noChildIndex :
true,
192 "Only trailing indices my be noChildIndex");
193 dune_static_assert(i8 == noChildIndex ? i9 == noChildIndex :
true,
194 "Only trailing indices my be noChildIndex");
197 TreePath
view() {
return *
this; }
209 class TreePathPopFront {
211 "TreePathPopFront works on TreePaths only");
214 typedef ImplementationDefined type;
218 template<std::size_t i0, std::size_t i1, std::size_t i2, std::size_t i3,
219 std::size_t i4, std::size_t i5, std::size_t i6, std::size_t i7,
220 std::size_t i8, std::size_t i9>
221 struct TreePathPopFront<TreePath<i0, i1, i2, i3, i4, i5, i6, i7, i8, i9> >
223 dune_static_assert(i0 != noChildIndex,
224 "Can't pop first element from an empty TreePath");
225 typedef TreePath<i1, i2, i3, i4, i5, i6, i7, i8, i9> type;
231 class TreePathFront {
233 "TreePathPopFront works on TreePaths only");
236 static const std::size_t
value = implementationDefined;
240 template<std::size_t i0, std::size_t i1, std::size_t i2, std::size_t i3,
241 std::size_t i4, std::size_t i5, std::size_t i6, std::size_t i7,
242 std::size_t i8, std::size_t i9>
243 class TreePathFront<TreePath<i0, i1, i2, i3, i4, i5, i6, i7, i8, i9> > :
244 public integral_constant<std::size_t, i0>
246 dune_static_assert(i0 != noChildIndex,
247 "Can't take first element of an empty TreePath");
252 template<
class TP, std::
size_t i>
253 class TreePathPushFront {
255 "TreePathPushFront works on TreePaths only");
258 typedef ImplementationDefined type;
262 template<std::size_t i0, std::size_t i1, std::size_t i2, std::size_t i3,
263 std::size_t i4, std::size_t i5, std::size_t i6, std::size_t i7,
264 std::size_t i8, std::size_t i9, std::size_t i>
265 struct TreePathPushFront<TreePath<i0, i1, i2, i3, i4, i5, i6, i7, i8, i9>,
268 dune_static_assert(i0 ?
false :
false,
"TreePathPushFront: exceeded "
269 "implementation limit on TreePath size");
271 template<std::size_t i0, std::size_t i1, std::size_t i2, std::size_t i3,
272 std::size_t i4, std::size_t i5, std::size_t i6, std::size_t i7,
273 std::size_t i8, std::size_t i>
274 struct TreePathPushFront<TreePath<i0, i1, i2, i3, i4, i5, i6, i7, i8>, i> {
275 typedef TreePath<i, i0, i1, i2, i3, i4, i5, i6, i7, i8> type;
287 class TreePathReverse {
290 typedef ImplementationDefined type;
293 template<
class TP,
class TP2 = TreePath<> >
294 struct TreePathReverse :
295 public TreePathReverse<
296 typename TreePathPopFront<TP>::type,
297 typename TreePathPushFront<TP2, TreePathFront<TP>::value>::type>
300 struct TreePathReverse<TreePath<>, TP2>
301 {
typedef TP2 type; };
313 struct TreePathPopBack {
315 typedef ImplementationDefined type;
319 struct TreePathPopBack :
320 public TreePathReverse<
321 typename TreePathPopFront<typename TreePathReverse<TP>::type>::type
329 struct TreePathBack {
331 static const std::size_t
value = implementationDefined;
335 struct TreePathBack :
336 public TreePathFront<typename TreePathReverse<TP>::type>
341 template<
class TP, std::
size_t i>
343 struct TreePathPushBack {
345 typedef ImplementationDefined type;
348 template<
class TP, std::
size_t i>
349 struct TreePathPushBack :
350 public TreePathReverse<
351 typename TreePathPushFront<typename TreePathReverse<TP>::type, i>::type
364 struct TreePathSize {
366 static const std::size_t
value = implementationDefined;
370 struct TreePathSize :
371 public integral_constant<
373 TreePathSize<typename TreePathPopFront<TP>::type>::value+1
377 struct TreePathSize<TreePath<> > :
378 public integral_constant<std::size_t, 0>
385 struct TreePathElement {
387 static const std::size_t
value = implementationDefined;
390 template<std::
size_t pos,
class TP>
391 struct TreePathElement :
392 public TreePathElement<pos-1, typename TreePathPopFront<TP>::type>
395 struct TreePathElement<0, TP> :
396 public TreePathFront<TP>
401 template<
typename,
typename>
402 struct TreePathConcat;
404 template<
typename TP1,
typename TP2>
405 struct TreePathConcat
407 typedef typename TreePathConcat<
408 typename TreePathPushBack<
412 typename TreePathPopFront<TP2>::type
416 template<
typename TP1>
417 struct TreePathConcat<TP1,TreePath<> >
422 #endif // HAVE_VARIADIC_TEMPLATES
434 return _stack.size();
446 return _stack.back();
452 return _stack.front();
458 for (std::size_t i = 0; i < tp.
size(); ++i)
480 #ifndef DOXYGEN // DynamicTreePath subclasses are implementation details and never exposed to the user
490 class MutableDynamicTreePath
491 :
public DynamicTreePath
496 typedef DynamicTreePath ViewType;
498 void push_back(std::size_t v)
508 void set_back(std::size_t v)
513 DynamicTreePath view()
520 MutableDynamicTreePath(Stack& stack)
521 : DynamicTreePath(stack)
531 template<std::
size_t treeDepth>
532 class MakeableDynamicTreePath
533 :
private FixedCapacityStack<std::size_t,treeDepth>
534 ,
public MutableDynamicTreePath
539 MutableDynamicTreePath mutablePath()
541 return static_cast<MutableDynamicTreePath&
>(*this);
544 MakeableDynamicTreePath()
545 : MutableDynamicTreePath(static_cast<FixedCapacityStackView<std::size_t>&>(*this))
553 template<TreePathType::Type tpType>
554 struct TreePathFactory;
560 template<
typename Tree>
561 static TreePath<> create(
const Tree& tree)
569 struct TreePathFactory<TreePathType::
dynamic>
571 template<
typename Tree>
572 static MakeableDynamicTreePath<TreeInfo<Tree>::depth> create(
const Tree& tree)
574 return MakeableDynamicTreePath<TreeInfo<Tree>::depth>();
585 #endif // DUNE_TYPETREE_TREEPATH_HH
Definition: treepath.hh:26
TreePath mutablePath()
Definition: treepath.hh:35
Definition: treepath.hh:32
std::size_t front() const
Get the first index value.
Definition: treepath.hh:450
TreePath< i..., k...> type
Definition: treepath.hh:123
TreePath< k, i...> type
Definition: treepath.hh:61
void print_tree_path(std::ostream &os)
Definition: treepath.hh:127
Definition: treepath.hh:26
std::size_t element(std::size_t pos) const
Get the index value at position pos.
Definition: treepath.hh:438
Definition: treepath.hh:92
Definition: treepath.hh:56
std::size_t back() const
Get the last index value.
Definition: treepath.hh:444
std::size_t size() const
Get the size (length) of this path.
Definition: treepath.hh:432
A TreePath that stores the path of a node as runtime information.
Definition: treepath.hh:426
std::ostream & operator<<(std::ostream &os, const TreePath< i...> &tp)
Definition: treepath.hh:138
TreePath view()
Definition: treepath.hh:34
Definition: treepath.hh:118
Definition: treepath.hh:26
TreePath< i..., k > type
Definition: treepath.hh:52
Definition: fixedcapacitystack.hh:19
friend std::ostream & operator<<(std::ostream &os, const DynamicTreePath &tp)
Definition: treepath.hh:455
Definition: treepath.hh:39
static const std::size_t value
Definition: compositenode.hh:38
Definition: treepath.hh:65
TreePath< i...> type
Definition: treepath.hh:97
Type
Definition: treepath.hh:26
Definition: treepath.hh:84
Definition: treepath.hh:47
TreePath ViewType
Definition: treepath.hh:33
Definition: treepath.hh:109
TreePath< i...> type
Definition: treepath.hh:114