SDK Array API documentation

Version: stable

<dmsdk/dlib/array.h>

Templatized array with bounds checking.
template <typename T> class dmArray

The backing storage is either auto-allocated (dynamically allocated) or user-allocated (supplied by user). With exception of changing the size and capacity, all operations are guaranteed to be O(1).

dmArray<int> a;
a.Push(1);
FUNCTION
dmArray::Back()

array back

dmArray::Back()

array back (const)

dmArray::Begin()

array begin

dmArray::Capacity()

capacity of array

dmArray::Empty()

array empty

dmArray::End()

array end

dmArray::EraseSwap()

array eraseswap

dmArray::EraseSwapRef()

array reference eraseswap

dmArray::Front()

array front

dmArray::Front()

array front (const)

dmArray::Full()

array full

dmArray::OffsetCapacity()

array offset capacity

dmArray::Pop()

array pop

dmArray::Push()

array push

dmArray::PushArray()

array push array

dmArray::Remaining()

remaining size of array

dmArray::SetCapacity()

array set capacity

dmArray::SetSize()

array set size

dmArray::Size()

size of array

dmArray::Swap()

array swap

dmArray::dmArray()

empty auto-allocated array

dmArray::dmArray()

user-allocated array

dmArray::operator[]()

array operator[]

dmArray::operator[]()

array operator[] (const)

dmArray::~dmArray()

array destructor

Functions

dmArray::Back()

dmArray::Back()

Last element of the array

PARAMETERS

RETURNS

reference

T& reference to the last element


dmArray::Back()

dmArray::Back()

Last element of the array (const)

PARAMETERS

RETURNS

reference

const T& const-reference to the last element


dmArray::Begin()

dmArray::Begin()

Pointer to the start of the backing storage

PARAMETERS

RETURNS

pointer

T* pointer to start of memory


dmArray::Capacity()

dmArray::Capacity()

Capacity is currently allocated storage.

PARAMETERS

RETURNS

number

uint32_t array capacity


dmArray::Empty()

dmArray::Empty()

Check if the array is empty. The array is empty when the size is zero.

PARAMETERS

RETURNS

boolean

boolean true if the array is empty


dmArray::End()

dmArray::End()

Pointer to the end of the backing storage The end is essentially outside of the used storage.

PARAMETERS

RETURNS

pointer

T* pointer to end of memory


dmArray::EraseSwap()

dmArray::EraseSwap(index)

Remove the element at the specified index. The removed element is replaced by the element at the end (if any), thus potentially altering the order. While operation changes the array size, it is guaranteed to be O(1).

PARAMETERS

index

uint32_t index of the element to remove

RETURNS

reference

T& reference to the new element at index


dmArray::EraseSwapRef()

dmArray::EraseSwapRef(element)

Remove the element by reference The removed element is replaced by the element at the end (if any), thus potentially altering the order. While operation changes the array size, it is guaranteed to be O(1).

PARAMETERS

element

T& reference to the element to remove.

RETURNS

reference

T& reference to the new referenced element


dmArray::Front()

dmArray::Front()

First element of the array

PARAMETERS

RETURNS

reference

T& reference to the first element


dmArray::Front()

dmArray::Front()

First element of the array (const)

PARAMETERS

RETURNS

reference

const T& const-reference to the first element


dmArray::Full()

dmArray::Full()

Check if the array is full. The array is full when the size is equal to the capacity.

PARAMETERS

RETURNS

boolean

boolean true if the array is full


dmArray::OffsetCapacity()

dmArray::OffsetCapacity(offset)

Relative change of capacity Equivalent to SetCapacity(Capacity() + offset). Only allowed for auto-allocated arrays and will result in a new dynamic allocation followed by memcpy of the elements.

PARAMETERS

offset

uint32_t relative amount of elements to change the capacity


dmArray::Pop()

dmArray::Pop()

Remove the last element of the array Only allowed when the size is larger than zero.

PARAMETERS


dmArray::Push()

dmArray::Push(element)

Add an element to the end of the array Only allowed when the capacity is larger than size.

PARAMETERS

element

const T& element element to add


dmArray::PushArray()

dmArray::PushArray(array,count)

Add an array of elements to the end of the array Only allowed when the capacity is larger than size + count

PARAMETERS

array

const T& array of elements to add

count

uint32_t amount of elements in the array


dmArray::Remaining()

dmArray::Remaining()

Amount of additional elements that can be stored

PARAMETERS

RETURNS

number

uint32_t amount of additional elements that can be stored


dmArray::SetCapacity()

dmArray::SetCapacity(capacity)

Set the capacity of the array. If the size is less than the capacity, the array is truncated. If it is larger, the array is extended. Only allowed for auto-allocated arrays and will result in a new dynamic allocation followed by memcpy of the elements.

PARAMETERS

capacity

uint32_t capacity of the array


dmArray::SetSize()

dmArray::SetSize(size)

Set size of the array

PARAMETERS

size

uint32_t size of the array, must be less or equal to the capacity


dmArray::Size()

dmArray::Size()

Size of the array in elements

PARAMETERS

RETURNS

number

uint32_t array size


dmArray::Swap()

dmArray::Swap(rhs)

Swap the content of two arrays

PARAMETERS

rhs

dmArray<T>& reference to array to swap content with


dmArray::dmArray()

dmArray::dmArray()

PARAMETERS

EXAMPLES

dmArray<int>* a = new dmArray<int>();

dmArray::dmArray()

dmArray::dmArray(user_array,size,capacity)

user-allocated array with initial size and capacity

PARAMETERS

user_array

T* User-allocated array to be used as storage.

size

uint32_t Initial size

capacity

uint32_t Initial capacity


dmArray::operator[]()

dmArray::operator[](index)

Retrieve an element by index

PARAMETERS

index

uint32_t array index

RETURNS

reference

T& reference to the element at the specified index


dmArray::operator[]()

dmArray::operator[](index)

Retrieve an element by index (const)

PARAMETERS

index

uint32_t array index

RETURNS

reference

const T& const-reference to the element at the specified index


dmArray::~dmArray()

dmArray::~dmArray()

Only frees memory when auto-allocated.

PARAMETERS