Jet  v1.3.3
array_accessor3.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_ACCESSOR3_H_
8 #define INCLUDE_JET_ARRAY_ACCESSOR3_H_
9 
10 #include <jet/array_accessor.h>
11 #include <jet/point3.h>
12 #include <jet/size3.h>
13 #include <utility> // just make cpplint happy..
14 
15 namespace jet {
16 
30 template <typename T>
31 class ArrayAccessor<T, 3> final {
32  public:
35 
39  ArrayAccessor(const Size3& size, T* const data);
40 
47  size_t width, size_t height, size_t depth, T* const data);
48 
51 
53  void set(const ArrayAccessor& other);
54 
56  void reset(const Size3& size, T* const data);
57 
59  void reset(size_t width, size_t height, size_t depth, T* const data);
60 
62  T& at(size_t i);
63 
65  const T& at(size_t i) const;
66 
68  T& at(const Point3UI& pt);
69 
71  const T& at(const Point3UI& pt) const;
72 
74  T& at(size_t i, size_t j, size_t k);
75 
77  const T& at(size_t i, size_t j, size_t k) const;
78 
80  T* const begin() const;
81 
83  T* const end() const;
84 
86  T* begin();
87 
89  T* end();
90 
92  Size3 size() const;
93 
95  size_t width() const;
96 
98  size_t height() const;
99 
101  size_t depth() const;
102 
104  T* const data() const;
105 
107  void swap(ArrayAccessor& other);
108 
139  template <typename Callback>
140  void forEach(Callback func) const;
141 
172  template <typename Callback>
173  void forEachIndex(Callback func) const;
174 
195  template <typename Callback>
196  void parallelForEach(Callback func);
197 
216  template <typename Callback>
217  void parallelForEachIndex(Callback func) const;
218 
220  size_t index(const Point3UI& pt) const;
221 
223  size_t index(size_t i, size_t j, size_t k) const;
224 
226  T& operator[](size_t i);
227 
229  const T& operator[](size_t i) const;
230 
232  T& operator()(const Point3UI& pt);
233 
235  const T& operator()(const Point3UI& pt) const;
236 
238  T& operator()(size_t i, size_t j, size_t k);
239 
241  const T& operator()(size_t i, size_t j, size_t k) const;
242 
245 
247  operator ConstArrayAccessor<T, 3>() const;
248 
249  private:
250  Size3 _size;
251  T* _data;
252 };
253 
255 template <typename T> using ArrayAccessor3 = ArrayAccessor<T, 3>;
256 
257 
269 template <typename T>
270 class ConstArrayAccessor<T, 3> {
271  public:
274 
278  ConstArrayAccessor(const Size3& size, const T* const data);
279 
286  size_t width, size_t height, size_t depth, const T* const data);
287 
289  explicit ConstArrayAccessor(const ArrayAccessor<T, 3>& other);
290 
293 
295  const T& at(size_t i) const;
296 
298  const T& at(const Point3UI& pt) const;
299 
301  const T& at(size_t i, size_t j, size_t k) const;
302 
304  const T* const begin() const;
305 
307  const T* const end() const;
308 
310  Size3 size() const;
311 
313  size_t width() const;
314 
316  size_t height() const;
317 
319  size_t depth() const;
320 
322  const T* const data() const;
323 
354  template <typename Callback>
355  void forEach(Callback func) const;
356 
387  template <typename Callback>
388  void forEachIndex(Callback func) const;
389 
408  template <typename Callback>
409  void parallelForEachIndex(Callback func) const;
410 
412  size_t index(const Point3UI& pt) const;
413 
415  size_t index(size_t i, size_t j, size_t k) const;
416 
418  const T& operator[](size_t i) const;
419 
421  const T& operator()(const Point3UI& pt) const;
422 
424  const T& operator()(size_t i, size_t j, size_t k) const;
425 
426  private:
427  Size3 _size;
428  const T* _data;
429 };
430 
432 template <typename T> using ConstArrayAccessor3 = ConstArrayAccessor<T, 3>;
433 
434 } // namespace jet
435 
436 #include "detail/array_accessor3-inl.h"
437 
438 #endif // INCLUDE_JET_ARRAY_ACCESSOR3_H_
jet::ArrayAccessor< T, 3 >::begin
T * begin()
Returns the begin iterator of the array.
jet::ConstArrayAccessor< T, 3 >
3-D read-only array accessor class.
Definition: array_accessor3.h:270
jet::ConstArrayAccessor< T, 3 >::height
size_t height() const
Returns the height of the array.
jet::ConstArrayAccessor< T, 3 >::begin
const T *const begin() const
Returns the begin iterator of the array.
jet::ArrayAccessor< T, 3 >::at
T & at(const Point3UI &pt)
Returns the reference to the element at (pt.x, pt.y, pt.z).
jet::ConstArrayAccessor< T, 3 >::depth
size_t depth() const
Returns the depth of the array.
jet::ArrayAccessor< T, 3 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::ArrayAccessor< T, 3 >::at
T & at(size_t i)
Returns the reference to the i-th element.
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor
ConstArrayAccessor(const Size3 &size, const T *const data)
jet::ArrayAccessor< T, 3 >::width
size_t width() const
Returns the width of the array.
jet::ArrayAccessor< T, 3 >::begin
T *const begin() const
Returns the begin iterator of the array.
jet::ArrayAccessor< T, 3 >::swap
void swap(ArrayAccessor &other)
Swaps the content of with other array accessor.
size3.h
jet::ConstArrayAccessor< T, 3 >::operator()
const T & operator()(const Point3UI &pt) const
Returns the const reference to the element at (pt.x, pt.y, pt.z).
jet::ConstArrayAccessor< T, 3 >::index
size_t index(size_t i, size_t j, size_t k) const
Returns the linear index of the given =3-D coordinate (i, j, k).
jet::ConstArrayAccessor< T, 3 >::width
size_t width() const
Returns the width of the array.
jet::ConstArrayAccessor< T, 3 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to the i-th element.
jet::ArrayAccessor< T, 3 >::at
const T & at(size_t i, size_t j, size_t k) const
Returns the const reference to the element at (i, j, k).
jet::ConstArrayAccessor< T, 3 >::at
const T & at(size_t i) const
Returns the const reference to the i-th element.
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor
ConstArrayAccessor(const ConstArrayAccessor &other)
Copy constructor.
jet::ConstArrayAccessor< T, 3 >::end
const T *const end() const
Returns the end iterator of the array.
jet::ArrayAccessor< T, 3 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor
ConstArrayAccessor()
Constructs empty 3-D read-only array accessor.
jet::ArrayAccessor< T, 3 >::operator()
T & operator()(const Point3UI &pt)
Returns the reference to the element at (pt.x, pt.y, pt.z).
array_accessor.h
point3.h
jet
Definition: advection_solver2.h:18
jet::ConstArrayAccessor< T, 3 >::index
size_t index(const Point3UI &pt) const
Returns the linear index of the given 3-D coordinate (pt.x, pt.y, pt.z).
jet::ArrayAccessor< T, 3 >::height
size_t height() const
Returns the height of the array.
jet::ArrayAccessor< T, 3 >::end
T * end()
Returns the end iterator of the array.
jet::ConstArrayAccessor
Generic N-dimensional read-only array accessor class interface.
Definition: array_accessor.h:47
jet::ArrayAccessor< T, 3 >::operator()
const T & operator()(const Point3UI &pt) const
Returns the const reference to the element at (pt.x, pt.y, pt.z).
jet::ConstArrayAccessor< T, 3 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::ArrayAccessor< T, 3 >::end
T *const end() const
Returns the end iterator of the array.
jet::ConstArrayAccessor< T, 3 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::Size3
3-D size class.
Definition: size3.h:19
jet::ArrayAccessor< T, 3 >::parallelForEach
void parallelForEach(Callback func)
Iterates the array and invoke given func for each index in parallel.
jet::ArrayAccessor< T, 3 >::operator[]
T & operator[](size_t i)
Returns the reference to the i-th element.
jet::Point< T, 3 >
3-D point class.
Definition: point3.h:23
jet::ArrayAccessor< T, 3 >
3-D array accessor class.
Definition: array_accessor3.h:31
jet::ConstArrayAccessor< T, 3 >::data
const T *const data() const
Returns the raw pointer to the array data.
jet::ArrayAccessor< T, 3 >::data
T *const data() const
Returns the raw pointer to the array data.
jet::ArrayAccessor< T, 3 >::reset
void reset(size_t width, size_t height, size_t depth, T *const data)
Resets the array.
jet::ArrayAccessor< T, 3 >::index
size_t index(size_t i, size_t j, size_t k) const
Returns the linear index of the given =3-D coordinate (i, j, k).
jet::ArrayAccessor< T, 3 >::index
size_t index(const Point3UI &pt) const
Returns the linear index of the given 3-D coordinate (pt.x, pt.y, pt.z).
jet::ConstArrayAccessor< T, 3 >::at
const T & at(const Point3UI &pt) const
Returns the const reference to the element at (pt.x, pt.y, pt.z).
jet::ArrayAccessor< T, 3 >::at
T & at(size_t i, size_t j, size_t k)
Returns the reference to the element at (i, j, k).
jet::ArrayAccessor< T, 3 >::at
const T & at(const Point3UI &pt) const
Returns the const reference to the element at (pt.x, pt.y, pt.z).
jet::ArrayAccessor< T, 3 >::ArrayAccessor
ArrayAccessor(const Size3 &size, T *const data)
jet::ArrayAccessor< T, 3 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each index.
jet::ArrayAccessor< T, 3 >::at
const T & at(size_t i) const
Returns the const reference to the i-th element.
jet::ArrayAccessor< T, 3 >::operator()
T & operator()(size_t i, size_t j, size_t k)
Returns the reference to the element at (i, j, k).
jet::ArrayAccessor< T, 3 >::ArrayAccessor
ArrayAccessor()
Constructs empty 3-D array accessor.
jet::ArrayAccessor< T, 3 >::ArrayAccessor
ArrayAccessor(size_t width, size_t height, size_t depth, T *const data)
jet::ConstArrayAccessor< T, 3 >::operator()
const T & operator()(size_t i, size_t j, size_t k) const
Returns the reference to the element at (i, j, k).
jet::ConstArrayAccessor< T, 3 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each index.
jet::ArrayAccessor< T, 3 >::size
Size3 size() const
Returns the size of the array.
jet::ArrayAccessor< T, 3 >::depth
size_t depth() const
Returns the depth of the array.
jet::ConstArrayAccessor< T, 3 >::at
const T & at(size_t i, size_t j, size_t k) const
Returns the const reference to the element at (i, j, k).
jet::ArrayAccessor< T, 3 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to the i-th element.
jet::ArrayAccessor< T, 3 >::operator()
const T & operator()(size_t i, size_t j, size_t k) const
Returns the const reference to the element at (i, j, k).
jet::ArrayAccessor< T, 3 >::operator=
ArrayAccessor & operator=(const ArrayAccessor &other)
Copies given array other to this array.
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor
ConstArrayAccessor(size_t width, size_t height, size_t depth, const T *const data)
jet::ConstArrayAccessor< T, 3 >::size
Size3 size() const
Returns the size of the array.
jet::ArrayAccessor< T, 3 >::set
void set(const ArrayAccessor &other)
Replaces the content with given other array accessor.
jet::ArrayAccessor< T, 3 >::ArrayAccessor
ArrayAccessor(const ArrayAccessor &other)
Copy constructor.
jet::ConstArrayAccessor< T, 3 >::ConstArrayAccessor
ConstArrayAccessor(const ArrayAccessor< T, 3 > &other)
Constructs a read-only array accessor from read/write accessor.
jet::ArrayAccessor
Generic N-dimensional array accessor class interface.
Definition: array_accessor.h:29
jet::ArrayAccessor< T, 3 >::reset
void reset(const Size3 &size, T *const data)
Resets the array.