Vector

Fields

VectorObject * _obj
RED::uint64 _size
RED::uint64 _mem_size

Functions

SET_CID
IMPLEMENT_AS
Vector
Vector
~Vector
RED_RC operator=
bool empty
RED::uint64 size
RED::uint64 capacity
T & operator[]
const T & operator[]
T & front
const T & front
T & back
const T & back
void clear
RED_RC resize
RED_RC resize
void reset
RED_RC reserve
RED_RC push_back
RED_RC push_front
RED_RC insert
void pop_back
void pop_front
void erase
void erase
void swap
RED_RC operator+=

Detailed Description

template<class T>
class Vector : public RED::Object

Vectors of objects or scalars.

@related class RED::Map

Public Functions

SET_CID(CID_class_REDVector)
IMPLEMENT_AS()
Vector()

Vector default construction method.

Vector(const RED::Vector<T> &iSource)

Vector copy construction method.

If a memory error occurs during the operation, ‘this’ is set as an empty array, but we can’t return any error code from a ctor().

The memory capacity of ‘this’ is set to the actual size of ‘iSource’.

Parameters:iSourceObject source defining our contents.
virtual ~Vector()

RED::Vector destruction method.

RED_RC operator=(const RED::Vector<T> &iSource)

Assignment operator.

The memory capacity of ‘this’ is set to the actual size of ‘iSource’.

Parameters:iSource – Source overwriting our current contents.
Returns:RED_OK when the assignment succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail.

bool empty() const
Returns:true if the vector is empty, false if the vector is not empty.
RED::uint64 size() const
Returns:The number of Objects in the vector.
RED::uint64 capacity() const
Returns:The number of items allocated in memory.
T &operator[](RED::uint64 iPos)

Returns a reference to the element at the specified position.

Parameters:iPos – Requested list access position.
Returns:A reference to the Object. The returned value is undefined if the provided position is out of the vector boundaries.
const T &operator[](RED::uint64 iPos) const
T &front()

Returns a reference on the first vector element.

Returns:The first vector Object reference. If the vector is empty, the return value is undefined.
const T &front() const
T &back()

Returns a reference on the last vector element.

Returns:The last vector Object reference. If the vector is empty, the return value is undefined.
const T &back() const
void clear()

Erases the contents of the vector.

All Objects in the vector are destroyed. All vector storage memory is released.

RED_RC resize(RED::uint64 iNewSize)

Changes the size of the vector.

The number of objects in the vector is modified:

  • If the actual vector size is below the requested size, new initialized objects are added to the vector until the wished size is reached.
  • If the actual vector size is above the requested size, all objects beyond the requested size are deleted. The allocated memory remains.

Parameters:iNewSize – New number of objects in the vector.
Returns:RED_OK when the operation succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail.

RED_RC resize(RED::uint64 iNewSize, const T &iDefaultValue)

Changes the size of the vector.

Works as Vector::resize, provided an initialization value for all vector objects that may be added.

Parameters:
  • iNewSize – New number of objects in the vector.
  • iDefaultValueObject default value for added Objects.
Returns:

RED_OK when the operation succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail.

void reset(const T &iDefaultValue)

Changes all actual vector values to the provided value.

This method changes the values of all vector elements to ‘iDefaultValue’. The memory is not modified, the size of the vector is not modified either.

Parameters:iDefaultValueObject default value for added Objects.
RED_RC reserve(RED::uint64 iNewMemorySize)

Changes the memory size of the vector.

Simply changes the allocated size of the vector. The vector contents are not modified by the call.

Parameters:iNewMemorySize – New number of items to handle in memory.
Returns:RED_OK when the operation succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail.

RED_RC push_back(const T &iElement)

Adds an object to the end of the vector.

Parameters:iElement – Element being added.
Returns:RED_OK when the operation succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail.

RED_RC push_front(const T &iElement)

Inserts an element at the first position in the vector.

Parameters:iElement – Element being added.
Returns:RED_OK when the operation succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail.

RED_RC insert(RED::uint64 iPosition, const T &iElement)

Inserts an element at any position in the vector.

Parameters:
  • iPosition – Insertion position. Insertion request behind the last position insert as the last element.
  • iElement – Element being added.
Returns:

RED_OK when the operation succeeded,

RED_ALLOC_FAILURE if an internal allocation did fail.

void pop_back()

Removes the last vector element.

The allocated storage memory is not modified by that call.

void pop_front()

Removes the first vector element.

The allocated storage memory is not modified by that call.

void erase(RED::uint64 iPos)

Removes an element at the specified position.

The allocated storage memory is not modified by that call.

Parameters:iPos – Position of the element to be removed.
void erase(RED::uint64 iPosStart, RED::uint64 iPosEnd)

Removes elements between the specified positions.

The allocated storage memory is not modified by that call. erase(i) is equivalent to erase(i,i)

Parameters:
  • iPosStart – first position to be removed.
  • iPosEnd – last position to be removed.
void swap(RED::Vector<T> &ioSecondVector)

exchange *this and another vector

The allocated storage memory in both vector are just swap. Internal vector variables are swapped too, but each vector keep their own id.

Parameters:ioSecondVector – vector to swap with.
RED_RC operator+=(const RED::Vector<T> &iVector)

Addition operator.

Appends the contents of the ‘iVector’ source vector to the contents of ‘this’.

Parameters:iVector – Source vector appened at the end of ‘this’.
Returns:RED_OK if the operation has succeeded,

RED_ALLOC_FAILURE if an internal allocation has failed.

Public Members

VectorObject *_obj

Array of Object’s.

RED::uint64 _size

Number of objects in the array.

RED::uint64 _mem_size

Allocated number of objects in system memory.