ArrayAccessor3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ArrayAccessor3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D array accessor class.
6 > Created Time: 2017/01/28
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_ARRAY_ACCESSOR3_H
10 #define CUBBYFLOW_ARRAY_ACCESSOR3_H
11 
13 #include <Core/Size/Size3.h>
14 
15 namespace CubbyFlow
16 {
30  template <typename T>
31  class ArrayAccessor<T, 3> final {
32  public:
34  ArrayAccessor();
35 
39  ArrayAccessor(const Size3& size, T* const data);
40 
47  size_t width, size_t height, size_t depth, T* const data);
48 
50  ArrayAccessor(const ArrayAccessor& other);
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 
244  ArrayAccessor& operator=(const ArrayAccessor& other);
245 
247  operator ConstArrayAccessor<T, 3>() const;
248 
249  private:
250  Size3 m_size;
251  T* m_data;
252  };
253 
255  template <typename T> using ArrayAccessor3 = ArrayAccessor<T, 3>;
256 
268  template <typename T>
269  class ConstArrayAccessor<T, 3> {
270  public:
273 
277  ConstArrayAccessor(const Size3& size, const T* const data);
278 
285  size_t width, size_t height, size_t depth, const T* const data);
286 
288  explicit ConstArrayAccessor(const ArrayAccessor<T, 3>& other);
289 
292 
294  const T& At(size_t i) const;
295 
297  const T& At(const Point3UI& pt) const;
298 
300  const T& At(size_t i, size_t j, size_t k) const;
301 
303  const T* const begin() const;
304 
306  const T* const end() const;
307 
309  Size3 size() const;
310 
312  size_t Width() const;
313 
315  size_t Height() const;
316 
318  size_t Depth() const;
319 
321  const T* const data() const;
322 
353  template <typename Callback>
354  void ForEach(Callback func) const;
355 
386  template <typename Callback>
387  void ForEachIndex(Callback func) const;
388 
407  template <typename Callback>
408  void ParallelForEachIndex(Callback func) const;
409 
411  size_t Index(const Point3UI& pt) const;
412 
414  size_t Index(size_t i, size_t j, size_t k) const;
415 
417  const T& operator[](size_t i) const;
418 
420  const T& operator()(const Point3UI& pt) const;
421 
423  const T& operator()(size_t i, size_t j, size_t k) const;
424 
425  private:
426  Size3 m_size;
427  const T* m_data;
428  };
429 
431  template <typename T> using ConstArrayAccessor3 = ConstArrayAccessor<T, 3>;
432 }
433 
435 
436 #endif
3-D array accessor class.
Definition: ArrayAccessor3.h:31
3-D read-only array accessor class.
Definition: ArrayAccessor3.h:269
3-D point class.
Definition: Point3.h:26
Generic N-dimensional array accessor class interface.
Definition: ArrayAccessor.h:31
Definition: pybind11Utils.h:24
Generic N-dimensional read-only array accessor class interface.
Definition: ArrayAccessor.h:52