Array1.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Array1.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 1-D array class.
6 > Created Time: 2017/01/23
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_ARRAY1_H
10 #define CUBBYFLOW_ARRAY1_H
11 
12 #include <Core/Array/Array.h>
14 
15 #include <vector>
16 
17 namespace CubbyFlow
18 {
28  template <typename T>
29  class Array<T, 1> final
30  {
31  public:
32  using ContainerType = std::vector<T>;
33  using Iterator = typename ContainerType::iterator;
34  using ConstIterator = typename ContainerType::const_iterator;
35 
37  Array();
38 
42  explicit Array(size_t size, const T& initVal = T());
43 
56  Array(const std::initializer_list<T>& list);
57 
59  Array(const Array& other);
60 
62  Array(Array&& other);
63 
65  void Set(const T& value);
66 
68  void Set(const Array& other);
69 
71  void Set(const std::initializer_list<T>& list);
72 
74  void Clear();
75 
77  void Resize(size_t size, const T& initVal = T());
78 
80  T& At(size_t i);
81 
83  const T& At(size_t i) const;
84 
86  size_t size() const;
87 
89  T* data();
90 
92  const T* data() const;
93 
95  Iterator begin();
96 
98  ConstIterator begin() const;
99 
101  Iterator end();
102 
104  ConstIterator end() const;
105 
107  ArrayAccessor1<T> Accessor();
108 
110  ConstArrayAccessor1<T> ConstAccessor() const;
111 
113  void Swap(Array& other);
114 
116  void Append(const T& newVal);
117 
119  void Append(const Array& other);
120 
137  template <typename Callback>
138  void ForEach(Callback func) const;
139 
156  template <typename Callback>
157  void ForEachIndex(Callback func) const;
158 
180  template <typename Callback>
181  void ParallelForEach(Callback func);
182 
201  template <typename Callback>
202  void ParallelForEachIndex(Callback func) const;
203 
205  T& operator[](size_t i);
206 
208  const T& operator[](size_t i) const;
209 
211  Array& operator=(const T& other);
212 
214  Array& operator=(const Array& other);
215 
217  Array& operator=(Array&& other);
218 
220  Array& operator=(const std::initializer_list<T>& list);
221 
223  operator ArrayAccessor1<T>();
224 
226  operator ConstArrayAccessor1<T>() const;
227 
228  private:
229  ContainerType m_data;
230  };
231 
233  template <typename T>
235 }
236 
237 #include <Core/Array/Array1-Impl.h>
238 
239 #endif
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
std::vector< T > ContainerType
Definition: Array1.h:32
1-D array class.
Definition: Array1.h:29
Definition: pybind11Utils.h:24
Generic N-dimensional array class interface.
Definition: Array.h:28
1-D array accessor class.
Definition: ArrayAccessor1.h:28
typename ContainerType::const_iterator ConstIterator
Definition: Array1.h:34
typename ContainerType::iterator Iterator
Definition: Array1.h:33