Simple Application Framework
1
|
Dynamic array. More...
#include <DynArray.h>
Public Types | |
typedef const T * | ConstIterator |
Random-access non-mutable DynArray iterator. | |
typedef T * | Iterator |
Random-access mutable DynArray iterator. | |
Public Member Functions | |
DynArray () | |
Constructor. | |
DynArray (Size initSize, const T &initVal=T()) | |
Constructor. | |
DynArray (const MyType &a) | |
Copy constructor. | |
~DynArray () | |
Destructor. | |
Iterator | Back () |
Iterator to the last element. | |
ConstIterator | Back () const |
Iterator to the last element. | |
Iterator | Begin () |
Iterator to the first element. | |
ConstIterator | Begin () const |
Iterator to the first element. | |
Size | Capacity () const |
Get the maximum number of elements the array can accomodate without memory reallocation. | |
Size | Elements () const |
Get the current number of elements in the container. | |
Iterator | End () |
Iterator one after the last element. | |
ConstIterator | End () const |
Iterator one after the last element. | |
Iterator | Erase (Iterator it) |
Remove arbitrary element from the array. | |
Iterator | Erase (Iterator itBegin, Iterator itEnd) |
Remove a range of elements from the array. | |
MyType & | Free () |
Free memory occupied by the container. | |
Iterator | Front () |
Iterator to the first element. | |
ConstIterator | Front () const |
Iterator to the first element. | |
bool | IsEmpty () const |
Check whether the array is empty. | |
MyType & | operator= (const MyType &a) |
Assignment operator. | |
T & | operator[] (Size i) |
Subscript operator. | |
const T & | operator[] (Size i) const |
Subscript operator. | |
MyType & | PopBack () |
Remove the last element in the array. | |
MyType & | PopFront () |
Remove the first element in the array. | |
MyType & | PushBack (const T &val) |
Add new element to the end of the array. | |
MyType & | PushFront (const T &val) |
Add new element to the beginning of the array. | |
MyType & | Reserve (Size cap) |
Enlarge the capacity of the array such that it is at least cap . | |
MyType & | Resize (Size newSize, const T &initVal=T()) |
Resize the array. | |
MyType & | Shrink () |
Free allocated storage that is not used by valid array elements. | |
MyType & | Swap (MyType &da) |
Swap the content of two arrays. | |
Protected Types | |
typedef DynArray< T > | MyType |
Protected Member Functions | |
void | Grow (Size cap) |
Enlarge the capacity of the array. | |
Size | OptimalCapacityIncrease (Size reqSize) |
Returns how much the capacity should be increased in order to be able to fit the requested number of elements and to reduce later memory reallocations. | |
Static Protected Member Functions | |
static Size | MinCapacity () |
Minimum capacity of the array. |
Dynamic array.
This class represents a one-dimensional array of data that can be dynamically resized. The data is stored in a continuous memory region and the content of the array is preserved during the resize operation. The class is optimized for frequent resizing, i.e., the number of memory reallocations should be minimized. On the other hand, the container may consume more memory than necessary in order to accommodate extra storage for future growth.
Alternatives:
Iterator category: Random-access.
T | Data type. |
typedef const T* Saf::Collection::DynArray< T >::ConstIterator |
Random-access non-mutable DynArray iterator.
typedef T* Saf::Collection::DynArray< T >::Iterator |
Random-access mutable DynArray iterator.
typedef DynArray<T> Saf::Collection::DynArray< T >::MyType [protected] |
Saf::Collection::DynArray< T >::DynArray | ( | ) | [inline] |
Constructor.
Saf::Collection::DynArray< T >::DynArray | ( | Size | initSize, |
const T & | initVal = T() |
||
) | [inline, explicit] |
Constructor.
[in] | initSize | Initial number of elements in the array. |
[in] | initVal | Initial value of the elements. |
Saf::Collection::DynArray< T >::DynArray | ( | const MyType & | a | ) | [inline] |
Copy constructor.
Saf::Collection::DynArray< T >::~DynArray | ( | ) | [inline] |
Destructor.
Iterator Saf::Collection::DynArray< T >::Back | ( | ) | [inline] |
Iterator to the last element.
ConstIterator Saf::Collection::DynArray< T >::Back | ( | ) | const [inline] |
Iterator to the last element.
Iterator Saf::Collection::DynArray< T >::Begin | ( | ) | [inline] |
Iterator to the first element.
ConstIterator Saf::Collection::DynArray< T >::Begin | ( | ) | const [inline] |
Iterator to the first element.
Size Saf::Collection::DynArray< T >::Capacity | ( | ) | const [inline] |
Get the maximum number of elements the array can accomodate without memory reallocation.
Size Saf::Collection::DynArray< T >::Elements | ( | ) | const [inline] |
Get the current number of elements in the container.
Properties:
Iterator Saf::Collection::DynArray< T >::End | ( | ) | [inline] |
Iterator one after the last element.
ConstIterator Saf::Collection::DynArray< T >::End | ( | ) | const [inline] |
Iterator one after the last element.
Iterator Saf::Collection::DynArray< T >::Erase | ( | Iterator | it | ) | [inline] |
Remove arbitrary element from the array.
Succeeding elements are shifted.
Properties:
Iterator Saf::Collection::DynArray< T >::Erase | ( | Iterator | itBegin, |
Iterator | itEnd | ||
) | [inline] |
Remove a range of elements from the array.
The elements in the range [itBegin, itEnd)
are removed and succeeding elements are shifted.
Properties:
MyType& Saf::Collection::DynArray< T >::Free | ( | ) | [inline] |
Free memory occupied by the container.
Properties:
Iterator Saf::Collection::DynArray< T >::Front | ( | ) | [inline] |
Iterator to the first element.
ConstIterator Saf::Collection::DynArray< T >::Front | ( | ) | const [inline] |
Iterator to the first element.
void Saf::Collection::DynArray< T >::Grow | ( | Size | cap | ) | [inline, protected] |
Enlarge the capacity of the array.
[in] | cap | The requested capacity. Must be greater than zero and at least equal to the current number of elements. |
bool Saf::Collection::DynArray< T >::IsEmpty | ( | ) | const [inline] |
Check whether the array is empty.
Properties:
static Size Saf::Collection::DynArray< T >::MinCapacity | ( | ) | [inline, static, protected] |
Minimum capacity of the array.
Setting this higher reduces memory reallocations but may waste some memory for small arrays.
MyType& Saf::Collection::DynArray< T >::operator= | ( | const MyType & | a | ) | [inline] |
Assignment operator.
T& Saf::Collection::DynArray< T >::operator[] | ( | Size | i | ) | [inline] |
Subscript operator.
const T& Saf::Collection::DynArray< T >::operator[] | ( | Size | i | ) | const [inline] |
Subscript operator.
Size Saf::Collection::DynArray< T >::OptimalCapacityIncrease | ( | Size | reqSize | ) | [inline, protected] |
Returns how much the capacity should be increased in order to be able to fit the requested number of elements and to reduce later memory reallocations.
[in] | reqSize | The requested new size. |
MyType& Saf::Collection::DynArray< T >::PopBack | ( | ) | [inline] |
Remove the last element in the array.
Properties:
MyType& Saf::Collection::DynArray< T >::PopFront | ( | ) | [inline] |
Remove the first element in the array.
Properties:
MyType& Saf::Collection::DynArray< T >::PushBack | ( | const T & | val | ) | [inline] |
Add new element to the end of the array.
Properties:
Elements() == Capacity()
. MyType& Saf::Collection::DynArray< T >::PushFront | ( | const T & | val | ) | [inline] |
Add new element to the beginning of the array.
Properties:
MyType& Saf::Collection::DynArray< T >::Reserve | ( | Size | cap | ) | [inline] |
Enlarge the capacity of the array such that it is at least cap
.
This method informs the object about future growth of the array and is useful to avoid iterator invalidations or excessive memory reallocations.
Properties:
cap > Capacity()
. MyType& Saf::Collection::DynArray< T >::Resize | ( | Size | newSize, |
const T & | initVal = T() |
||
) | [inline] |
Resize the array.
The content of the first min(Elements(), newSize)
elements is preserved.
Properties:
newSize > Capacity()
.[in] | newSize | New size of the array. |
[in] | initVal | Initial value of the newly added elements. |
newSize
is greater than the current capacity. More memory than requested may be allocated to accommodate for future growth. Use Shrink() to free unused memory.MyType& Saf::Collection::DynArray< T >::Shrink | ( | ) | [inline] |
Free allocated storage that is not used by valid array elements.
Properties:
MyType& Saf::Collection::DynArray< T >::Swap | ( | MyType & | da | ) | [inline] |
Swap the content of two arrays.
Properties: