Array

Namespace: Array Language: C++ Type: Defold C++ File: array.h Source: engine/dlib/src/dmsdk/dlib/array.h Include: dmsdk/dlib/array.h

Templatized array with bounds checking.

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 a;
a.SetCapacity(1);
a.Push(1);
int b = a[0];

API

Back

Type: FUNCTION Last element of the array

Returns

Back

Type: FUNCTION Last element of the array (const)

Returns

Begin

Type: FUNCTION Pointer to the start of the backing storage

Returns

Begin

Type: FUNCTION Pointer to the start of the backing storage

Returns

Capacity

Type: FUNCTION Capacity is currently allocated storage.

Returns

DM_ARRAY_SIZE

Type: MACRO get number of elements in C array

Parameters

Returns

dmArray

Type: CLASS 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).

Template Parameters

dmArray

Type: FUNCTION constructor. empty auto-allocated memory

Examples

dmArray a;
a.Push(1);

dmArray

Type: FUNCTION user-allocated array with initial size and capacity

Parameters

dmArray

Type: FUNCTION user-allocated array with initial size and capacity

Parameters

Empty

Type: FUNCTION Check if the array is empty. The array is empty when the size is zero.

Returns

End

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

Returns

End

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

Returns

EraseSwap

Type: FUNCTION 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

Returns

EraseSwapRef

Type: FUNCTION 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

Returns

Front

Type: FUNCTION First element of the array

Returns

Front

Type: FUNCTION First element of the array (const)

Returns

Full

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

Returns

Map

Type: FUNCTION map a function on all values

Parameters

OffsetCapacity

Type: FUNCTION 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

operator[]

Type: FUNCTION Retrieve an element by index

Parameters

Returns

operator[]

Type: FUNCTION Retrieve an element by index (const)

Parameters

Returns

Pop

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

Push

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

Parameters

PushArray

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

Parameters

Remaining

Type: FUNCTION Amount of additional elements that can be stored

Returns

SetCapacity

Type: FUNCTION 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

SetSize

Type: FUNCTION Set size of the array

Parameters

Size

Type: FUNCTION Size of the array in elements

Returns

Swap

Type: FUNCTION Swap the content of two arrays

Parameters

~dmArray

Type: FUNCTION Only frees memory when auto-allocated.