ADTF  3.18.2
cMultiArray< T >

Multi dimensional array class template. More...

Public Member Functions

 cMultiArray ()
 Constructor that initializes the array to an invalid state (0 dimensions)
 
 cMultiArray (const cMultiArrayDimensions &oDimensions)
 Constructor that initializes the array to the dimensions specified in the parameter. More...
 
virtual ~cMultiArray ()
 Virtual destructor.
 
tBool IsValid () const
 Check if the array is in a valid state and initialized correctly. More...
 
tSize NumElements () const
 Get the total number of stored elements in the array across all dimensions. More...
 
const cMultiArrayDimensionsDimensions () const
 Get the dimensions of the array. More...
 
tResult Set (const cMultiArrayIndex &oIndex, T value)
 Set the element at the specified array index. More...
 
tResult Get (const cMultiArrayIndex &oIndex, T &value) const
 Get the element at the specified array index. More...
 

Protected Member Functions

tResult InitializeDataStore ()
 Initializes the data vector to the correct size (specified by the dimensions of the array) More...
 
tBool ContainsIndex (const cMultiArrayIndex &oIndex) const
 Check if an index is in bound of the arrays dimensions. More...
 
tResult CalculateInternIndex (const cMultiArrayIndex &oIndex, tUInt &nInternIndex) const
 Calculate the internal flat index that matches the multi dimensional index specified. More...
 

Protected Attributes

cMultiArrayDimensions m_oDimensions
 Stores the arrays dimension object.
 
std::vector< T > m_oData
 Stores the arrays actual data (in a flat vector)
 

Detailed Description

template<typename T>
class A_UTILS_NS::cMultiArray< T >

Multi dimensional array class template.

Usage: Specify the arrays dimensions during construction time:

cMultiArray<tInt> array(cMultiArrayDimensions(3, 2, 4)); // constructs a 3x2x4 array
// Access the elements by using the cMultiArrayIndex object (zero-based):
if (IS_OK(array.Set(cMultiArrayIndex(0, 1, 3), 42))) // set the value at (0, 1, 3) to 42
...
if (IS_OK(array.Get(cMultiArrayIndex(0, 1, 3), value))) // get the value at (0, 1, 3)
...
cMultiArrayIndex cMultiArrayDimensions
Type to specify array dimensions.
Definition: multiarray.h:176

Definition at line 198 of file multiarray.h.

Constructor & Destructor Documentation

◆ cMultiArray()

cMultiArray ( const cMultiArrayDimensions oDimensions)
inlineexplicit

Constructor that initializes the array to the dimensions specified in the parameter.

If the dimensions object is invalid the array will be invalid as well. All values will be default constructed

Parameters
oDimensions[in] The dimensions of the array

Definition at line 361 of file multiarray.h.

References IS_FAILED.

Member Function Documentation

◆ CalculateInternIndex()

tResult CalculateInternIndex ( const cMultiArrayIndex oIndex,
tUInt nInternIndex 
) const
inlineprotected

Calculate the internal flat index that matches the multi dimensional index specified.

Parameters
oIndex[in] The index to base the calculation on
nInternIndex[out] Destination value for the calculated intern index
Returns
Returns standard result

Definition at line 302 of file multiarray.h.

References cMultiArrayIndex::GetDimensionValue(), IS_FAILED, cMultiArrayIndex::IsValid(), and cMultiArrayIndex::NumDimensions().

◆ ContainsIndex()

tBool ContainsIndex ( const cMultiArrayIndex oIndex) const
inlineprotected

Check if an index is in bound of the arrays dimensions.

Parameters
oIndex[in] The index to check
Returns
Returns true if the index is contained, false otherwise

Definition at line 260 of file multiarray.h.

References cMultiArrayIndex::GetDimensionValue(), IS_FAILED, cMultiArrayIndex::IsValid(), and cMultiArrayIndex::NumDimensions().

◆ Dimensions()

const cMultiArrayDimensions& Dimensions ( ) const
inline

Get the dimensions of the array.

Returns
Returns a reference to the dimensions of the array. The dimensions object will be invalid if the array is invalid

Definition at line 412 of file multiarray.h.

◆ Get()

tResult Get ( const cMultiArrayIndex oIndex,
T &  value 
) const
inline

Get the element at the specified array index.

Parameters
oIndex[in] The multi dimension index
value[out] The found element value (set by the getter if successful)
Returns
Returns standard result

Definition at line 453 of file multiarray.h.

References IS_FAILED, cMultiArrayIndex::IsValid(), and RETURN_NOERROR.

◆ InitializeDataStore()

tResult InitializeDataStore ( )
inlineprotected

Initializes the data vector to the correct size (specified by the dimensions of the array)

Returns
Returns standard result

Definition at line 224 of file multiarray.h.

References cMultiArrayIndex::GetDimensionValue(), IS_FAILED, cMultiArrayIndex::NumDimensions(), and RETURN_NOERROR.

◆ IsValid()

tBool IsValid ( ) const
inline

Check if the array is in a valid state and initialized correctly.

Returns
Returns true if the array is valid and initialized

Definition at line 387 of file multiarray.h.

References cMultiArrayIndex::IsValid().

◆ NumElements()

tSize NumElements ( ) const
inline

Get the total number of stored elements in the array across all dimensions.

Returns
Returns the total number of elements in the array

Definition at line 399 of file multiarray.h.

◆ Set()

tResult Set ( const cMultiArrayIndex oIndex,
value 
)
inline

Set the element at the specified array index.

Parameters
oIndex[in] The multi dimension index
value[in] The new element value
Returns
Returns standard result

Definition at line 426 of file multiarray.h.

References IS_FAILED, cMultiArrayIndex::IsValid(), and RETURN_NOERROR.