Compute Library
 21.05
IArray< T > Class Template Referenceabstract

Array of type T. More...

#include <IArray.h>

Public Member Functions

 IArray ()
 Default constructor. More...
 
 IArray (size_t max_num_values)
 Constructor: initializes an array which can contain up to max_num_points values. More...
 
size_t max_num_values () const
 Maximum number of values which can be stored in this array. More...
 
virtual ~IArray ()=default
 Default virtual destructor. More...
 
size_t num_values () const
 Number of values currently stored in the array. More...
 
bool push_back (const T &val)
 Append the passed argument to the end of the array if there is room. More...
 
void clear ()
 Clear all the points from the array. More...
 
bool overflow () const
 Did we lose some values because the array is too small? More...
 
virtual T * buffer () const =0
 Pointer to the first element of the array. More...
 
virtual T & at (size_t index) const
 Reference to the element of the array located at the given index. More...
 
void resize (size_t num)
 Resizes the array to contain "num" elements. More...
 

Detailed Description

template<class T>
class arm_compute::IArray< T >

Array of type T.

Definition at line 35 of file IArray.h.

Constructor & Destructor Documentation

◆ IArray() [1/2]

IArray ( )
inline

Default constructor.

Definition at line 39 of file IArray.h.

40  : _num_values(0), _max_size(0) {};

◆ IArray() [2/2]

IArray ( size_t  max_num_values)
inline

Constructor: initializes an array which can contain up to max_num_points values.

Parameters
[in]max_num_valuesMaximum number of values the array will be able to stored

Definition at line 45 of file IArray.h.

46  : _num_values(0), _max_size(max_num_values)
47  {
48  }
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:53

◆ ~IArray()

virtual ~IArray ( )
virtualdefault

Default virtual destructor.

Member Function Documentation

◆ at()

virtual T& at ( size_t  index) const
inlinevirtual

Reference to the element of the array located at the given index.

Parameters
[in]indexIndex of the element
Returns
A reference to the element of the array located at the given index.

Definition at line 112 of file IArray.h.

113  {
114  ARM_COMPUTE_ERROR_ON(buffer() == nullptr);
116  return buffer()[index];
117  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
virtual T * buffer() const =0
Pointer to the first element of the array.
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:53

References ARM_COMPUTE_ERROR_ON, IArray< T >::buffer(), and IArray< T >::max_num_values().

Referenced by IArray< T >::push_back().

◆ buffer()

virtual T* buffer ( ) const
pure virtual

Pointer to the first element of the array.

Other elements of the array can be accessed using buffer()[idx] for 0 <= idx < num_poins().

Returns
A pointer to the first element of the array

Implemented in ICLArray< T >, ICLArray< cl_float >, ICLArray< cl_int >, and Array< T >.

Referenced by IArray< T >::at().

◆ clear()

void clear ( )
inline

Clear all the points from the array.

Definition at line 86 of file IArray.h.

87  {
88  _num_values = 0;
89  }

◆ max_num_values()

size_t max_num_values ( ) const
inline

Maximum number of values which can be stored in this array.

Returns
Maximum number of values

Definition at line 53 of file IArray.h.

54  {
55  return _max_size;
56  }

Referenced by IArray< T >::at(), IArray< T >::overflow(), IArray< T >::push_back(), and IArray< T >::resize().

◆ num_values()

size_t num_values ( ) const
inline

Number of values currently stored in the array.

Returns
Number of values currently stored in the array or max_num_values + 1 if the array is overflowed.

Definition at line 63 of file IArray.h.

64  {
65  return _num_values;
66  }

◆ overflow()

bool overflow ( ) const
inline

Did we lose some values because the array is too small?

Returns
True if we tried to add a value using push_back() but there wasn't any room left to store it. False if all the values were successfully added to the array.

Definition at line 95 of file IArray.h.

96  {
97  return _num_values > max_num_values();
98  }
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:53

References IArray< T >::max_num_values().

◆ push_back()

bool push_back ( const T &  val)
inline

Append the passed argument to the end of the array if there is room.

Parameters
[in]valValue to add to the array.
Returns
True if the point was successfully added to the array. False if the array is full and the point couldn't be added.

Definition at line 73 of file IArray.h.

74  {
75  ARM_COMPUTE_ERROR_ON(0 == _max_size);
76  if(_num_values >= max_num_values())
77  {
78  _num_values = max_num_values() + 1;
79  return false;
80  }
81  at(_num_values) = val;
82  _num_values++;
83  return true;
84  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:53
virtual T & at(size_t index) const
Reference to the element of the array located at the given index.
Definition: IArray.h:112

References ARM_COMPUTE_ERROR_ON, IArray< T >::at(), and IArray< T >::max_num_values().

◆ resize()

void resize ( size_t  num)
inline

Resizes the array to contain "num" elements.

If "num" is smaller than the maximum array size, the content is reduced to its first "num" elements, "num" elements can't be bigger than the maximum number of values which can be stored in this array.

Parameters
[in]numThe new array size in number of elements

Definition at line 123 of file IArray.h.

124  {
126  _num_values = num;
127  };
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:53

References ARM_COMPUTE_ERROR_ON, and IArray< T >::max_num_values().


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