Jet  v1.3.3
array_accessor1.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_ARRAY_ACCESSOR1_H_
8 #define INCLUDE_JET_ARRAY_ACCESSOR1_H_
9 
10 #include <jet/array_accessor.h>
11 #include <utility> // just make cpplint happy..
12 
13 namespace jet {
14 
26 template <typename T>
27 class ArrayAccessor<T, 1> final {
28  public:
31 
33  ArrayAccessor(size_t size, T* const data);
34 
37 
39  void set(const ArrayAccessor& other);
40 
42  void reset(size_t size, T* const data);
43 
45  T& at(size_t i);
46 
48  const T& at(size_t i) const;
49 
51  T* const begin() const;
52 
54  T* const end() const;
55 
57  T* begin();
58 
60  T* end();
61 
63  size_t size() const;
64 
66  T* const data() const;
67 
69  void swap(ArrayAccessor& other);
70 
87  template <typename Callback>
88  void forEach(Callback func) const;
89 
106  template <typename Callback>
107  void forEachIndex(Callback func) const;
108 
130  template <typename Callback>
131  void parallelForEach(Callback func);
132 
151  template <typename Callback>
152  void parallelForEachIndex(Callback func) const;
153 
155  T& operator[](size_t i);
156 
158  const T& operator[](size_t i) const;
159 
162 
164  operator ConstArrayAccessor<T, 1>() const;
165 
166  private:
167  size_t _size;
168  T* _data;
169 };
170 
172 template <typename T> using ArrayAccessor1 = ArrayAccessor<T, 1>;
173 
174 
183 template <typename T>
184 class ConstArrayAccessor<T, 1> {
185  public:
188 
190  ConstArrayAccessor(size_t size, const T* const data);
191 
193  explicit ConstArrayAccessor(const ArrayAccessor<T, 1>& other);
194 
197 
199  const T& at(size_t i) const;
200 
202  const T* const begin() const;
203 
205  const T* const end() const;
206 
208  size_t size() const;
209 
211  const T* const data() const;
212 
229  template <typename Callback>
230  void forEach(Callback func) const;
231 
248  template <typename Callback>
249  void forEachIndex(Callback func) const;
250 
269  template <typename Callback>
270  void parallelForEachIndex(Callback func) const;
271 
273  const T& operator[](size_t i) const;
274 
275  private:
276  size_t _size;
277  const T* _data;
278 };
279 
281 template <typename T> using ConstArrayAccessor1 = ConstArrayAccessor<T, 1>;
282 
283 } // namespace jet
284 
285 #include "detail/array_accessor1-inl.h"
286 
287 #endif // INCLUDE_JET_ARRAY_ACCESSOR1_H_
jet::ConstArrayAccessor< T, 1 >::ConstArrayAccessor
ConstArrayAccessor(const ArrayAccessor< T, 1 > &other)
Constructs a read-only array accessor from read/write accessor.
jet::ArrayAccessor< T, 1 >::operator=
ArrayAccessor & operator=(const ArrayAccessor &other)
Copies given array accessor other.
jet::ArrayAccessor< T, 1 >::end
T * end()
Returns the end iterator of the array.
jet::ConstArrayAccessor< T, 1 >
1-D read-only array accessor class.
Definition: array_accessor1.h:184
jet::ArrayAccessor< T, 1 >::ArrayAccessor
ArrayAccessor(const ArrayAccessor &other)
Copy constructor.
jet::ConstArrayAccessor< T, 1 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::ArrayAccessor< T, 1 >::at
const T & at(size_t i) const
Returns the const reference to the i-th element.
jet::ArrayAccessor< T, 1 >::data
T *const data() const
Returns the raw pointer to the array data.
jet::ArrayAccessor< T, 1 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to i-th element.
jet::ArrayAccessor< T, 1 >::reset
void reset(size_t size, T *const data)
Resets the array.
jet::ArrayAccessor< T, 1 >::ArrayAccessor
ArrayAccessor()
Constructs empty 1-D array accessor.
jet::ArrayAccessor< T, 1 >::end
T *const end() const
Returns the end iterator of the array.
jet::ConstArrayAccessor< T, 1 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::ArrayAccessor< T, 1 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::ConstArrayAccessor< T, 1 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to i-th element.
array_accessor.h
jet::ConstArrayAccessor< T, 1 >::ConstArrayAccessor
ConstArrayAccessor(const ConstArrayAccessor &other)
Copy constructor.
jet
Definition: advection_solver2.h:18
jet::ArrayAccessor< T, 1 >::size
size_t size() const
Returns size of the array.
jet::ConstArrayAccessor< T, 1 >::at
const T & at(size_t i) const
Returns the const reference to the i-th element.
jet::ConstArrayAccessor< T, 1 >::ConstArrayAccessor
ConstArrayAccessor()
Constructs empty 1-D array accessor.
jet::ConstArrayAccessor
Generic N-dimensional read-only array accessor class interface.
Definition: array_accessor.h:47
jet::ArrayAccessor< T, 1 >::at
T & at(size_t i)
Returns the reference to the i-th element.
jet::ArrayAccessor< T, 1 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each element.
jet::ConstArrayAccessor< T, 1 >::size
size_t size() const
Returns size of the array.
jet::ArrayAccessor< T, 1 >::swap
void swap(ArrayAccessor &other)
Swaps the content of with other array accessor.
jet::ArrayAccessor< T, 1 >::ArrayAccessor
ArrayAccessor(size_t size, T *const data)
Constructs an array accessor that wraps given array.
jet::ConstArrayAccessor< T, 1 >::data
const T *const data() const
Returns the raw pointer to the array data.
jet::ArrayAccessor< T, 1 >::set
void set(const ArrayAccessor &other)
Replaces the content with given other array accessor.
jet::ArrayAccessor< T, 1 >::parallelForEach
void parallelForEach(Callback func)
Iterates the array and invoke given func for each element in parallel using multi-threading.
jet::ArrayAccessor< T, 1 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::ConstArrayAccessor< T, 1 >::begin
const T *const begin() const
Returns the begin iterator of the array.
jet::ConstArrayAccessor< T, 1 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each element.
jet::ConstArrayAccessor< T, 1 >::end
const T *const end() const
Returns the end iterator of the array.
jet::ArrayAccessor< T, 1 >::begin
T *const begin() const
Returns the begin iterator of the array.
jet::ArrayAccessor< T, 1 >::operator[]
T & operator[](size_t i)
Returns the reference to i-th element.
jet::ArrayAccessor< T, 1 >
1-D array accessor class.
Definition: array_accessor1.h:27
jet::ArrayAccessor
Generic N-dimensional array accessor class interface.
Definition: array_accessor.h:29
jet::ArrayAccessor< T, 1 >::begin
T * begin()
Returns the begin iterator of the array.
jet::ConstArrayAccessor< T, 1 >::ConstArrayAccessor
ConstArrayAccessor(size_t size, const T *const data)
Constructs an read-only array accessor that wraps given array.