muwerk ustd Library
A low-resource, minimal implementation of Arrays, Maps and Queues for low-resource avrs.
|
Lightweight c++11 array implementation. More...
#include <ustd_array.h>
Public Member Functions | |
array (unsigned int startSize=ARRAY_INIT_SIZE, unsigned int maxSize=ARRAY_MAX_SIZE, unsigned int incSize=ARRAY_INC_SIZE, bool shrink=true) | |
array (const T initarray[], unsigned int count) | |
array (const array< T > &ar) | |
~array () | |
arrayIterator< T > | begin () |
arrayIterator< T > | end () |
arrayIterator< const T > | begin () const |
arrayIterator< const T > | end () const |
bool | resize (unsigned int newSize) |
void | setInvalidValue (T &entryInvalidValue) |
int | add (T &entry) |
bool | erase (unsigned int index) |
bool | erase () |
T | operator[] (unsigned int i) const |
T & | operator[] (unsigned int i) |
bool | isEmpty () const |
unsigned int | length () const |
unsigned int | alloclen () const |
Lightweight c++11 array implementation.
ustd_array.h is a minimal, yet highly portable array data type implementation that runs well on architectures with very limited resources such as attiny 8kb avr.
The array class either:
The library header-only.
Make sure to provide the required platform define before including ustd headers.
|
inline |
Constructs an array object. All allocation-hints are optional, the array class will allocate memory as needed during writes, if startSize!=maxSize.
startSize | The number of array entries that are allocated during object creation |
maxSize | The maximal limit of records that will be allocated. If startSize < maxSize, the array size will grow automatically as needed. |
incSize | The number of array entries that are allocated as a chunk if the array needs to grow |
shrink | Boolean indicating, if the array should deallocate memory, if the array size shrinks (due to erase()). |
|
inline |
construct array with const T[] c-array of length count
initarray | c-array of type T |
count | number of entries in initarray |
|
inline |
array copy constructor
|
inline |
Free resources
|
inline |
Append an array element after the current end of the array
entry | array element that is appended after the last current entry. The new array size must be smaller than maxSize as defined during array creation. New array memory is automatically allocated if within maxSize boundaries. |
|
inline |
Check the number of allocated array-entries, which can be larger than the length of the array.
|
inline |
Iterator support: begin()
|
inline |
Iterator support: begin()
|
inline |
Iterator support: end()
|
inline |
Iterator support: end()
|
inline |
Delete all array elements. memory might be freed, if shrink=True during array creation.
|
inline |
Delete array element at given index
index | The array index of the element to be erased. The array size is reduced by 1, and memory might be freed, if shrink=True during array creation. |
|
inline |
Check, if array is empty.
|
inline |
Check number of array-members.
|
inline |
Assign content of array element at i, e.g. myArray[3]=3
|
inline |
Read content of array element at i, a=myArray[3] Note: Since version 0.7.0 a read operation never mutates (e.g. extends) the array, earlier version allowed array-extension via read.
|
inline |
Change the array allocation size.
Note: Usage of this function is optional for optimization. By default, all necessary allocations (and deallocations, if shrink=true during construction was set) are handled automatically.
newSize | the new number of array entries, corresponding memory is allocated/freed as necessary. |
|
inline |
Set the value that's given back, if read of an invalid index is requested. By default, an entry all set to zero is given back. Using this function, the value of an invalid read can be configured.
entryInvalidValue | The value that is given back in case an invalid operation (e.g. read out of bounds) is tried. |