template< class T > class RED::Vector

Vectors of objects or scalars.

#include <REDSTL.h>

Inherits: Object.

Public functions:

Vector ( const RED::Vector< T > & iSource )
Vector ( )
virtual ~Vector ( )
virtual void *As ( const RED::CID & iCID )
virtual const void *As ( const RED::CID & iCID ) const
template< class T_As > const T_As *As ( ) const
template< class T_As > T_As *As ( )
T &back ( )
const T &back ( ) const
RED::uint64capacity ( ) const
voidclear ( )
boolempty ( ) const
voiderase ( RED::uint64 iPos )
voiderase ( RED::uint64 iPosStart, RED::uint64 iPosEnd )
T &front ( )
const T &front ( ) const
RED_RCinsert ( RED::uint64 iPosition, const T & iElement )
RED_RCoperator+= ( const RED::Vector< T > & iVector )
RED_RCoperator= ( const RED::Vector< T > & iSource )
T &operator[] ( RED::uint64 iPos )
const T &operator[] ( RED::uint64 iPos ) const
voidpop_back ( )
voidpop_front ( )
RED_RCpush_back ( const T & iElement )
RED_RCpush_front ( const T & iElement )
RED_RCreserve ( RED::uint64 iNewMemorySize )
voidreset ( const T & iDefaultValue )
RED_RCresize ( RED::uint64 iNewSize )
RED_RCresize ( RED::uint64 iNewSize, const T & iDefaultValue )
RED::uint64size ( ) const
voidswap ( RED::Vector< T > & ioSecondVector )

Public static functions:

static RED::CIDGetClassID ( )

Public variables:

RED::uint64_mem_size
VectorObject *_obj
RED::uint64_size

Protected functions:

RED_RCAllocate ( RED::uint64 iMinimalSize = 0 )

Functions documentation

public RED::Vector::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:

iSource:Object source defining our contents.

Vector default construction method.

public virtual RED::Vector::~Vector()

RED::Vector destruction method.

public virtual void * RED::Vector::As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters:

iCID:Requested class.

Returns:

An object pointer of the given class on success, NULL otherwise.

Reimplements: RED::Object::As.

public virtual const void * RED::Vector::As(const RED::CID &iCID) const

Converts the object to an instance of the given type.

Parameters:

iCID:Requested class.

Returns:

An object pointer of the given class on success, NULL otherwise.

Reimplements: RED::Object::As.

template< class T_As > public const T_As * RED::Vector::As() const

Template version of the as const method.

Simply set T to be the class you want to retrieve an interface to.

Returns:

A pointer to a const instance of class T on success, NULL otherwise.

Reimplements: RED::Object::As.

template< class T_As > public T_As * RED::Vector::As()

Template version of the as method.

Simply set T to be the class you want to retrieve an interface to.

Returns:

A pointer to an instance of class T on success, NULL otherwise.

Reimplements: RED::Object::As.

public T & RED::Vector::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.
public const T & RED::Vector::back() const

Returns:

The number of items allocated in memory.
public void RED::Vector::clear()

Erases the contents of the vector.

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

public bool RED::Vector::empty() const

Returns:

true if the vector is empty, false if the vector is not empty.

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.
public void RED::Vector::erase(RED::uint64iPosStart,
RED::uint64iPosEnd
)

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.
public T & RED::Vector::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.
public const T & RED::Vector::front() const
public RED_RC RED::Vector::insert(RED::uint64iPosition,
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.
public RED_RC RED::Vector::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 RED_RC RED::Vector::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.

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.
public const T & RED::Vector::operator[](RED::uint64iPos) const
public void RED::Vector::pop_back()

Removes the last vector element.

The allocated storage memory is not modified by that call.

Removes the first vector element.

The allocated storage memory is not modified by that call.

public RED_RC RED::Vector::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.
public RED_RC RED::Vector::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.

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.
public void RED::Vector::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:

iDefaultValue:Object default value for added Objects.

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.
public RED_RC RED::Vector::resize(RED::uint64iNewSize,
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.
iDefaultValue:Object default value for added Objects.

Returns:

RED_OK when the operation succeeded,
RED_ALLOC_FAILURE if an internal allocation did fail.

Returns:

The number of Objects in the vector.
public void RED::Vector::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.
protected RED_RC RED::Vector::Allocate(RED::uint64iMinimalSize = 0)

sAdd memory storage to the vector.

Parameters:

iMinimalSize:Set to the minimal number of objects to allocate when specified.

Returns:

RED_OK when the allocation succeeded,
RED_ALLOC_FAILURE otherwise.

Variables documentation

Allocated number of objects in system memory.

public VectorObject * RED::Vector::_obj

Array of Object's.

Number of objects in the array.