Array2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Array2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D array class.
6 > Created Time: 2017/01/24
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_ARRAY2_H
10 #define CUBBYFLOW_ARRAY2_H
11 
12 #include <Core/Array/Array.h>
14 #include <Core/Size/Size2.h>
15 
16 #include <vector>
17 
18 namespace CubbyFlow
19 {
41  template <typename T>
42  class Array<T, 2> final
43  {
44  public:
45  using ContainerType = std::vector<T>;
46  using Iterator = typename ContainerType::iterator;
47  using ConstIterator = typename ContainerType::const_iterator;
48 
50  Array();
51 
55  explicit Array(const Size2& size, const T& initVal = T());
56 
62  Array(size_t width, size_t height, const T& initVal = T());
63 
83  Array(const std::initializer_list<std::initializer_list<T>>& list);
84 
86  Array(const Array& other);
87 
89  Array(Array&& other);
90 
92  void Set(const T& value);
93 
95  void Set(const Array& other);
96 
116  void Set(const std::initializer_list<std::initializer_list<T>>& list);
117 
119  void Clear();
120 
122  void Resize(const Size2& size, const T& initVal = T());
123 
126  void Resize(size_t width, size_t height, const T& initVal = T());
127 
135  T& At(size_t i);
136 
144  const T& At(size_t i) const;
145 
147  T& At(const Point2UI& pt);
148 
150  const T& At(const Point2UI& pt) const;
151 
153  T& At(size_t i, size_t j);
154 
156  const T& At(size_t i, size_t j) const;
157 
159  Size2 size() const;
160 
162  size_t Width() const;
163 
165  size_t Height() const;
166 
168  T* data();
169 
171  const T* data() const;
172 
174  Iterator begin();
175 
177  ConstIterator begin() const;
178 
180  Iterator end();
181 
183  ConstIterator end() const;
184 
186  ArrayAccessor2<T> Accessor();
187 
189  ConstArrayAccessor2<T> ConstAccessor() const;
190 
192  void Swap(Array& other);
193 
223  template <typename Callback>
224  void ForEach(Callback func) const;
225 
255  template <typename Callback>
256  void ForEachIndex(Callback func) const;
257 
278  template <typename Callback>
279  void ParallelForEach(Callback func);
280 
299  template <typename Callback>
300  void ParallelForEachIndex(Callback func) const;
301 
311  T& operator[](size_t i);
312 
322  const T& operator[](size_t i) const;
323 
325  T& operator()(const Point2UI& pt);
326 
328  const T& operator()(const Point2UI& pt) const;
329 
331  T& operator()(size_t i, size_t j);
332 
334  const T& operator()(size_t i, size_t j) const;
335 
337  Array& operator=(const T& other);
338 
340  Array& operator=(const Array& other);
341 
343  Array& operator=(Array&& other);
344 
364  Array& operator=(const std::initializer_list<std::initializer_list<T>>& list);
365 
367  operator ArrayAccessor2<T>();
368 
370  operator ConstArrayAccessor2<T>() const;
371 
372  private:
373  Size2 m_size;
374  std::vector<T> m_data;
375  };
376 
378  template <typename T>
380 }
381 
382 #include <Core/Array/Array2-Impl.h>
383 
384 #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
Definition: pybind11Utils.h:24
Generic N-dimensional array class interface.
Definition: Array.h:28
std::vector< T > ContainerType
Definition: Array2.h:45
typename ContainerType::iterator Iterator
Definition: Array2.h:46
typename ContainerType::const_iterator ConstIterator
Definition: Array2.h:47
2-D array class.
Definition: Array2.h:42