Jet  v1.3.3
Public Types | Public Member Functions | List of all members
jet::Array< T, 1 > Class Template Referencefinal

1-D array class. More...

#include <jet/array1.h>

Public Types

typedef std::vector< T > ContainerType
 
typedef ContainerType::iterator Iterator
 
typedef ContainerType::const_iterator ConstIterator
 

Public Member Functions

 Array ()
 Constructs zero-sized 1-D array. More...
 
 Array (size_t size, const T &initVal=T())
 
 Array (const std::initializer_list< T > &lst)
 Constructs 1-D array with given initializer list lst. More...
 
 Array (const Array &other)
 Copy constructor. More...
 
 Array (Array &&other)
 Move constructor. More...
 
void set (const T &value)
 Sets entire array with given value. More...
 
void set (const Array &other)
 Copies given array other to this array. More...
 
void set (const std::initializer_list< T > &lst)
 Copies given initializer list lst to this array. More...
 
void clear ()
 Clears the array and resizes to zero. More...
 
void resize (size_t size, const T &initVal=T())
 Resizes the array with size and fill the new element with initVal. More...
 
T & at (size_t i)
 Returns the reference to the i-th element. More...
 
const T & at (size_t i) const
 Returns the const reference to the i-th element. More...
 
size_t size () const
 Returns size of the array. More...
 
T * data ()
 Returns the raw pointer to the array data. More...
 
const T *const data () const
 Returns the const raw pointer to the array data. More...
 
Iterator begin ()
 Returns the begin iterator of the array. More...
 
ConstIterator begin () const
 Returns the begin const iterator of the array. More...
 
Iterator end ()
 Returns the end iterator of the array. More...
 
ConstIterator end () const
 Returns the end const iterator of the array. More...
 
ArrayAccessor1< T > accessor ()
 Returns the array accessor. More...
 
ConstArrayAccessor1< T > constAccessor () const
 Returns the const array accessor. More...
 
void swap (Array &other)
 Swaps the content of the array with other array. More...
 
void append (const T &newVal)
 Appends single value newVal at the end of the array. More...
 
void append (const Array &other)
 Appends other array at the end of the array. More...
 
template<typename Callback >
void forEach (Callback func) const
 Iterates the array and invoke given func for each element. More...
 
template<typename Callback >
void forEachIndex (Callback func) const
 Iterates the array and invoke given func for each index. More...
 
template<typename Callback >
void parallelForEach (Callback func)
 Iterates the array and invoke given func for each element in parallel using multi-threading. More...
 
template<typename Callback >
void parallelForEachIndex (Callback func) const
 Iterates the array and invoke given func for each index in parallel using multi-threading. More...
 
T & operator[] (size_t i)
 Returns the reference to i-th element. More...
 
const T & operator[] (size_t i) const
 Returns the const reference to i-th element. More...
 
Arrayoperator= (const T &other)
 Sets entire array with given value. More...
 
Arrayoperator= (const Array &other)
 Copies given array other to this array. More...
 
Arrayoperator= (Array &&other)
 Move assignment. More...
 
Arrayoperator= (const std::initializer_list< T > &lst)
 Copies given initializer list lst to this array. More...
 
 operator ArrayAccessor1< T > ()
 Casts to array accessor. More...
 
 operator ConstArrayAccessor1< T > () const
 Casts to const array accessor. More...
 

Detailed Description

template<typename T>
class jet::Array< T, 1 >

1-D array class.

This class represents 1-D array data structure. This class is a simple wrapper around std::vector with some additional features such as the array accessor object and parallel for-loop.

Template Parameters
T- Type to store in the array.

Member Typedef Documentation

◆ ConstIterator

template<typename T >
typedef ContainerType::const_iterator jet::Array< T, 1 >::ConstIterator

◆ ContainerType

template<typename T >
typedef std::vector<T> jet::Array< T, 1 >::ContainerType

◆ Iterator

template<typename T >
typedef ContainerType::iterator jet::Array< T, 1 >::Iterator

Constructor & Destructor Documentation

◆ Array() [1/5]

template<typename T >
jet::Array< T, 1 >::Array ( )

Constructs zero-sized 1-D array.

◆ Array() [2/5]

template<typename T >
jet::Array< T, 1 >::Array ( size_t  size,
const T &  initVal = T() 
)
explicit

Constructs 1-D array with given size and fill it with initVal.

Parameters
sizeInitial size of the array.
initValInitial value of each array element.

◆ Array() [3/5]

template<typename T >
jet::Array< T, 1 >::Array ( const std::initializer_list< T > &  lst)

Constructs 1-D array with given initializer list lst.

This constructor will build 1-D array with given initializer list lst such as

Array<int, 1> arr = {1, 2, 4, 9, 3};
Parameters
lstInitializer list that should be copy to the new array.

◆ Array() [4/5]

template<typename T >
jet::Array< T, 1 >::Array ( const Array< T, 1 > &  other)

Copy constructor.

◆ Array() [5/5]

template<typename T >
jet::Array< T, 1 >::Array ( Array< T, 1 > &&  other)

Move constructor.

Member Function Documentation

◆ accessor()

template<typename T >
ArrayAccessor1<T> jet::Array< T, 1 >::accessor ( )

Returns the array accessor.

◆ append() [1/2]

template<typename T >
void jet::Array< T, 1 >::append ( const Array< T, 1 > &  other)

Appends other array at the end of the array.

◆ append() [2/2]

template<typename T >
void jet::Array< T, 1 >::append ( const T &  newVal)

Appends single value newVal at the end of the array.

◆ at() [1/2]

template<typename T >
T& jet::Array< T, 1 >::at ( size_t  i)

Returns the reference to the i-th element.

◆ at() [2/2]

template<typename T >
const T& jet::Array< T, 1 >::at ( size_t  i) const

Returns the const reference to the i-th element.

◆ begin() [1/2]

template<typename T >
Iterator jet::Array< T, 1 >::begin ( )

Returns the begin iterator of the array.

◆ begin() [2/2]

template<typename T >
ConstIterator jet::Array< T, 1 >::begin ( ) const

Returns the begin const iterator of the array.

◆ clear()

template<typename T >
void jet::Array< T, 1 >::clear ( )

Clears the array and resizes to zero.

◆ constAccessor()

template<typename T >
ConstArrayAccessor1<T> jet::Array< T, 1 >::constAccessor ( ) const

Returns the const array accessor.

◆ data() [1/2]

template<typename T >
T* jet::Array< T, 1 >::data ( )

Returns the raw pointer to the array data.

◆ data() [2/2]

template<typename T >
const T* const jet::Array< T, 1 >::data ( ) const

Returns the const raw pointer to the array data.

◆ end() [1/2]

template<typename T >
Iterator jet::Array< T, 1 >::end ( )

Returns the end iterator of the array.

◆ end() [2/2]

template<typename T >
ConstIterator jet::Array< T, 1 >::end ( ) const

Returns the end const iterator of the array.

◆ forEach()

template<typename T >
template<typename Callback >
void jet::Array< T, 1 >::forEach ( Callback  func) const

Iterates the array and invoke given func for each element.

This function iterates the array elements and invoke the callback function func. The callback function takes array's element as its input. The order of execution will be 0 to N-1 where N is the size of the array. Below is the sample usage:

Array<int, 1> array(10, 4);
array.forEach([](int elem) {
printf("%d\n", elem);
});

◆ forEachIndex()

template<typename T >
template<typename Callback >
void jet::Array< T, 1 >::forEachIndex ( Callback  func) const

Iterates the array and invoke given func for each index.

This function iterates the array elements and invoke the callback function func. The callback function takes one parameter which is the index of the array. The order of execution will be 0 to N-1 where N is the size of the array. Below is the sample usage:

Array<int, 1> array(10, 4);
array.forEachIndex([&](size_t i) {
array[i] = 4.f * i + 1.5f;
});

◆ operator ArrayAccessor1< T >()

template<typename T >
jet::Array< T, 1 >::operator ArrayAccessor1< T > ( )

Casts to array accessor.

◆ operator ConstArrayAccessor1< T >()

template<typename T >
jet::Array< T, 1 >::operator ConstArrayAccessor1< T > ( ) const

Casts to const array accessor.

◆ operator=() [1/4]

template<typename T >
Array& jet::Array< T, 1 >::operator= ( Array< T, 1 > &&  other)

Move assignment.

◆ operator=() [2/4]

template<typename T >
Array& jet::Array< T, 1 >::operator= ( const Array< T, 1 > &  other)

Copies given array other to this array.

◆ operator=() [3/4]

template<typename T >
Array& jet::Array< T, 1 >::operator= ( const std::initializer_list< T > &  lst)

Copies given initializer list lst to this array.

◆ operator=() [4/4]

template<typename T >
Array& jet::Array< T, 1 >::operator= ( const T &  other)

Sets entire array with given value.

◆ operator[]() [1/2]

template<typename T >
T& jet::Array< T, 1 >::operator[] ( size_t  i)

Returns the reference to i-th element.

◆ operator[]() [2/2]

template<typename T >
const T& jet::Array< T, 1 >::operator[] ( size_t  i) const

Returns the const reference to i-th element.

◆ parallelForEach()

template<typename T >
template<typename Callback >
void jet::Array< T, 1 >::parallelForEach ( Callback  func)

Iterates the array and invoke given func for each element in parallel using multi-threading.

This function iterates the array elements and invoke the callback function func in parallel using multi-threading. The callback function takes array's element as its input. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:

Array<int, 1> array(1000, 4);
array.parallelForEach([](int& elem) {
elem *= 2;
});

The parameter type of the callback function doesn't have to be T&, but const T& or T can be used as well.

◆ parallelForEachIndex()

template<typename T >
template<typename Callback >
void jet::Array< T, 1 >::parallelForEachIndex ( Callback  func) const

Iterates the array and invoke given func for each index in parallel using multi-threading.

This function iterates the array elements and invoke the callback function func in parallel using multi-threading. The callback function takes one parameter which is the index of the array. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:

Array<int, 1> array(1000, 4);
array.parallelForEachIndex([](size_t i) {
array[i] *= 2;
});

◆ resize()

template<typename T >
void jet::Array< T, 1 >::resize ( size_t  size,
const T &  initVal = T() 
)

Resizes the array with size and fill the new element with initVal.

◆ set() [1/3]

template<typename T >
void jet::Array< T, 1 >::set ( const Array< T, 1 > &  other)

Copies given array other to this array.

◆ set() [2/3]

template<typename T >
void jet::Array< T, 1 >::set ( const std::initializer_list< T > &  lst)

Copies given initializer list lst to this array.

◆ set() [3/3]

template<typename T >
void jet::Array< T, 1 >::set ( const T &  value)

Sets entire array with given value.

◆ size()

template<typename T >
size_t jet::Array< T, 1 >::size ( ) const

Returns size of the array.

◆ swap()

template<typename T >
void jet::Array< T, 1 >::swap ( Array< T, 1 > &  other)

Swaps the content of the array with other array.


The documentation for this class was generated from the following file: