Jet  v1.3.3
array_accessor2.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_ARRAY_ACCESSOR2_H_
8 #define INCLUDE_JET_ARRAY_ACCESSOR2_H_
9 
10 #include <jet/array_accessor.h>
11 #include <jet/point2.h>
12 #include <jet/size2.h>
13 #include <utility> // just make cpplint happy..
14 
15 namespace jet {
16 
30 template <typename T>
31 class ArrayAccessor<T, 2> final {
32  public:
35 
39  ArrayAccessor(const Size2& size, T* const data);
40 
45  ArrayAccessor(size_t width, size_t height, T* const data);
46 
49 
51  void set(const ArrayAccessor& other);
52 
54  void reset(const Size2& size, T* const data);
55 
57  void reset(size_t width, size_t height, T* const data);
58 
60  T& at(size_t i);
61 
63  const T& at(size_t i) const;
64 
66  T& at(const Point2UI& pt);
67 
69  const T& at(const Point2UI& pt) const;
70 
72  T& at(size_t i, size_t j);
73 
75  const T& at(size_t i, size_t j) const;
76 
78  T* const begin() const;
79 
81  T* const end() const;
82 
84  T* begin();
85 
87  T* end();
88 
90  Size2 size() const;
91 
93  size_t width() const;
94 
96  size_t height() const;
97 
99  T* const data() const;
100 
102  void swap(ArrayAccessor& other);
103 
132  template <typename Callback>
133  void forEach(Callback func) const;
134 
163  template <typename Callback>
164  void forEachIndex(Callback func) const;
165 
186  template <typename Callback>
187  void parallelForEach(Callback func);
188 
207  template <typename Callback>
208  void parallelForEachIndex(Callback func) const;
209 
211  size_t index(const Point2UI& pt) const;
212 
214  size_t index(size_t i, size_t j) const;
215 
217  T& operator[](size_t i);
218 
220  const T& operator[](size_t i) const;
221 
223  T& operator()(const Point2UI& pt);
224 
226  const T& operator()(const Point2UI& pt) const;
227 
229  T& operator()(size_t i, size_t j);
230 
232  const T& operator()(size_t i, size_t j) const;
233 
236 
238  operator ConstArrayAccessor<T, 2>() const;
239 
240  private:
241  Size2 _size;
242  T* _data;
243 };
244 
246 template <typename T> using ArrayAccessor2 = ArrayAccessor<T, 2>;
247 
248 
260 template <typename T>
261 class ConstArrayAccessor<T, 2> {
262  public:
265 
269  ConstArrayAccessor(const Size2& size, const T* const data);
270 
276  size_t width, size_t height, const T* const data);
277 
279  explicit ConstArrayAccessor(const ArrayAccessor<T, 2>& other);
280 
283 
285  const T& at(size_t i) const;
286 
288  const T& at(const Point2UI& pt) const;
289 
291  const T& at(size_t i, size_t j) const;
292 
294  const T* const begin() const;
295 
297  const T* const end() const;
298 
300  Size2 size() const;
301 
303  size_t width() const;
304 
306  size_t height() const;
307 
309  const T* const data() const;
310 
339  template <typename Callback>
340  void forEach(Callback func) const;
341 
370  template <typename Callback>
371  void forEachIndex(Callback func) const;
372 
391  template <typename Callback>
392  void parallelForEachIndex(Callback func) const;
393 
395  size_t index(const Point2UI& pt) const;
396 
398  size_t index(size_t i, size_t j) const;
399 
401  const T& operator[](size_t i) const;
402 
404  const T& operator()(const Point2UI& pt) const;
405 
407  const T& operator()(size_t i, size_t j) const;
408 
409  private:
410  Size2 _size;
411  const T* _data;
412 };
413 
415 template <typename T> using ConstArrayAccessor2 = ConstArrayAccessor<T, 2>;
416 
417 } // namespace jet
418 
419 #include "detail/array_accessor2-inl.h"
420 
421 #endif // INCLUDE_JET_ARRAY_ACCESSOR2_H_
jet::Point< T, 2 >
2-D point class.
Definition: point2.h:23
jet::ConstArrayAccessor< T, 2 >::at
const T & at(const Point2UI &pt) const
Returns the const reference to the element at (pt.x, pt.y).
jet::ConstArrayAccessor< T, 2 >::operator()
const T & operator()(size_t i, size_t j) const
Returns the const reference to the element at (i, j).
jet::ConstArrayAccessor< T, 2 >::at
const T & at(size_t i, size_t j) const
Returns the const reference to the element at (i, j).
jet::ArrayAccessor< T, 2 >::begin
T * begin()
Returns the begin iterator of the array.
jet::ArrayAccessor< T, 2 >::height
size_t height() const
Returns the height of the array.
jet::ArrayAccessor< T, 2 >::at
T & at(size_t i)
Returns the reference to the i-th element.
jet::ConstArrayAccessor< T, 2 >::ConstArrayAccessor
ConstArrayAccessor(const ConstArrayAccessor &other)
Copy constructor.
jet::ArrayAccessor< T, 2 >::reset
void reset(const Size2 &size, T *const data)
Resets the array.
jet::ArrayAccessor< T, 2 >::index
size_t index(size_t i, size_t j) const
Returns the linear index of the given 2-D coordinate (i, j).
jet::ArrayAccessor< T, 2 >::at
const T & at(size_t i, size_t j) const
Returns the const reference to the element at (i, j).
jet::ArrayAccessor< T, 2 >::end
T *const end() const
Returns the end iterator of the array.
jet::ConstArrayAccessor< T, 2 >::at
const T & at(size_t i) const
Returns the reference to the i-th element.
jet::ArrayAccessor< T, 2 >::swap
void swap(ArrayAccessor &other)
Swaps the content of with other array accessor.
jet::ArrayAccessor< T, 2 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::ConstArrayAccessor< T, 2 >::end
const T *const end() const
Returns the end iterator of the array.
size2.h
jet::ConstArrayAccessor< T, 2 >::operator()
const T & operator()(const Point2UI &pt) const
Returns the const reference to the element at (pt.x, pt.y).
jet::ConstArrayAccessor< T, 2 >::ConstArrayAccessor
ConstArrayAccessor()
Constructs empty 2-D read-only array accessor.
jet::ArrayAccessor< T, 2 >::at
T & at(const Point2UI &pt)
Returns the reference to the element at (pt.x, pt.y).
jet::ArrayAccessor< T, 2 >::operator()
const T & operator()(size_t i, size_t j) const
Returns the const reference to the element at (i, j).
jet::ArrayAccessor< T, 2 >::operator=
ArrayAccessor & operator=(const ArrayAccessor &other)
Copies given array accessor other.
jet::ConstArrayAccessor< T, 2 >::width
size_t width() const
Returns the width of the array.
jet::ConstArrayAccessor< T, 2 >::ConstArrayAccessor
ConstArrayAccessor(const ArrayAccessor< T, 2 > &other)
Constructs a read-only array accessor from read/write accessor.
jet::ArrayAccessor< T, 2 >::ArrayAccessor
ArrayAccessor(const ArrayAccessor &other)
Copy constructor.
jet::ArrayAccessor< T, 2 >::set
void set(const ArrayAccessor &other)
Replaces the content with given other array accessor.
array_accessor.h
jet::ArrayAccessor< T, 2 >::width
size_t width() const
Returns the width of the array.
jet::ArrayAccessor< T, 2 >::at
const T & at(size_t i) const
Returns the const reference to the i-th element.
jet::ConstArrayAccessor< T, 2 >::ConstArrayAccessor
ConstArrayAccessor(size_t width, size_t height, const T *const data)
jet
Definition: advection_solver2.h:18
jet::ArrayAccessor< T, 2 >::size
Size2 size() const
Returns the size of the array.
jet::ConstArrayAccessor< T, 2 >
2-D read-only array accessor class.
Definition: array_accessor2.h:261
jet::ConstArrayAccessor< T, 2 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to the i-th element.
jet::ConstArrayAccessor< T, 2 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::ConstArrayAccessor< T, 2 >::height
size_t height() const
Returns the height of the array.
jet::ConstArrayAccessor
Generic N-dimensional read-only array accessor class interface.
Definition: array_accessor.h:47
jet::ArrayAccessor< T, 2 >::ArrayAccessor
ArrayAccessor()
Constructs empty 2-D array accessor.
jet::ConstArrayAccessor< T, 2 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::ArrayAccessor< T, 2 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::ConstArrayAccessor< T, 2 >::data
const T *const data() const
Returns the raw pointer to the array data.
jet::ArrayAccessor< T, 2 >::ArrayAccessor
ArrayAccessor(size_t width, size_t height, T *const data)
jet::ArrayAccessor< T, 2 >::reset
void reset(size_t width, size_t height, T *const data)
Resets the array.
jet::ConstArrayAccessor< T, 2 >::ConstArrayAccessor
ConstArrayAccessor(const Size2 &size, const T *const data)
jet::ArrayAccessor< T, 2 >::index
size_t index(const Point2UI &pt) const
Returns the linear index of the given 2-D coordinate (pt.x, pt.y).
jet::Size2
2-D size class.
Definition: size2.h:19
jet::ArrayAccessor< T, 2 >::end
T * end()
Returns the end iterator of the array.
jet::ArrayAccessor< T, 2 >
2-D array accessor class.
Definition: array_accessor2.h:31
jet::ArrayAccessor< T, 2 >::data
T *const data() const
Returns the raw pointer to the array data.
jet::ConstArrayAccessor< T, 2 >::index
size_t index(const Point2UI &pt) const
Returns the linear index of the given 2-D coordinate (pt.x, pt.y).
jet::ArrayAccessor< T, 2 >::begin
T *const begin() const
Returns the begin iterator of the array.
jet::ArrayAccessor< T, 2 >::operator()
const T & operator()(const Point2UI &pt) const
Returns the const reference to the element at (pt.x, pt.y).
jet::ConstArrayAccessor< T, 2 >::index
size_t index(size_t i, size_t j) const
Returns the linear index of the given 2-D coordinate (i, j).
jet::ConstArrayAccessor< T, 2 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each index.
jet::ArrayAccessor< T, 2 >::at
T & at(size_t i, size_t j)
Returns the reference to the element at (i, j).
jet::ConstArrayAccessor< T, 2 >::begin
const T *const begin() const
Returns the begin iterator of the array.
jet::ArrayAccessor< T, 2 >::operator[]
T & operator[](size_t i)
Returns the reference to the i-th element.
jet::ArrayAccessor< T, 2 >::ArrayAccessor
ArrayAccessor(const Size2 &size, T *const data)
jet::ArrayAccessor< T, 2 >::operator()
T & operator()(size_t i, size_t j)
Returns the reference to the element at (i, j).
jet::ArrayAccessor< T, 2 >::at
const T & at(const Point2UI &pt) const
Returns the const reference to the element at (pt.x, pt.y).
jet::ConstArrayAccessor< T, 2 >::size
Size2 size() const
Returns the size of the array.
jet::ArrayAccessor< T, 2 >::operator()
T & operator()(const Point2UI &pt)
Returns the reference to the element at (pt.x, pt.y).
jet::ArrayAccessor< T, 2 >::parallelForEach
void parallelForEach(Callback func)
Iterates the array and invoke given func for each index in parallel.
jet::ArrayAccessor< T, 2 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each index.
jet::ArrayAccessor
Generic N-dimensional array accessor class interface.
Definition: array_accessor.h:29
point2.h
jet::ArrayAccessor< T, 2 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to the i-th element.