Jet  v1.3.3
array3.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_ARRAY3_H_
8 #define INCLUDE_JET_ARRAY3_H_
9 
10 #include <jet/array.h>
11 #include <jet/array_accessor3.h>
12 
13 #include <fstream>
14 #include <functional>
15 #include <iostream>
16 #include <utility> // just make cpplint happy..
17 #include <vector>
18 
19 namespace jet {
20 
42 template <typename T>
43 class Array<T, 3> final {
44  public:
45  typedef std::vector<T> ContainerType;
46  typedef typename ContainerType::iterator Iterator;
47  typedef typename ContainerType::const_iterator ConstIterator;
48 
50  Array();
51 
55  explicit Array(const Size3& size, const T& initVal = T());
56 
63  explicit Array(size_t width, size_t height, size_t depth,
64  const T& initVal = T());
65 
87  Array(const std::initializer_list<
88  std::initializer_list<std::initializer_list<T>>>& lst);
89 
91  Array(const Array& other);
92 
94  Array(Array&& other);
95 
97  void set(const T& value);
98 
100  void set(const Array& other);
101 
123  void set(const std::initializer_list<
124  std::initializer_list<std::initializer_list<T>>>& lst);
125 
127  void clear();
128 
130  void resize(const Size3& size, const T& initVal = T());
131 
134  void resize(size_t width, size_t height, size_t depth,
135  const T& initVal = T());
136 
145  T& at(size_t i);
146 
155  const T& at(size_t i) const;
156 
158  T& at(const Point3UI& pt);
159 
161  const T& at(const Point3UI& pt) const;
162 
164  T& at(size_t i, size_t j, size_t k);
165 
167  const T& at(size_t i, size_t j, size_t k) const;
168 
170  Size3 size() const;
171 
173  size_t width() const;
174 
176  size_t height() const;
177 
179  size_t depth() const;
180 
182  T* data();
183 
186 
189 
192 
195 
197  const T* const data() const;
198 
201 
204 
206  void swap(Array& other);
207 
236  template <typename Callback>
237  void forEach(Callback func) const;
238 
267  template <typename Callback>
268  void forEachIndex(Callback func) const;
269 
289  template <typename Callback>
290  void parallelForEach(Callback func);
291 
309  template <typename Callback>
310  void parallelForEachIndex(Callback func) const;
311 
322  T& operator[](size_t i);
323 
334  const T& operator[](size_t i) const;
335 
337  T& operator()(const Point3UI& pt);
338 
340  const T& operator()(const Point3UI& pt) const;
341 
343  T& operator()(size_t i, size_t j, size_t k);
344 
346  const T& operator()(size_t i, size_t j, size_t k) const;
347 
349  Array& operator=(const T& value);
350 
352  Array& operator=(const Array& other);
353 
355  Array& operator=(Array&& other);
356 
378  Array& operator=(const std::initializer_list<
379  std::initializer_list<std::initializer_list<T>>>& lst);
380 
382  operator ArrayAccessor3<T>();
383 
385  operator ConstArrayAccessor3<T>() const;
386 
387  private:
388  Size3 _size;
389  std::vector<T> _data;
390 };
391 
393 template <typename T>
395 
396 } // namespace jet
397 
398 #include "detail/array3-inl.h"
399 
400 #endif // INCLUDE_JET_ARRAY3_H_
jet::ConstArrayAccessor< T, 3 >
3-D read-only array accessor class.
Definition: array_accessor3.h:270
jet::Array< T, 3 >::end
Iterator end()
Returns the end iterator of the array.
jet::Array< T, 3 >::end
ConstIterator end() const
Returns the end const iterator of the array.
jet::Array< T, 3 >::ContainerType
std::vector< T > ContainerType
Definition: array3.h:45
jet::Array< T, 3 >::width
size_t width() const
Returns the width of the array.
jet::Array< T, 3 >::at
const T & at(size_t i) const
Returns the const reference to the i-th element.
jet::Array< T, 3 >::at
const T & at(size_t i, size_t j, size_t k) const
Returns the const reference to the element at (i, j, k).
jet::Array< T, 3 >::operator=
Array & operator=(const T &value)
Sets entire array with given value.
jet::Array< T, 3 >::ConstIterator
ContainerType::const_iterator ConstIterator
Definition: array3.h:47
jet::Array< T, 3 >::parallelForEach
void parallelForEach(Callback func)
Iterates the array and invoke given func for each index in parallel.
jet::Array< T, 3 >::constAccessor
ConstArrayAccessor3< T > constAccessor() const
Returns the const array accessor.
jet::Array< T, 3 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each index.
jet::Array< T, 3 >::Array
Array(Array &&other)
Move constructor.
jet::Array< T, 3 >::operator()
T & operator()(size_t i, size_t j, size_t k)
Returns the reference to the element at (i, j, k).
jet::Array< T, 3 >::operator()
const T & operator()(const Point3UI &pt) const
Returns the const reference to the element at (pt.x, pt.y, pt.z).
jet::Array< T, 3 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::Array< T, 3 >::depth
size_t depth() const
Returns the depth of the array.
array.h
jet::Array< T, 3 >::data
T * data()
Returns the raw pointer to the array data.
jet::Array< T, 3 >::Array
Array()
Constructs zero-sized 3-D array.
jet
Definition: advection_solver2.h:18
jet::Array< T, 3 >::operator=
Array & operator=(Array &&other)
Move assignment.
jet::Array< T, 3 >::size
Size3 size() const
Returns the size of the array.
jet::Array< T, 3 >::at
T & at(size_t i, size_t j, size_t k)
Returns the reference to the element at (i, j, k).
jet::Array< T, 3 >::set
void set(const T &value)
Sets entire array with given value.
jet::Array< T, 3 >::set
void set(const Array &other)
Copies given array other to this array.
jet::Array< T, 3 >::Iterator
ContainerType::iterator Iterator
Definition: array3.h:46
jet::Array< T, 3 >::Array
Array(const Size3 &size, const T &initVal=T())
jet::Array< T, 3 >::operator[]
T & operator[](size_t i)
Returns the reference to the i-th element.
jet::Array< T, 3 >::Array
Array(size_t width, size_t height, size_t depth, const T &initVal=T())
jet::Array< T, 3 >::swap
void swap(Array &other)
Swaps the content of the array with other array.
jet::Size3
3-D size class.
Definition: size3.h:19
jet::Array< T, 3 >::operator()
T & operator()(const Point3UI &pt)
Returns the reference to the element at (pt.x, pt.y, pt.z).
jet::Array< T, 3 >::accessor
ArrayAccessor3< T > accessor()
Returns the array accessor.
jet::Array< T, 3 >::begin
ConstIterator begin() const
Returns the begin const iterator of the array.
jet::Point< T, 3 >
3-D point class.
Definition: point3.h:23
jet::Array< T, 3 >::at
T & at(size_t i)
Returns the reference to the i-th element.
jet::Array< T, 3 >::resize
void resize(size_t width, size_t height, size_t depth, const T &initVal=T())
jet::ArrayAccessor< T, 3 >
3-D array accessor class.
Definition: array_accessor3.h:31
jet::Array< T, 3 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::Array< T, 3 >::Array
Array(const Array &other)
Copy constructor.
jet::Array< T, 3 >::at
T & at(const Point3UI &pt)
Returns the reference to the element at (pt.x, pt.y, pt.z).
jet::Array< T, 3 >::clear
void clear()
Clears the array and resizes to zero.
array_accessor3.h
jet::Array
Generic N-dimensional array class interface.
Definition: array.h:26
jet::Array< T, 3 >::height
size_t height() const
Returns the height of the array.
jet::Array< T, 3 >::data
const T *const data() const
Returns the const raw pointer to the array data.
jet::Array< T, 3 >::begin
Iterator begin()
Returns the begin iterator of the array.
jet::Array< T, 3 >::operator()
const T & operator()(size_t i, size_t j, size_t k) const
Returns the const reference to the element at (i, j, k).
jet::Array< T, 3 >::Array
Array(const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &lst)
Constructs 3-D array with given initializer list lst.
jet::Array< T, 3 >::operator=
Array & operator=(const Array &other)
Copies given array other to this array.
jet::Array< T, 3 >::set
void set(const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &lst)
jet::Array< T, 3 >
3-D array class.
Definition: array3.h:43
jet::Array< T, 3 >::operator=
Array & operator=(const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &lst)
jet::Array< T, 3 >::at
const T & at(const Point3UI &pt) const
Returns the const reference to the element at (pt.x, pt.y, pt.z).
jet::Array< T, 3 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to the i-th element.
jet::Array< T, 3 >::resize
void resize(const Size3 &size, const T &initVal=T())
Resizes the array with size and fill the new element with initVal.