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

2-D array accessor class. More...

#include <jet/array_accessor2.h>

Public Member Functions

 ArrayAccessor ()
 Constructs empty 2-D array accessor. More...
 
 ArrayAccessor (const Size2 &size, T *const data)
 
 ArrayAccessor (size_t width, size_t height, T *const data)
 
 ArrayAccessor (const ArrayAccessor &other)
 Copy constructor. More...
 
void set (const ArrayAccessor &other)
 Replaces the content with given other array accessor. More...
 
void reset (const Size2 &size, T *const data)
 Resets the array. More...
 
void reset (size_t width, size_t height, T *const data)
 Resets the array. 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...
 
T & at (const Point2UI &pt)
 Returns the reference to the element at (pt.x, pt.y). More...
 
const T & at (const Point2UI &pt) const
 Returns the const reference to the element at (pt.x, pt.y). More...
 
T & at (size_t i, size_t j)
 Returns the reference to the element at (i, j). More...
 
const T & at (size_t i, size_t j) const
 Returns the const reference to the element at (i, j). More...
 
T *const begin () const
 Returns the begin iterator of the array. More...
 
T *const end () const
 Returns the end iterator of the array. More...
 
T * begin ()
 Returns the begin iterator of the array. More...
 
T * end ()
 Returns the end iterator of the array. More...
 
Size2 size () const
 Returns the size of the array. More...
 
size_t width () const
 Returns the width of the array. More...
 
size_t height () const
 Returns the height of the array. More...
 
T *const data () const
 Returns the raw pointer to the array data. More...
 
void swap (ArrayAccessor &other)
 Swaps the content of with other array accessor. More...
 
template<typename Callback >
void forEach (Callback func) const
 Iterates the array and invoke given func for each index. 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 index in parallel. 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...
 
size_t index (const Point2UI &pt) const
 Returns the linear index of the given 2-D coordinate (pt.x, pt.y). More...
 
size_t index (size_t i, size_t j) const
 Returns the linear index of the given 2-D coordinate (i, j). More...
 
T & operator[] (size_t i)
 Returns the reference to the i-th element. More...
 
const T & operator[] (size_t i) const
 Returns the const reference to the i-th element. More...
 
T & operator() (const Point2UI &pt)
 Returns the reference to the element at (pt.x, pt.y). More...
 
const T & operator() (const Point2UI &pt) const
 Returns the const reference to the element at (pt.x, pt.y). More...
 
T & operator() (size_t i, size_t j)
 Returns the reference to the element at (i, j). More...
 
const T & operator() (size_t i, size_t j) const
 Returns the const reference to the element at (i, j). More...
 
ArrayAccessoroperator= (const ArrayAccessor &other)
 Copies given array accessor other. More...
 
 operator ConstArrayAccessor< T, 2 > () const
 Casts type to ConstArrayAccessor. More...
 

Detailed Description

template<typename T>
class jet::ArrayAccessor< T, 2 >

2-D array accessor class.

This class represents 2-D 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. Similar to Array<T, 2>, this class interprets a linear array as a 2-D array using i-major indexing.

See also
Array<T, 2>
Template Parameters
T- Array value type.

Constructor & Destructor Documentation

◆ ArrayAccessor() [1/4]

template<typename T >
jet::ArrayAccessor< T, 2 >::ArrayAccessor ( )

Constructs empty 2-D array accessor.

◆ ArrayAccessor() [2/4]

template<typename T >
jet::ArrayAccessor< T, 2 >::ArrayAccessor ( const Size2 size,
T *const  data 
)

Constructs an array accessor that wraps given array.

Parameters
sizeSize of the 2-D array.
dataRaw array pointer.

◆ ArrayAccessor() [3/4]

template<typename T >
jet::ArrayAccessor< T, 2 >::ArrayAccessor ( size_t  width,
size_t  height,
T *const  data 
)

Constructs an array accessor that wraps given array.

Parameters
widthWidth of the 2-D array.
heightHeight of the 2-D array.
dataRaw array pointer.

◆ ArrayAccessor() [4/4]

template<typename T >
jet::ArrayAccessor< T, 2 >::ArrayAccessor ( const ArrayAccessor< T, 2 > &  other)

Copy constructor.

Member Function Documentation

◆ at() [1/6]

template<typename T >
T& jet::ArrayAccessor< T, 2 >::at ( const Point2UI pt)

Returns the reference to the element at (pt.x, pt.y).

◆ at() [2/6]

template<typename T >
const T& jet::ArrayAccessor< T, 2 >::at ( const Point2UI pt) const

Returns the const reference to the element at (pt.x, pt.y).

◆ at() [3/6]

template<typename T >
T& jet::ArrayAccessor< T, 2 >::at ( size_t  i)

Returns the reference to the i-th element.

◆ at() [4/6]

template<typename T >
const T& jet::ArrayAccessor< T, 2 >::at ( size_t  i) const

Returns the const reference to the i-th element.

◆ at() [5/6]

template<typename T >
T& jet::ArrayAccessor< T, 2 >::at ( size_t  i,
size_t  j 
)

Returns the reference to the element at (i, j).

◆ at() [6/6]

template<typename T >
const T& jet::ArrayAccessor< T, 2 >::at ( size_t  i,
size_t  j 
) const

Returns the const reference to the element at (i, j).

◆ begin() [1/2]

template<typename T >
T* jet::ArrayAccessor< T, 2 >::begin ( )

Returns the begin iterator of the array.

◆ begin() [2/2]

template<typename T >
T* const jet::ArrayAccessor< T, 2 >::begin ( ) const

Returns the begin iterator of the array.

◆ data()

template<typename T >
T* const jet::ArrayAccessor< T, 2 >::data ( ) const

Returns the raw pointer to the array data.

◆ end() [1/2]

template<typename T >
T* jet::ArrayAccessor< T, 2 >::end ( )

Returns the end iterator of the array.

◆ end() [2/2]

template<typename T >
T* const jet::ArrayAccessor< T, 2 >::end ( ) const

Returns the end iterator of the array.

◆ forEach()

template<typename T >
template<typename Callback >
void jet::ArrayAccessor< T, 2 >::forEach ( 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 array's element as its input. The order of execution will be the same as the nested for-loop below:

int data = {1, 2, 3, 4, 5, 6};
ArrayAccessor<int, 2> acc(2, 3, data);
for (size_t j = 0; j < acc.height(); ++j) {
for (size_t i = 0; i < acc.width(); ++i) {
func(acc(i, j));
}
}

Below is the sample usage:

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

◆ forEachIndex()

template<typename T >
template<typename Callback >
void jet::ArrayAccessor< T, 2 >::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 two parameters which are the (i, j) indices of the array. The order of execution will be the same as the nested for-loop below:

int data = {1, 2, 3, 4, 5, 6};
ArrayAccessor<int, 2> acc(2, 3, data);
for (size_t j = 0; j < acc.height(); ++j) {
for (size_t i = 0; i < acc.width(); ++i) {
func(i, j);
}
}

Below is the sample usage:

int data = {1, 2, 3, 4, 5, 6};
ArrayAccessor<int, 2> acc(2, 3, data);
acc.forEachIndex([&](size_t i, size_t j) {
acc(i, j) = 4.f * i + 7.f * j + 1.5f;
});

◆ height()

template<typename T >
size_t jet::ArrayAccessor< T, 2 >::height ( ) const

Returns the height of the array.

◆ index() [1/2]

template<typename T >
size_t jet::ArrayAccessor< T, 2 >::index ( const Point2UI pt) const

Returns the linear index of the given 2-D coordinate (pt.x, pt.y).

◆ index() [2/2]

template<typename T >
size_t jet::ArrayAccessor< T, 2 >::index ( size_t  i,
size_t  j 
) const

Returns the linear index of the given 2-D coordinate (i, j).

◆ operator ConstArrayAccessor< T, 2 >()

template<typename T >
jet::ArrayAccessor< T, 2 >::operator ConstArrayAccessor< T, 2 > ( ) const

Casts type to ConstArrayAccessor.

◆ operator()() [1/4]

template<typename T >
T& jet::ArrayAccessor< T, 2 >::operator() ( const Point2UI pt)

Returns the reference to the element at (pt.x, pt.y).

◆ operator()() [2/4]

template<typename T >
const T& jet::ArrayAccessor< T, 2 >::operator() ( const Point2UI pt) const

Returns the const reference to the element at (pt.x, pt.y).

◆ operator()() [3/4]

template<typename T >
T& jet::ArrayAccessor< T, 2 >::operator() ( size_t  i,
size_t  j 
)

Returns the reference to the element at (i, j).

◆ operator()() [4/4]

template<typename T >
const T& jet::ArrayAccessor< T, 2 >::operator() ( size_t  i,
size_t  j 
) const

Returns the const reference to the element at (i, j).

◆ operator=()

template<typename T >
ArrayAccessor& jet::ArrayAccessor< T, 2 >::operator= ( const ArrayAccessor< T, 2 > &  other)

Copies given array accessor other.

◆ operator[]() [1/2]

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

Returns the reference to the i-th element.

◆ operator[]() [2/2]

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

Returns the const reference to the i-th element.

◆ parallelForEach()

template<typename T >
template<typename Callback >
void jet::ArrayAccessor< T, 2 >::parallelForEach ( Callback  func)

Iterates the array and invoke given func for each index in parallel.

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 non-deterministic since it runs in parallel. Below is the sample usage:

int data = {1, 2, 3, 4, 5, 6};
ArrayAccessor<int, 2> acc(2, 3, data);
acc.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::ArrayAccessor< T, 2 >::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 two parameters which are the (i, j) indices 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};
ArrayAccessor<int, 2> acc(2, 3, data);
acc.parallelForEachIndex([&](size_t i, size_t j) {
acc(i, j) *= 2;
});

◆ reset() [1/2]

template<typename T >
void jet::ArrayAccessor< T, 2 >::reset ( const Size2 size,
T *const  data 
)

Resets the array.

◆ reset() [2/2]

template<typename T >
void jet::ArrayAccessor< T, 2 >::reset ( size_t  width,
size_t  height,
T *const  data 
)

Resets the array.

◆ set()

template<typename T >
void jet::ArrayAccessor< T, 2 >::set ( const ArrayAccessor< T, 2 > &  other)

Replaces the content with given other array accessor.

◆ size()

template<typename T >
Size2 jet::ArrayAccessor< T, 2 >::size ( ) const

Returns the size of the array.

◆ swap()

template<typename T >
void jet::ArrayAccessor< T, 2 >::swap ( ArrayAccessor< T, 2 > &  other)

Swaps the content of with other array accessor.

◆ width()

template<typename T >
size_t jet::ArrayAccessor< T, 2 >::width ( ) const

Returns the width of the array.


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