Go to the documentation of this file.
4 #ifndef DUNE_TYPETREE_TREEPATH_HH
5 #define DUNE_TYPETREE_TREEPATH_HH
10 #include <dune/common/documentation.hh>
11 #include <dune/common/typetraits.hh>
25 namespace TreePathType {
29 template<std::size_t... i>
44 template<std::size_t... i>
46 :
public index_constant<sizeof...(i)>
50 template<std::size_t... i>
56 template<
typename,std::
size_t>
59 template<std::size_t k, std::size_t... i>
65 template<
typename,std::
size_t>
68 template<std::size_t k, std::size_t... i>
78 template<std::
size_t k>
80 :
public index_constant<k>
88 template<std::size_t j, std::size_t k, std::size_t... l>
96 template<std::size_t k, std::size_t... i>
98 :
public index_constant<k>
101 template<
typename, std::size_t...>
104 template<std::size_t k, std::size_t... i>
110 template<std::size_t j,
121 template<std::size_t k, std::size_t... i>
127 template<
typename,
typename>
130 template<std::size_t... i, std::size_t... k>
136 template<std::size_t... i>
140 template<std::size_t k, std::size_t... i>
147 template<std::size_t... i>
165 return _stack.size();
177 return _stack.back();
183 return _stack.front();
189 for (std::size_t i = 0; i < tp.
size(); ++i)
211 #ifndef DOXYGEN // DynamicTreePath subclasses are implementation details and never exposed to the user
221 class MutableDynamicTreePath
222 :
public DynamicTreePath
227 typedef DynamicTreePath ViewType;
239 void set_back(std::size_t v)
244 DynamicTreePath view()
251 MutableDynamicTreePath(Stack& stack)
252 : DynamicTreePath(stack)
262 template<std::
size_t treeDepth>
263 class MakeableDynamicTreePath
264 :
private FixedCapacityStack<std::size_t,treeDepth>
265 ,
public MutableDynamicTreePath
270 MutableDynamicTreePath mutablePath()
272 return static_cast<MutableDynamicTreePath&>(*
this);
275 MakeableDynamicTreePath()
276 : MutableDynamicTreePath(static_cast<FixedCapacityStackView<std::size_t>&>(*this))
284 template<TreePathType::Type tpType>
285 struct TreePathFactory;
291 template<
typename Tree>
292 static TreePath<> create(
const Tree& tree)
300 struct TreePathFactory<TreePathType::
dynamic>
302 template<
typename Tree>
303 static MakeableDynamicTreePath<TreeInfo<Tree>::depth> create(
const Tree& tree)
305 return MakeableDynamicTreePath<TreeInfo<Tree>::depth>();
321 template<
typename... T>
343 template<
typename... U,
typename std::enable_if<(
sizeof...(T) > 0 &&
sizeof...(U) ==
sizeof...(T)),
bool>::type =
true>
359 using Data = std::tuple<T...>;
372 template<
typename... T>
380 template<
typename... T>
403 template<std::size_t i,
typename... T>
405 ->
typename std::decay<decltype(std::get<i>(tp._data))>::type
407 return std::get<i>(tp._data);
426 template<std::size_t i,
typename... T>
429 return std::get<i>(tp._data);
438 template<
typename... T,
typename std::enable_if<(
sizeof...(T) > 0),
bool>::type =
true>
446 template<
typename... T,
typename std::enable_if<(
sizeof...(T) > 0),
bool>::type =
true>
458 template<
typename... T>
460 -> decltype(treePathEntry<0>(tp))
462 return treePathEntry<0>(tp);
466 template<
typename... T>
469 return treePathEntry<0>(tp);
476 template<
typename... T>
479 return HybridTreePath<T...,std::size_t>(std::tuple_cat(tp._data,std::make_tuple(i)));
497 template<std::size_t i,
typename... T>
500 return HybridTreePath<T...,index_constant<i> >(std::tuple_cat(tp._data,std::make_tuple(i_)));
507 template<
typename... T>
510 return HybridTreePath<std::size_t,T...>(std::tuple_cat(std::make_tuple(element),tp._data));
528 template<std::size_t i,
typename... T>
531 return HybridTreePath<index_constant<i>,T...>(std::tuple_cat(std::make_tuple(_i),tp._data));
539 template<std::size_t i,
typename... T>
540 typename std::enable_if<
543 print_hybrid_tree_path(std::ostream& os,
const HybridTreePath<T...>& tp, index_constant<i> _i)
547 template<std::size_t i,
typename... T>
548 typename std::enable_if<
551 print_hybrid_tree_path(std::ostream& os,
const HybridTreePath<T...>& tp, index_constant<i> _i)
554 print_hybrid_tree_path(os,tp,index_constant<i+1>{});
562 template<
typename... T>
565 os <<
"HybridTreePath< ";
566 impl::print_hybrid_tree_path(os, tp, index_constant<0>{});
576 #endif // DUNE_TYPETREE_TREEPATH_HH
constexpr std::size_t treePathSize(const TreePath< i... > &)
Returns the size (number of components) of the given TreePath.
Definition: treepath.hh:51
Definition: fixedcapacitystack.hh:19
std::size_t frontIndex(const HybridTreePath< T... > &tp)
Returns the index value of the first element of the HybridTreePath.
Definition: treepath.hh:467
Definition: treepath.hh:26
Definition: treepath.hh:75
friend std::ostream & operator<<(std::ostream &os, const DynamicTreePath &tp)
Definition: treepath.hh:186
Definition: treepath.hh:26
A hybrid version of TreePath that supports both compile time and run time indices.
Definition: treepath.hh:322
constexpr static index_sequence enumerate()
Returns an index_sequence for enumerating the components of this HybridTreePath.
Definition: treepath.hh:349
std::size_t back() const
Get the last index value.
Definition: treepath.hh:175
std::size_t size() const
Get the size (length) of this path.
Definition: treepath.hh:163
TreePath< k, i... > type
Definition: treepath.hh:71
Definition: treepath.hh:119
Type
Definition: treepath.hh:26
auto treePathEntry(const HybridTreePath< T... > &tp, index_constant< i >={}) -> typename std::decay< decltype(std::get< i >(tp._data))>::type
Returns a copy of the i-th element of the HybridTreePath.
Definition: treepath.hh:404
auto front(const HybridTreePath< T... > &tp) -> decltype(treePathEntry< 0 >(tp))
Returns a copy of the first element of the HybridTreePath.
Definition: treepath.hh:459
std::size_t treePathIndex(const HybridTreePath< T... > &tp, index_constant< i >={})
Returns the index value of the i-th element of the HybridTreePath.
Definition: treepath.hh:427
Definition: treepath.hh:94
Definition: accumulate_static.hh:13
TreePath view()
Definition: treepath.hh:37
HybridTreePath< T..., std::size_t > push_back(const HybridTreePath< T... > &tp, std::size_t i)
Appends a run time index to a HybridTreePath.
Definition: treepath.hh:477
HybridTreePath< std::size_t, T... > push_front(const HybridTreePath< T... > &tp, std::size_t element)
Prepends a run time index to a HybridTreePath.
Definition: treepath.hh:508
std::index_sequence_for< T... > index_sequence
An index_sequence for the entries in this HybridTreePath.
Definition: treepath.hh:328
std::size_t backIndex(const HybridTreePath< T... > &tp)
Returns the index value of the last element of the HybridTreePath.
Definition: treepath.hh:447
constexpr HybridTreePath(U... t)
Constructor from arguments.
Definition: treepath.hh:344
TreePath< i..., k > type
Definition: treepath.hh:62
Definition: treepath.hh:57
Definition: treepath.hh:26
Definition: treepath.hh:128
constexpr HybridTreePath()
Default constructor.
Definition: treepath.hh:331
constexpr HybridTreePath< T... > hybridTreePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:373
auto back(const HybridTreePath< T... > &tp) -> decltype(treePathEntry< treePathSize(tp) -1 >(tp))
Returns a copy of the last element of the HybridTreePath.
Definition: treepath.hh:439
std::ostream & operator<<(std::ostream &os, const TreePath< i... > &tp)
Definition: treepath.hh:148
Definition: treepath.hh:42
Definition: treepath.hh:66
Definition: treepath.hh:102
std::size_t element(std::size_t pos) const
Get the index value at position pos.
Definition: treepath.hh:169
A TreePath that stores the path of a node as runtime information.
Definition: treepath.hh:157
constexpr HybridTreePath(std::tuple< T... > t)
Constructor from a std::tuple
Definition: treepath.hh:338
TreePath< i... > type
Definition: treepath.hh:107
TreePath< i... > type
Definition: treepath.hh:124
Definition: treepath.hh:30
TreePath ViewType
Definition: treepath.hh:36
constexpr TreePath()=default
std::size_t front() const
Get the first index value.
Definition: treepath.hh:181
TreePath< i..., k... > type
Definition: treepath.hh:133
TreePath mutablePath()
Definition: treepath.hh:38
void print_tree_path(std::ostream &os)
Definition: treepath.hh:137