Array3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Array3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D array class.
6 > Created Time: 2017/01/24
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_ARRAY3_H
10 #define CUBBYFLOW_ARRAY3_H
11 
12 #include <Core/Array/Array.h>
14 #include <Core/Size/Size3.h>
15 
16 #include <vector>
17 
18 namespace CubbyFlow
19 {
44  template <typename T>
45  class Array<T, 3> final
46  {
47  public:
48  using ContainerType = std::vector<T>;
49  using Iterator = typename ContainerType::iterator;
50  using ConstIterator = typename ContainerType::const_iterator;
51 
53  Array();
54 
58  explicit Array(const Size3& size, const T& initVal = T());
59 
66  explicit Array(size_t width, size_t height, size_t depth, const T& initVal = T());
67 
95  Array(const std::initializer_list<std::initializer_list<std::initializer_list<T>>>& list);
96 
98  Array(const Array& other);
99 
101  Array(Array&& other);
102 
104  void Set(const T& value);
105 
107  void Set(const Array& other);
108 
136  void Set(const std::initializer_list<std::initializer_list<std::initializer_list<T>>>& list);
137 
139  void Clear();
140 
142  void Resize(const Size3& size, const T& initVal = T());
143 
146  void Resize(size_t width, size_t height, size_t depth, const T& initVal = T());
147 
156  T& At(size_t i);
157 
166  const T& At(size_t i) const;
167 
169  T& At(const Point3UI& pt);
170 
172  const T& At(const Point3UI& pt) const;
173 
175  T& At(size_t i, size_t j, size_t k);
176 
178  const T& At(size_t i, size_t j, size_t k) const;
179 
181  Size3 size() const;
182 
184  size_t Width() const;
185 
187  size_t Height() const;
188 
190  size_t Depth() const;
191 
193  T* data();
194 
196  Iterator begin();
197 
199  ConstIterator begin() const;
200 
202  Iterator end();
203 
205  ConstIterator end() const;
206 
208  const T* const data() const;
209 
211  ArrayAccessor3<T> Accessor();
212 
214  ConstArrayAccessor3<T> ConstAccessor() const;
215 
217  void Swap(Array& other);
218 
251  template <typename Callback>
252  void ForEach(Callback func) const;
253 
286  template <typename Callback>
287  void ForEachIndex(Callback func) const;
288 
309  template <typename Callback>
310  void ParallelForEach(Callback func);
311 
330  template <typename Callback>
331  void ParallelForEachIndex(Callback func) const;
332 
343  T& operator[](size_t i);
344 
355  const T& operator[](size_t i) const;
356 
358  T& operator()(const Point3UI& pt);
359 
361  const T& operator()(const Point3UI& pt) const;
362 
364  T& operator()(size_t i, size_t j, size_t k);
365 
367  const T& operator()(size_t i, size_t j, size_t k) const;
368 
370  Array& operator=(const T& value);
371 
373  Array& operator=(const Array& other);
374 
376  Array& operator=(Array&& other);
377 
405  Array& operator=(const std::initializer_list<std::initializer_list<std::initializer_list<T>>>& list);
406 
408  operator ArrayAccessor3<T>();
409 
411  operator ConstArrayAccessor3<T>() const;
412 
413  private:
414  Size3 m_size;
415  std::vector<T> m_data;
416  };
417 
419  template <typename T>
421 }
422 
423 #include <Core/Array/Array3-Impl.h>
424 
425 #endif
3-D array accessor class.
Definition: ArrayAccessor3.h:31
3-D read-only array accessor class.
Definition: ArrayAccessor3.h:269
typename ContainerType::iterator Iterator
Definition: Array3.h:49
3-D point class.
Definition: Point3.h:26
Definition: pybind11Utils.h:24
Generic N-dimensional array class interface.
Definition: Array.h:28
3-D array class.
Definition: Array3.h:45
typename ContainerType::const_iterator ConstIterator
Definition: Array3.h:50
std::vector< T > ContainerType
Definition: Array3.h:48