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

1-D read-only array accessor class. More...

#include <jet/array_accessor1.h>

Public Member Functions

 ConstArrayAccessor ()
 Constructs empty 1-D array accessor. More...
 
 ConstArrayAccessor (size_t size, const T *const data)
 Constructs an read-only array accessor that wraps given array. More...
 
 ConstArrayAccessor (const ArrayAccessor< T, 1 > &other)
 Constructs a read-only array accessor from read/write accessor. More...
 
 ConstArrayAccessor (const ConstArrayAccessor &other)
 Copy constructor. More...
 
const T & at (size_t i) const
 Returns the const reference to the i-th element. More...
 
const T *const begin () const
 Returns the begin iterator of the array. More...
 
const T *const end () const
 Returns the end iterator of the array. More...
 
size_t size () const
 Returns size of the array. More...
 
const T *const data () const
 Returns the raw pointer to the array data. 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 parallelForEachIndex (Callback func) const
 Iterates the array and invoke given func for each index in parallel using multi-threading. More...
 
const T & operator[] (size_t i) const
 Returns the const reference to i-th element. More...
 

Detailed Description

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

1-D read-only array accessor class.

This class represents 1-D read-only array accessor. Array accessor provides array-like data read/write functions, but does not handle memory management. Thus, it is more like a random access iterator, but with multi-dimension support.

Constructor & Destructor Documentation

◆ ConstArrayAccessor() [1/4]

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

Constructs empty 1-D array accessor.

◆ ConstArrayAccessor() [2/4]

template<typename T >
jet::ConstArrayAccessor< T, 1 >::ConstArrayAccessor ( size_t  size,
const T *const  data 
)

Constructs an read-only array accessor that wraps given array.

◆ ConstArrayAccessor() [3/4]

template<typename T >
jet::ConstArrayAccessor< T, 1 >::ConstArrayAccessor ( const ArrayAccessor< T, 1 > &  other)
explicit

Constructs a read-only array accessor from read/write accessor.

◆ ConstArrayAccessor() [4/4]

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

Copy constructor.

Member Function Documentation

◆ at()

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

Returns the const reference to the i-th element.

◆ begin()

template<typename T >
const T* const jet::ConstArrayAccessor< T, 1 >::begin ( ) const

Returns the begin iterator of the array.

◆ data()

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

Returns the raw pointer to the array data.

◆ end()

template<typename T >
const T* const jet::ConstArrayAccessor< T, 1 >::end ( ) const

Returns the end iterator of the array.

◆ forEach()

template<typename T >
template<typename Callback >
void jet::ConstArrayAccessor< 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:

int data = {1, 2, 3, 4, 5, 6};
ConstArrayAccessor<int, 1> acc(6, data);
acc.forEach([](int elem) {
printf("%d\n", elem);
});

◆ forEachIndex()

template<typename T >
template<typename Callback >
void jet::ConstArrayAccessor< 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:

int data = {1, 2, 3, 4, 5, 6};
ConstArrayAccessor<int, 1> acc(6, data);
acc.forEachIndex([&](size_t i) {
data[i] = acc[i] * acc[i];
});

◆ operator[]()

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

Returns the const reference to i-th element.

◆ parallelForEachIndex()

template<typename T >
template<typename Callback >
void jet::ConstArrayAccessor< 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:

int data = {1, 2, 3, 4, 5, 6};
ConstArrayAccessor<int, 1> acc(6, data);
accessor.parallelForEachIndex([](size_t i) {
data[i] = acc[i] * acc[i];
});

◆ size()

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

Returns size of the array.


The documentation for this class was generated from the following file:
jet::ConstArrayAccessor< T, 1 >::data
const T *const data() const
Returns the raw pointer to the array data.