ArrayAccessor1.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ArrayAccessor1.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 1-D array accessor class.
6 > Created Time: 2017/01/27
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_ARRAY_ACCESSOR1_H
10 #define CUBBYFLOW_ARRAY_ACCESSOR1_H
11 
13 
14 namespace CubbyFlow
15 {
27  template <typename T>
28  class ArrayAccessor<T, 1> final
29  {
30  public:
32  ArrayAccessor();
33 
35  ArrayAccessor(size_t size, T* const data);
36 
38  ArrayAccessor(const ArrayAccessor& other);
39 
41  void Set(const ArrayAccessor& other);
42 
44  void Reset(size_t size, T* const data);
45 
47  T& At(size_t i);
48 
50  const T& At(size_t i) const;
51 
53  T* const begin() const;
54 
56  T* const end() const;
57 
59  T* begin();
60 
62  T* end();
63 
65  size_t size() const;
66 
68  T* const data() const;
69 
71  void Swap(ArrayAccessor& other);
72 
89  template <typename Callback>
90  void ForEach(Callback func) const;
91 
108  template <typename Callback>
109  void ForEachIndex(Callback func) const;
110 
132  template <typename Callback>
133  void ParallelForEach(Callback func);
134 
153  template <typename Callback>
154  void ParallelForEachIndex(Callback func) const;
155 
157  T& operator[](size_t i);
158 
160  const T& operator[](size_t i) const;
161 
163  ArrayAccessor& operator=(const ArrayAccessor& other);
164 
166  operator ConstArrayAccessor<T, 1>() const;
167 
168  private:
169  size_t m_size;
170  T* m_data;
171  };
172 
174  template <typename T> using ArrayAccessor1 = ArrayAccessor<T, 1>;
175 
184  template <typename T>
185  class ConstArrayAccessor<T, 1>
186  {
187  public:
190 
192  ConstArrayAccessor(size_t size, const T* const data);
193 
195  explicit ConstArrayAccessor(const ArrayAccessor<T, 1>& other);
196 
199 
201  const T& At(size_t i) const;
202 
204  const T* const begin() const;
205 
207  const T* const end() const;
208 
210  size_t size() const;
211 
213  const T* const data() const;
214 
231  template <typename Callback>
232  void ForEach(Callback func) const;
233 
250  template <typename Callback>
251  void ForEachIndex(Callback func) const;
252 
271  template <typename Callback>
272  void ParallelForEachIndex(Callback func) const;
273 
275  const T& operator[](size_t i) const;
276 
277  private:
278  size_t m_size;
279  const T* m_data;
280  };
281 
283  template <typename T> using ConstArrayAccessor1 = ConstArrayAccessor<T, 1>;
284 }
285 
287 
288 #endif
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
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
1-D array accessor class.
Definition: ArrayAccessor1.h:28