Jet  v1.3.3
array1.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_ARRAY1_H_
8 #define INCLUDE_JET_ARRAY1_H_
9 
10 #include <jet/array.h>
11 #include <jet/array_accessor1.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 
30 template <typename T>
31 class Array<T, 1> final {
32  public:
33  typedef std::vector<T> ContainerType;
34  typedef typename ContainerType::iterator Iterator;
35  typedef typename ContainerType::const_iterator ConstIterator;
36 
38  Array();
39 
43  explicit Array(size_t size, const T& initVal = T());
44 
57  Array(const std::initializer_list<T>& lst);
58 
60  Array(const Array& other);
61 
63  Array(Array&& other);
64 
66  void set(const T& value);
67 
69  void set(const Array& other);
70 
72  void set(const std::initializer_list<T>& lst);
73 
75  void clear();
76 
78  void resize(size_t size, const T& initVal = T());
79 
81  T& at(size_t i);
82 
84  const T& at(size_t i) const;
85 
87  size_t size() const;
88 
90  T* data();
91 
93  const T* const data() const;
94 
97 
100 
103 
106 
109 
112 
114  void swap(Array& other);
115 
117  void append(const T& newVal);
118 
120  void append(const Array& other);
121 
137  template <typename Callback>
138  void forEach(Callback func) const;
139 
155  template <typename Callback>
156  void forEachIndex(Callback func) const;
157 
178  template <typename Callback>
179  void parallelForEach(Callback func);
180 
198  template <typename Callback>
199  void parallelForEachIndex(Callback func) const;
200 
202  T& operator[](size_t i);
203 
205  const T& operator[](size_t i) const;
206 
208  Array& operator=(const T& other);
209 
211  Array& operator=(const Array& other);
212 
214  Array& operator=(Array&& other);
215 
217  Array& operator=(const std::initializer_list<T>& lst);
218 
220  operator ArrayAccessor1<T>();
221 
223  operator ConstArrayAccessor1<T>() const;
224 
225  private:
226  ContainerType _data;
227 };
228 
230 template <typename T>
232 
233 } // namespace jet
234 
235 #include "detail/array1-inl.h"
236 
237 #endif // INCLUDE_JET_ARRAY1_H_
jet::Array< T, 1 >::ContainerType
std::vector< T > ContainerType
Definition: array1.h:33
jet::Array< T, 1 >
1-D array class.
Definition: array1.h:31
jet::Array< T, 1 >::append
void append(const Array &other)
Appends other array at the end of the array.
jet::Array< T, 1 >::at
const T & at(size_t i) const
Returns the const reference to the i-th element.
jet::Array< T, 1 >::operator=
Array & operator=(const Array &other)
Copies given array other to this array.
jet::Array< T, 1 >::append
void append(const T &newVal)
Appends single value newVal at the end of the array.
jet::Array< T, 1 >::parallelForEachIndex
void parallelForEachIndex(Callback func) const
Iterates the array and invoke given func for each index in parallel using multi-threading.
jet::Array< T, 1 >::Array
Array(const std::initializer_list< T > &lst)
Constructs 1-D array with given initializer list lst.
jet::ConstArrayAccessor< T, 1 >
1-D read-only array accessor class.
Definition: array_accessor1.h:184
jet::Array< T, 1 >::Array
Array(const Array &other)
Copy constructor.
jet::Array< T, 1 >::end
Iterator end()
Returns the end iterator of the array.
jet::Array< T, 1 >::Array
Array(size_t size, const T &initVal=T())
jet::Array< T, 1 >::operator=
Array & operator=(const std::initializer_list< T > &lst)
Copies given initializer list lst to this array.
jet::Array< T, 1 >::constAccessor
ConstArrayAccessor1< T > constAccessor() const
Returns the const array accessor.
jet::Array< T, 1 >::Array
Array()
Constructs zero-sized 1-D array.
array.h
jet::Array< T, 1 >::Array
Array(Array &&other)
Move constructor.
jet::Array< T, 1 >::forEachIndex
void forEachIndex(Callback func) const
Iterates the array and invoke given func for each index.
jet::Array< T, 1 >::operator[]
T & operator[](size_t i)
Returns the reference to i-th element.
jet::Array< T, 1 >::size
size_t size() const
Returns size of the array.
jet
Definition: advection_solver2.h:18
jet::Array< T, 1 >::forEach
void forEach(Callback func) const
Iterates the array and invoke given func for each element.
jet::Array< T, 1 >::resize
void resize(size_t size, const T &initVal=T())
Resizes the array with size and fill the new element with initVal.
jet::Array< T, 1 >::operator=
Array & operator=(const T &other)
Sets entire array with given value.
jet::Array< T, 1 >::operator[]
const T & operator[](size_t i) const
Returns the const reference to i-th element.
jet::Array< T, 1 >::begin
ConstIterator begin() const
Returns the begin const iterator of the array.
jet::Array< T, 1 >::data
const T *const data() const
Returns the const raw pointer to the array data.
jet::Array< T, 1 >::ConstIterator
ContainerType::const_iterator ConstIterator
Definition: array1.h:35
jet::Array
Generic N-dimensional array class interface.
Definition: array.h:26
jet::Array< T, 1 >::Iterator
ContainerType::iterator Iterator
Definition: array1.h:34
jet::Array< T, 1 >::accessor
ArrayAccessor1< T > accessor()
Returns the array accessor.
array_accessor1.h
jet::Array< T, 1 >::swap
void swap(Array &other)
Swaps the content of the array with other array.
jet::Array< T, 1 >::clear
void clear()
Clears the array and resizes to zero.
jet::Array< T, 1 >::set
void set(const T &value)
Sets entire array with given value.
jet::Array< T, 1 >::set
void set(const Array &other)
Copies given array other to this array.
jet::Array< T, 1 >::operator=
Array & operator=(Array &&other)
Move assignment.
jet::Array< T, 1 >::parallelForEach
void parallelForEach(Callback func)
Iterates the array and invoke given func for each element in parallel using multi-threading.
jet::Array< T, 1 >::set
void set(const std::initializer_list< T > &lst)
Copies given initializer list lst to this array.
jet::Array< T, 1 >::at
T & at(size_t i)
Returns the reference to the i-th element.
jet::Array< T, 1 >::data
T * data()
Returns the raw pointer to the array data.
jet::ArrayAccessor< T, 1 >
1-D array accessor class.
Definition: array_accessor1.h:27
jet::Array< T, 1 >::end
ConstIterator end() const
Returns the end const iterator of the array.
jet::Array< T, 1 >::begin
Iterator begin()
Returns the begin iterator of the array.