DASH  0.3.0
CartView.h
1 #ifndef DASH__VIEW__CART_VIEW_H__INCLUDED
2 #define DASH__VIEW__CART_VIEW_H__INCLUDED
3 
4 #include <dash/Types.h>
5 #include <dash/Dimensional.h>
6 #include <dash/Cartesian.h>
7 
8 #include <iterator>
9 
10 
11 namespace dash {
12 
17 template<
18  typename Iter,
19  dim_t NumDimensions,
20  MemArrange Arrangement = ROW_MAJOR,
21  typename SizeType = dash::default_size_t >
22 class CartViewBase {
23 public:
24  typedef typename std::iterator_traits<Iter>::value_type value_type;
25  typedef typename std::iterator_traits<Iter>::reference reference;
26 
27 private:
29  Iter m_begin;
30 
31 public:
32  // construct from iterator
33  template<typename ... Args>
34  CartViewBase(Iter it, Args... args) :
35  m_cart { (SizeType)args ... },
36  m_begin { it } {
37  }
38 
39  // construct from container
40  template<typename Container, typename... Args>
41  CartViewBase(Container & container, Args... args) :
42  m_cart { args ... },
43  m_begin { container.begin() } {
44  }
45 
46  constexpr SizeType rank() const {
47  return m_cart.rank();
48  }
49 
50  constexpr SizeType size() const {
51  return m_cart.size();
52  }
53 
54  constexpr SizeType extent(dim_t dim) const {
55  return m_cart.extent(dim);
56  }
57 
58  template<typename ... Args>
59  reference at(Args ... args) const {
60  Iter it = m_begin;
61  std::advance(it, m_cart.at(args...));
62  return *it;
63  }
64 
65  // x(), y(), z() accessors
66  // enabled only for the appropriate sizes
67  template<dim_t U=NumDimensions>
68  constexpr typename std::enable_if<(U>0),SizeType>::type
69  x(SizeType offs) const {
70  return m_cart.x(offs);
71  }
72 
73  template<dim_t U=NumDimensions>
74  constexpr typename std::enable_if<(U>1),SizeType>::type
75  y(SizeType offs) const {
76  return m_cart.y(offs);
77  }
78 
79  template<dim_t U=NumDimensions>
80  constexpr typename std::enable_if<(U>2),SizeType>::type
81  z(SizeType offs) const {
82  return m_cart.z(offs);
83  }
84 
85 };
86 
90 template<
91  typename Iter,
92  dim_t NumDimensions,
93  MemArrange Arrangement = ROW_MAJOR,
94  typename SizeType = dash::default_size_t >
95 struct CartView
96 : public CartViewBase<Iter, NumDimensions, Arrangement, SizeType> {
97 public:
98  template<typename... Args>
99  CartView(
100  Iter it,
101  Args... args)
103  it,
104  args...) { }
105 
106  template<typename Container, typename... Args>
107  CartView(
108  Container & cont,
109  Args... args)
111  cont,
112  args...) { }
113 };
114 
115 } // namespace dash
116 
117 #endif // DASH__VIEW__CART_VIEW_H__INCLUDED
internal::default_unsigned_index default_size_t
Unsigned integer type used as default for size values.
Definition: Types.h:69
Base class for a cartesian view, i.e.
Definition: CartView.h:22
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
constexpr dim_t rank() const noexcept
The number of dimension in the cartesian space with extent greater than 1.
Definition: Cartesian.h:315
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
Cartesian view class.
Definition: CartView.h:95
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
Definition: Cartesian.h:412
constexpr IndexType at(IndexType arg, Args... args) const
Convert the given coordinates to their respective linear index.
Definition: Cartesian.h:429
constexpr std::enable_if<(U > 2), SizeType >::type z(SizeType offs) const
Accessor for dimension 3 (z), enabled for dimensionality > 2.
Definition: Cartesian.h:609
constexpr std::enable_if<(U > 0), SizeType >::type x(SizeType offs) const
Accessor for dimension 1 (x), enabled for dimensionality > 0.
Definition: Cartesian.h:591
constexpr std::enable_if<(U > 1), SizeType >::type y(SizeType offs) const
Accessor for dimension 2 (y), enabled for dimensionality > 1.
Definition: Cartesian.h:600
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
Definition: Cartesian.h:395