ArrayAccessor2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ArrayAccessor2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D array accessor class.
6 > Created Time: 2017/01/28
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_ARRAY_ACCESSOR2_H
10 #define CUBBYFLOW_ARRAY_ACCESSOR2_H
11 
13 #include <Core/Size/Size2.h>
14 
15 namespace CubbyFlow
16 {
30  template <typename T>
31  class ArrayAccessor<T, 2> final
32  {
33  public:
35  ArrayAccessor();
36 
40  ArrayAccessor(const Size2& size, T* const data);
41 
46  ArrayAccessor(size_t width, size_t height, T* const data);
47 
49  ArrayAccessor(const ArrayAccessor& other);
50 
52  void Set(const ArrayAccessor& other);
53 
55  void Reset(const Size2& size, T* const data);
56 
58  void Reset(size_t width, size_t height, T* const data);
59 
61  T& At(size_t i);
62 
64  const T& At(size_t i) const;
65 
67  T& At(const Point2UI& pt);
68 
70  const T& At(const Point2UI& pt) const;
71 
73  T& At(size_t i, size_t j);
74 
76  const T& At(size_t i, size_t j) const;
77 
79  T* const begin() const;
80 
82  T* const end() const;
83 
85  T* begin();
86 
88  T* end();
89 
91  Size2 size() const;
92 
94  size_t Width() const;
95 
97  size_t Height() const;
98 
100  T* const data() const;
101 
103  void Swap(ArrayAccessor& other);
104 
133  template <typename Callback>
134  void ForEach(Callback func) const;
135 
164  template <typename Callback>
165  void ForEachIndex(Callback func) const;
166 
187  template <typename Callback>
188  void ParallelForEach(Callback func);
189 
208  template <typename Callback>
209  void ParallelForEachIndex(Callback func) const;
210 
212  size_t Index(const Point2UI& pt) const;
213 
215  size_t Index(size_t i, size_t j) const;
216 
218  T& operator[](size_t i);
219 
221  const T& operator[](size_t i) const;
222 
224  T& operator()(const Point2UI& pt);
225 
227  const T& operator()(const Point2UI& pt) const;
228 
230  T& operator()(size_t i, size_t j);
231 
233  const T& operator()(size_t i, size_t j) const;
234 
236  ArrayAccessor& operator=(const ArrayAccessor& other);
237 
239  operator ConstArrayAccessor<T, 2>() const;
240 
241  private:
242  Size2 m_size;
243  T* m_data;
244  };
245 
247  template <typename T> using ArrayAccessor2 = ArrayAccessor<T, 2>;
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 m_size;
411  const T* m_data;
412  };
413 
415  template <typename T> using ConstArrayAccessor2 = ConstArrayAccessor<T, 2>;
416 }
417 
419 
420 #endif
2-D read-only array accessor class.
Definition: ArrayAccessor2.h:261
2-D point class.
Definition: Point2.h:25
2-D array accessor class.
Definition: ArrayAccessor2.h:31
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