Jet  v1.3.3
array2.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_ARRAY2_H_
8 #define INCLUDE_JET_ARRAY2_H_
9 
10 #include <jet/array.h>
11 #include <jet/array_accessor2.h>
12 #include <jet/size2.h>
13 
14 #include <fstream>
15 #include <functional>
16 #include <iostream>
17 #include <utility> // just make cpplint happy..
18 #include <vector>
19 
20 namespace jet {
21 
41 template <typename T>
42 class Array<T, 2> final {
43  public:
44  typedef std::vector<T> ContainerType;
45  typedef typename ContainerType::iterator Iterator;
46  typedef typename ContainerType::const_iterator ConstIterator;
47 
49  Array();
50 
54  explicit Array(const Size2& size, const T& initVal = T());
55 
61  Array(size_t width, size_t height, const T& initVal = T());
62 
81  Array(const std::initializer_list<std::initializer_list<T>>& lst);
82 
84  Array(const Array& other);
85 
87  Array(Array&& other);
88 
90  void set(const T& value);
91 
93  void set(const Array& other);
94 
113  void set(const std::initializer_list<std::initializer_list<T>>& lst);
114 
116  void clear();
117 
119  void resize(const Size2& size, const T& initVal = T());
120 
123  void resize(size_t width, size_t height, const T& initVal = T());
124 
132  T& at(size_t i);
133 
141  const T& at(size_t i) const;
142 
144  T& at(const Point2UI& pt);
145 
147  const T& at(const Point2UI& pt) const;
148 
150  T& at(size_t i, size_t j);
151 
153  const T& at(size_t i, size_t j) const;
154 
156  Size2 size() const;
157 
159  size_t width() const;
160 
162  size_t height() const;
163 
165  T* data();
166 
168  const T* const data() const;
169 
172 
175 
178 
181 
184 
187 
189  void swap(Array& other);
190 
217  template <typename Callback>
218  void forEach(Callback func) const;
219 
246  template <typename Callback>
247  void forEachIndex(Callback func) const;
248 
268  template <typename Callback>
269  void parallelForEach(Callback func);
270 
288  template <typename Callback>
289  void parallelForEachIndex(Callback func) const;
290 
300  T& operator[](size_t i);
301 
311  const T& operator[](size_t i) const;
312 
314  T& operator()(const Point2UI& pt);
315 
317  const T& operator()(const Point2UI& pt) const;
318 
320  T& operator()(size_t i, size_t j);
321 
323  const T& operator()(size_t i, size_t j) const;
324 
326  Array& operator=(const T& other);
327 
329  Array& operator=(const Array& other);
330 
332  Array& operator=(Array&& other);
333 
353  const std::initializer_list<std::initializer_list<T>>& lst);
354 
356  operator ArrayAccessor2<T>();
357 
359  operator ConstArrayAccessor2<T>() const;
360 
361  private:
362  Size2 _size;
363  std::vector<T> _data;
364 };
365 
367 template <typename T>
369 
370 } // namespace jet
371 
372 #include "detail/array2-inl.h"
373 
374 #endif // INCLUDE_JET_ARRAY2_H_
jet::Point< T, 2 >
2-D point class.
Definition: point2.h:23
jet::Array< T, 2 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each index.
array_accessor2.h
jet::Array< T, 2 >::resize
void resize(size_t width, size_t height, const T &initVal=T())
jet::Array< T, 2 >::operator()
T & operator()(const Point2UI &pt)
Returns the reference to the element at (pt.x, pt.y).
jet::Array< T, 2 >::ConstIterator
ContainerType::const_iterator ConstIterator
Definition: array2.h:46
jet::Array< T, 2 >::data
const T *const data() const
Returns the const raw pointer to the array data.
jet::Array< T, 2 >::Array
Array(const Size2 &size, const T &initVal=T())
jet::Array< T, 2 >::constAccessor
ConstArrayAccessor2< T > constAccessor() const
Returns the const array accessor.
jet::Array< T, 2 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to the i-th element.
jet::Array< T, 2 >::at
T & at(size_t i)
Returns the reference to the i-th element.
jet::Array< T, 2 >::operator=
Array & operator=(Array &&other)
Move assignment.
size2.h
jet::Array< T, 2 >::clear
void clear()
Clears the array and resizes to zero.
jet::Array< T, 2 >::resize
void resize(const Size2 &size, const T &initVal=T())
Resizes the array with size and fill the new element with initVal.
jet::Array< T, 2 >::operator()
const T & operator()(const Point2UI &pt) const
Returns the const reference to the element at (pt.x, pt.y).
jet::Array< T, 2 >::at
T & at(const Point2UI &pt)
Returns the reference to the element at (pt.x, pt.y).
array.h
jet::Array< T, 2 >::height
size_t height() const
Returns the height of the array.
jet::Array< T, 2 >::set
void set(const std::initializer_list< std::initializer_list< T >> &lst)
jet::Array< T, 2 >::end
Iterator end()
Returns the end iterator of the array.
jet::Array< T, 2 >
2-D array class.
Definition: array2.h:42
jet::Array< T, 2 >::accessor
ArrayAccessor2< T > accessor()
Returns the array accessor.
jet::Array< T, 2 >::at
T & at(size_t i, size_t j)
Returns the reference to the element at (i, j).
jet
Definition: advection_solver2.h:18
jet::Array< T, 2 >::set
void set(const T &value)
Sets entire array with given value.
jet::Array< T, 2 >::size
Size2 size() const
Returns the size of the array.
jet::ConstArrayAccessor< T, 2 >
2-D read-only array accessor class.
Definition: array_accessor2.h:261
jet::Array< T, 2 >::end
ConstIterator end() const
Returns the end const iterator of the array.
jet::Array< T, 2 >::ContainerType
std::vector< T > ContainerType
Definition: array2.h:44
jet::Array< T, 2 >::at
const T & at(size_t i) const
Returns the const reference to the i-th element.
jet::Array< T, 2 >::begin
Iterator begin()
Returns the begin iterator of the array.
jet::Array< T, 2 >::begin
ConstIterator begin() const
Returns the begin const iterator of the array.
jet::Array< T, 2 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::Array< T, 2 >::Array
Array(const std::initializer_list< std::initializer_list< T >> &lst)
Constructs 2-D array with given initializer list lst.
jet::Size2
2-D size class.
Definition: size2.h:19
jet::ArrayAccessor< T, 2 >
2-D array accessor class.
Definition: array_accessor2.h:31
jet::Array< T, 2 >::operator=
Array & operator=(const Array &other)
Copies given array other to this array.
jet::Array< T, 2 >::operator=
Array & operator=(const std::initializer_list< std::initializer_list< T >> &lst)
jet::Array
Generic N-dimensional array class interface.
Definition: array.h:26
jet::Array< T, 2 >::at
const T & at(const Point2UI &pt) const
Returns the const reference to the element at (pt.x, pt.y).
jet::Array< T, 2 >::set
void set(const Array &other)
Copies given array other to this array.
jet::Array< T, 2 >::swap
void swap(Array &other)
Swaps the content of the array with other array.
jet::Array< T, 2 >::operator()
T & operator()(size_t i, size_t j)
Returns the reference to the element at (i, j).
jet::Array< T, 2 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::Array< T, 2 >::parallelForEach
void parallelForEach(Callback func)
Iterates the array and invoke given func for each index in parallel.
jet::Array< T, 2 >::operator[]
T & operator[](size_t i)
Returns the reference to the i-th element.
jet::Array< T, 2 >::Iterator
ContainerType::iterator Iterator
Definition: array2.h:45
jet::Array< T, 2 >::width
size_t width() const
Returns the width of the array.
jet::Array< T, 2 >::operator()
const T & operator()(size_t i, size_t j) const
Returns the const reference to the element at (i, j).
jet::Array< T, 2 >::Array
Array(Array &&other)
Move constructor.
jet::Array< T, 2 >::data
T * data()
Returns the raw pointer to the array data.
jet::Array< T, 2 >::at
const T & at(size_t i, size_t j) const
Returns the const reference to the element at (i, j).
jet::Array< T, 2 >::operator=
Array & operator=(const T &other)
Sets entire array with given value.
jet::Array< T, 2 >::Array
Array()
Constructs zero-sized 2-D array.
jet::Array< T, 2 >::Array
Array(size_t width, size_t height, const T &initVal=T())
jet::Array< T, 2 >::Array
Array(const Array &other)
Copy constructor.