DASH  0.3.0
ViewOrigin.h
1 #ifndef DASH__VIEW__VIEW_ORIGIN_H__INCLUDED
2 #define DASH__VIEW__VIEW_ORIGIN_H__INCLUDED
3 
4 #include <dash/view/IndexSet.h>
5 #include <dash/view/ViewTraits.h>
6 #include <dash/view/ViewIterator.h>
7 
8 #include <dash/Types.h>
9 #include <dash/Range.h>
10 #include <dash/Iterator.h>
11 
12 
13 namespace dash {
14 
15 // ------------------------------------------------------------------------
16 // ViewOrigin
17 // ------------------------------------------------------------------------
18 
22 template <dim_t NDim = 1>
24 {
25  typedef ViewOrigin self_t;
26 
27 public:
28  typedef dash::default_index_t index_type;
29  typedef dash::default_extent_t size_type;
30  typedef self_t domain_type;
31  typedef self_t local_type;
32  typedef self_t global_type;
33  typedef IndexSetIdentity<self_t> index_set_type;
34 
35 public:
36  typedef std::integral_constant<bool, false> is_local;
37  typedef std::integral_constant<dim_t, NDim> rank;
38 
39 private:
40  std::array<size_type, NDim> _extents = { };
41  std::array<index_type, NDim> _offsets = { };
42  index_set_type _index_set;
43 public:
44  constexpr ViewOrigin() = delete;
45  constexpr ViewOrigin(self_t &&) = default;
46  constexpr ViewOrigin(const self_t &) = default;
47  ~ViewOrigin() = default;
48  self_t & operator=(self_t &&) = default;
49  self_t & operator=(const self_t &) = default;
50 
51  template <std::size_t N>
52  constexpr explicit ViewOrigin(
53  std::array<dim_t, N> extents)
54  : _extents(extents)
55  , _index_set(*this)
56  { }
57 
58  constexpr const domain_type & domain() const {
59  return *this;
60  }
61 
62  constexpr const index_set_type & index_set() const {
63  return _index_set;
64  }
65 
66  constexpr bool operator==(const self_t & rhs) const {
67  return (this == &rhs);
68  }
69 
70  constexpr bool operator!=(const self_t & rhs) const {
71  return !(*this == rhs);
72  }
73 
74  // ---- extents ---------------------------------------------------------
75 
76  constexpr const std::array<size_type, NDim> extents() const {
77  return _extents;
78  }
79 
80  template <dim_t ExtentDim = 0>
81  constexpr index_type extent() const {
82  return _extents[ExtentDim];
83  }
84 
85  constexpr index_type extent(dim_t extent_dim) const {
86  return _extents[extent_dim];
87  }
88 
89  // ---- offsets ---------------------------------------------------------
90 
91  constexpr const std::array<index_type, NDim> & offsets() const {
92  return _offsets;
93  }
94 
95  template <dim_t OffsetDim = 0>
96  constexpr index_type offset() const {
97  return _offsets[OffsetDim];
98  }
99 
100  constexpr index_type offset(dim_t offset_dim) const {
101  return _offsets[offset_dim];
102  }
103 
104  // ---- size ------------------------------------------------------------
105 
106  template <dim_t SizeDim = 0>
107  constexpr index_type size() const {
108  return extent<SizeDim>() *
109  (SizeDim + 1 < NDim
110  ? size<SizeDim + 1>()
111  : 1);
112  }
113 };
114 
115 template <dim_t NDim>
116 struct view_traits<ViewOrigin<NDim>> {
120 
121  typedef typename ViewOrigin<NDim>::index_type index_type;
122  typedef typename ViewOrigin<NDim>::size_type size_type;
123  typedef typename ViewOrigin<NDim>::index_set_type index_set_type;
124 
125  typedef std::integral_constant<bool, false> is_projection;
126  typedef std::integral_constant<bool, true> is_view;
127  typedef std::integral_constant<bool, true> is_origin;
128  typedef std::integral_constant<bool, false> is_local;
129 
130  typedef std::integral_constant<dim_t, NDim> rank;
131 };
132 
133 } // namespace dash
134 
135 #endif // DASH__VIEW__VIEW_ORIGIN_H__INCLUDED
internal::default_unsigned_index default_extent_t
Unsigned integer type used as default for extent values.
Definition: Types.h:64
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
Monotype for the logical symbol that represents a view origin.
Definition: ViewOrigin.h:23
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
Definition: Types.h:59
View type traits.
Definition: ViewTraits.h:31