- Select ref document -

SDK Array API documentation

version 1.2.149

<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);

Functions

dmArray::Back

dmArray::Back()

Last element of the array

Returns

reference

T& reference to the last element

reference

T& reference to the last element

dmArray::Back

dmArray::Back()

Last element of the array (const)

Returns

reference

const T& const-reference to the last element

reference

const T& const-reference to the last element

dmArray::Begin

dmArray::Begin()

Pointer to the start of the backing storage

Returns

pointer

T* pointer to start of memory

pointer

T* pointer to start of memory

dmArray::Capacity

dmArray::Capacity()

Capacity is currently allocated storage.

Returns

number

uint32_t array capacity

number

uint32_t array capacity

dmArray::Empty

dmArray::Empty()

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

Returns

boolean

boolean true if the array is empty

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.

Returns

pointer

T* pointer to end of memory

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

index

uint32_t index of the element to remove

Returns

reference

T& reference to the new element at index

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.

element

T& reference to the element to remove.

Returns

reference

T& reference to the new referenced element

reference

T& reference to the new referenced element

dmArray::Front

dmArray::Front()

First element of the array

Returns

reference

T& reference to the first element

reference

T& reference to the first element

dmArray::Front

dmArray::Front()

First element of the array (const)

Returns

reference

const T& const-reference to the first element

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.

Returns

boolean

boolean true if the array is full

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

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.

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

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

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

Returns

number

uint32_t amount of additional elements that can be stored

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

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

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

Returns

number

uint32_t array size

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

rhs

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

dmArray::dmArray

dmArray::dmArray()

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

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

index

uint32_t array index

Returns

reference

T& reference to the element at the specified index

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

index

uint32_t array index

Returns

reference

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

reference

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

dmArray::~dmArray

dmArray::~dmArray()

Only frees memory when auto-allocated.