<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);
array back
Last element of the array
reference -
T& reference to the last element
array back (const)
Last element of the array (const)
reference -
const T& const-reference to the last element
array begin
Pointer to the start of the backing storage
pointer -
T* pointer to start of memory
capacity of array
Capacity is currently allocated storage.
number -
uint32_t array capacity
array empty
Check if the array is empty. The array is empty when the size is zero.
boolean -
boolean true if the array is empty
array end
Pointer to the end of the backing storage The end is essentially outside of the used storage.
pointer -
T* pointer to end of memory
array eraseswap
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).
index -
uint32_t index of the element to remove
reference -
T& reference to the new element at index
array reference eraseswap
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).
element -
T& reference to the element to remove.
reference -
T& reference to the new referenced element
array front
First element of the array
reference -
T& reference to the first element
array front (const)
First element of the array (const)
reference -
const T& const-reference to the first element
array full
Check if the array is full. The array is full when the size is equal to the capacity.
boolean -
boolean true if the array is full
array offset capacity
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.
offset -
uint32_t relative amount of elements to change the capacity
array pop
Remove the last element of the array Only allowed when the size is larger than zero.
array push
Add an element to the end of the array Only allowed when the capacity is larger than size.
element -
const T& element element to add
array push array
Add an array of elements to the end of the array Only allowed when the capacity is larger than size + count
array -
const T& array of elements to add
count -
uint32_t amount of elements in the array
remaining size of array
Amount of additional elements that can be stored
number -
uint32_t amount of additional elements that can be stored
array set 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.
capacity -
uint32_t capacity of the array
array set size
Set size of the array
size -
uint32_t size of the array, must be less or equal to the capacity
size of array
Size of the array in elements
number -
uint32_t array size
array swap
Swap the content of two arrays
rhs -
dmArray<T>
& reference to array to swap content with
empty auto-allocated array
dmArray<int>* a = new dmArray<int>();
user-allocated array
user-allocated array with initial size and capacity
user_array -
T* User-allocated array to be used as storage.
size -
uint32_t Initial size
capacity -
uint32_t Initial capacity
array operator[]
Retrieve an element by index
index -
uint32_t array index
reference -
T& reference to the element at the specified index
array operator[] (const)
Retrieve an element by index (const)
index -
uint32_t array index
reference -
const T& const-reference to the element at the specified index
array destructor
Only frees memory when auto-allocated.