Generic array class.
TValue | Generic type parameter. |
Inherits Rx::Interop::Runtime30::IMemory.
Public Member Functions | |
CRxArray () | |
Default constructor. Creates an empty array. More... | |
CRxArray (size_t nElementCount) | |
Constructor. Creates a new array with the given number of default-constructed elements. More... | |
CRxArray (size_t nElementCount, const TValue &tInitValue) | |
Constructor. Constructs a new array with nElementCount copies of elements with value tInitValue. More... | |
CRxArray (const CRxArray< TValue > &xArray) | |
Copy constructor. Creates a copy of the given array. More... | |
CRxArray (CRxArray< TValue > &&xArray) | |
Move constructor. More... | |
CRxArray (void *pvInternal, bool bMove) | |
Creates a new array by moving or copying the internal data into this array. More... | |
virtual | ~CRxArray () |
Destructs the array. More... | |
void | Assign (size_t nElementCount, const TValue &tInitValue) |
Replaces the contents with nElementCount copies of value tInitValue. More... | |
TValue & | At (size_t nIndex) |
Returns a reference to the element at the specified index, with bounds checking. If nIndex is not within the range of the array, an exception is thrown. More... | |
const TValue & | At (size_t nIndex) const |
Returns a reference to the element at the specified index, with bounds checking. If nIndex is not within the range of the array, an exception is thrown. More... | |
TValue & | Back () |
Returns a reference to the last element in the array. Calling Back on an empty array is undefined. More... | |
const TValue & | Back () const |
Returns a reference to the last element in the array. Calling Back on an empty array is undefined. More... | |
TValue * | begin () |
Returns an iterator (pointer) to the first element of the array. More... | |
const TValue * | begin () const |
Returns an iterator (pointer) to the first element of the array. More... | |
size_t | Capacity () const |
Returns the number of elements that the array has currently allocated space for. More... | |
void | Clear () |
Removes all elements from the array. More... | |
virtual void | CopyFrom (const IMemoryAccess *pMemory)=0 |
Copies the memory block described by pMemory into this memory block. This memory block is automatically resized. The function throws an exception if the element sizes of the given memory block does not agree with the element size of this memory block. More... | |
virtual void | CopyFrom (const IMemoryAccess *pxSrcMemory) |
Copies the content of the given source memory into this array. Sets the size of this array to the size of the memory. More... | |
void | CopyFromInternal (const void *pvInternal) |
Creates a new array by copying the internal data into this array. More... | |
void | CopyIntoInternal (void *pvInternal) const |
Copies this array into the internal data. More... | |
TValue * | Data () |
Gets the pointer to the internal data. More... | |
const TValue * | Data () const |
Gets the pointer to the internal data. More... | |
virtual void | Delete () |
Removes all elements from the array. More... | |
TValue * | end () |
Returns an iterator (pointer) to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior. More... | |
const TValue * | end () const |
Returns an iterator (pointer) to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior. More... | |
void | Erase (size_t nPosition) |
Removes the element at the given position from the array. More... | |
void | Erase (size_t nPosition, size_t nCount) |
Removes specified elements from the array. More... | |
TValue & | Front () |
Returns a reference to the first element in the array. Calling Front on an empty array is undefined. More... | |
const TValue & | Front () const |
Returns a reference to the first element in the array. Calling Front on an empty array is undefined. More... | |
virtual size_t | GetElementSize () const |
Gets the size of a single value in this array. More... | |
virtual void * | GetPointer () |
Gets the pointer to the internal data. More... | |
virtual const void * | GetPointer () const |
Gets the pointer to the internal data. More... | |
void | Insert (size_t nPosition, const TValue &tValue) |
Inserts elements at the specified location in the array. More... | |
void | Insert (size_t nPosition, TValue &&tValue) |
Inserts elements at the specified location in the array. More... | |
void | Insert (size_t nPosition, size_t nCount, const TValue &tValue) |
Inserts nCount copies of tValue at the specified location in the array. More... | |
bool | IsEmpty () const |
Checks if the array has no elements. More... | |
virtual bool | IsValid () const |
Query if this object is valid. Returns always true. More... | |
virtual size_t | Length () const |
Gets the number of elements in this array. More... | |
void | MoveFromInternal (void *pvInternal) |
Creates a new array by moving the internal data into this array. More... | |
void | MoveIntoInternal (void *pvInternal) |
moves this array into the internal data. This array is empty afterwards. More... | |
virtual void | New (size_t nElementCount) |
Resizes the array to contain count elements. More... | |
CRxArray< TValue > & | operator= (const CRxArray< TValue > &xArray) |
Copy assignment operator. Replaces the contents with a copy of the contents of the given array. More... | |
CRxArray< TValue > & | operator= (CRxArray< TValue > &&xArray) |
Move assignment operator. Replaces the contents with those of the given array using move semantics (i.e. the data in the given array is moved into this array). The given array is in a valid but unspecified state afterwards. More... | |
TValue & | operator[] (size_t nIndex) |
Returns a reference to the element at the specified index. No bounds checking is performed. More... | |
const TValue & | operator[] (size_t nIndex) const |
Returns a reference to the element at the specified index. No bounds checking is performed. More... | |
void | PopBack () |
Removes the last element of the array. Calling PopBack on an empty array is undefined. More... | |
void | PushBack (const TValue &tValue) |
Appends the given element value to the end of the array. The new element is initialized as a copy of tValue. More... | |
void | PushBack (TValue &&tValue) |
Appends the given element value to the end of the array. The value is moved into the new element. More... | |
void | Reserve (size_t nNewElementCount) |
Increase the capacity of the array to a value that's greater or equal to nNewElementCount. If nNewElementCount is greater than the current capacity, new storage is allocated, otherwise the method does nothing. More... | |
virtual void | Reset () |
Sets the internal memory to zeros. More... | |
void | Resize (size_t nNewElementCount, const TValue &tValue) |
Resizes the array to contain count elements. More... | |
virtual void | Resize (size_t nNewElementCount) |
Resizes the array to contain count elements. More... | |
void | ShrinkToFit () |
Requests the removal of unused capacity. More... | |
size_t | Size () const |
Returns the number of elements in the array. More... | |
void | Swap (CRxArray< TValue > &xArray) |
Exchanges the contents of the array with those of xArray. Does not invoke any move, copy, or swap operations on individual elements. More... | |
Protected Attributes | |
void * | m_pvVector |
Rx::CRxArray< TValue >::CRxArray | ( | ) |
Default constructor. Creates an empty array.
Rx::CRxArray< TValue >::CRxArray | ( | size_t | nElementCount | ) |
Constructor. Creates a new array with the given number of default-constructed elements.
nElementCount | The number of elements. |
Rx::CRxArray< TValue >::CRxArray | ( | size_t | nElementCount, |
const TValue & | tInitValue | ||
) |
Constructor. Constructs a new array with nElementCount copies of elements with value tInitValue.
nElementCount | The number of elements. |
tInitValue | The initial value of each element in this array. |
Rx::CRxArray< TValue >::CRxArray | ( | const CRxArray< TValue > & | xArray | ) |
Copy constructor. Creates a copy of the given array.
xArray | The array to copy. |
Rx::CRxArray< TValue >::CRxArray | ( | CRxArray< TValue > && | xArray | ) |
Move constructor.
xArray | [in,out] The array to move. |
Rx::CRxArray< TValue >::CRxArray | ( | void * | pvInternal, |
bool | bMove | ||
) |
Creates a new array by moving or copying the internal data into this array.
pvInternal | [in,out] Pointer to the internal data. |
bMove | True to move the data, false to copy the data. |
|
virtual |
Destructs the array.
The destructor of the elements are called and the used storage is deallocated. Note, that if the elements are pointers, the pointed-to objects are not destroyed.
void Rx::CRxArray< TValue >::Assign | ( | size_t | nElementCount, |
const TValue & | tInitValue | ||
) |
Replaces the contents with nElementCount copies of value tInitValue.
TValue& Rx::CRxArray< TValue >::At | ( | size_t | nIndex | ) |
Returns a reference to the element at the specified index, with bounds checking. If nIndex is not within the range of the array, an exception is thrown.
nIndex | The index. |
const TValue& Rx::CRxArray< TValue >::At | ( | size_t | nIndex | ) | const |
Returns a reference to the element at the specified index, with bounds checking. If nIndex is not within the range of the array, an exception is thrown.
nIndex | The index. |
TValue& Rx::CRxArray< TValue >::Back | ( | ) |
Returns a reference to the last element in the array. Calling Back on an empty array is undefined.
const TValue& Rx::CRxArray< TValue >::Back | ( | ) | const |
Returns a reference to the last element in the array. Calling Back on an empty array is undefined.
TValue* Rx::CRxArray< TValue >::begin | ( | ) |
Returns an iterator (pointer) to the first element of the array.
const TValue* Rx::CRxArray< TValue >::begin | ( | ) | const |
Returns an iterator (pointer) to the first element of the array.
size_t Rx::CRxArray< TValue >::Capacity | ( | ) | const |
Returns the number of elements that the array has currently allocated space for.
void Rx::CRxArray< TValue >::Clear | ( | ) |
Removes all elements from the array.
Invalidates any references, pointers, or iterators referring to contained elements. Any past-the-end iterators are also invalidated.
Leaves the Capacity() of the array unchanged.
|
pure virtualinherited |
Copies the memory block described by pMemory into this memory block. This memory block is automatically resized. The function throws an exception if the element sizes of the given memory block does not agree with the element size of this memory block.
pMemory | [in] The memory to copy into this memory block. |
|
virtual |
Copies the content of the given source memory into this array. Sets the size of this array to the size of the memory.
pxSrcMemory | The source memory. |
void Rx::CRxArray< TValue >::CopyFromInternal | ( | const void * | pvInternal | ) |
Creates a new array by copying the internal data into this array.
pvInternal | [in,out] Pointer to the internal data. |
void Rx::CRxArray< TValue >::CopyIntoInternal | ( | void * | pvInternal | ) | const |
Copies this array into the internal data.
pvInternal | [in,out] Pointer to the internal data. |
TValue* Rx::CRxArray< TValue >::Data | ( | ) |
Gets the pointer to the internal data.
const TValue* Rx::CRxArray< TValue >::Data | ( | ) | const |
Gets the pointer to the internal data.
|
virtual |
Removes all elements from the array.
Invalidates any references, pointers, or iterators referring to contained elements. Any past-the-end iterators are also invalidated.
Leaves the Capacity() of the array unchanged.
Implements Rx::Interop::Runtime30::IMemory.
TValue* Rx::CRxArray< TValue >::end | ( | ) |
Returns an iterator (pointer) to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior.
const TValue* Rx::CRxArray< TValue >::end | ( | ) | const |
Returns an iterator (pointer) to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior.
void Rx::CRxArray< TValue >::Erase | ( | size_t | nPosition | ) |
Removes the element at the given position from the array.
nPosition | The position. |
void Rx::CRxArray< TValue >::Erase | ( | size_t | nPosition, |
size_t | nCount | ||
) |
Removes specified elements from the array.
nPosition | The position. |
nCount | Number of elements to remove. |
TValue& Rx::CRxArray< TValue >::Front | ( | ) |
Returns a reference to the first element in the array. Calling Front on an empty array is undefined.
const TValue& Rx::CRxArray< TValue >::Front | ( | ) | const |
Returns a reference to the first element in the array. Calling Front on an empty array is undefined.
|
virtual |
Gets the size of a single value in this array.
Implements Rx::Interop::Runtime30::IMemoryAccess.
|
virtual |
Gets the pointer to the internal data.
Implements Rx::Interop::Runtime30::IMemory.
|
virtual |
Gets the pointer to the internal data.
Implements Rx::Interop::Runtime30::IMemoryAccess.
void Rx::CRxArray< TValue >::Insert | ( | size_t | nPosition, |
const TValue & | tValue | ||
) |
Inserts elements at the specified location in the array.
Causes reallocation if the new size is greater than the old capacity. If the new size is greater than capacity, all iterators and references are invalidated. Otherwise, only the iterators and references before the insertion point remain valid. The past-the-end iterator is also invalidated.
nPosition | The position. |
tValue | The value. |
void Rx::CRxArray< TValue >::Insert | ( | size_t | nPosition, |
TValue && | tValue | ||
) |
Inserts elements at the specified location in the array.
Causes reallocation if the new size is greater than the old capacity. If the new size is greater than capacity, all iterators and references are invalidated. Otherwise, only the iterators and references before the insertion point remain valid. The past-the-end iterator is also invalidated.
nPosition | The position. |
tValue | [in,out] The value to move. |
void Rx::CRxArray< TValue >::Insert | ( | size_t | nPosition, |
size_t | nCount, | ||
const TValue & | tValue | ||
) |
Inserts nCount copies of tValue at the specified location in the array.
Causes reallocation if the new size is greater than the old capacity. If the new size is greater than capacity, all iterators and references are invalidated. Otherwise, only the iterators and references before the insertion point remain valid. The past-the-end iterator is also invalidated.
nPosition | The position. |
tValue | The value. |
bool Rx::CRxArray< TValue >::IsEmpty | ( | ) | const |
Checks if the array has no elements.
|
virtual |
Query if this object is valid. Returns always true.
Implements Rx::Interop::Runtime30::IMemoryAccess.
|
virtual |
Gets the number of elements in this array.
Implements Rx::Interop::Runtime30::IMemoryAccess.
void Rx::CRxArray< TValue >::MoveFromInternal | ( | void * | pvInternal | ) |
Creates a new array by moving the internal data into this array.
pvInternal | [in,out] Pointer to the internal data. |
void Rx::CRxArray< TValue >::MoveIntoInternal | ( | void * | pvInternal | ) |
moves this array into the internal data. This array is empty afterwards.
pvInternal | [in,out] Pointer to the internal data. |
|
virtual |
Resizes the array to contain count elements.
If the current size is greater than nNewElementCount, the array is reduced to its first nNewElementCount elements.
If the current size is less than count, additional default-inserted elements are appended.
nNewElementCount | Number of new elements. |
Implements Rx::Interop::Runtime30::IMemory.
CRxArray<TValue>& Rx::CRxArray< TValue >::operator= | ( | const CRxArray< TValue > & | xArray | ) |
Copy assignment operator. Replaces the contents with a copy of the contents of the given array.
xArray | The array to copy. |
CRxArray<TValue>& Rx::CRxArray< TValue >::operator= | ( | CRxArray< TValue > && | xArray | ) |
Move assignment operator. Replaces the contents with those of the given array using move semantics (i.e. the data in the given array is moved into this array). The given array is in a valid but unspecified state afterwards.
xArray | [in,out] The array to move. |
TValue& Rx::CRxArray< TValue >::operator[] | ( | size_t | nIndex | ) |
Returns a reference to the element at the specified index. No bounds checking is performed.
nIndex | The index. |
const TValue& Rx::CRxArray< TValue >::operator[] | ( | size_t | nIndex | ) | const |
Returns a reference to the element at the specified index. No bounds checking is performed.
nIndex | The index. |
void Rx::CRxArray< TValue >::PopBack | ( | ) |
Removes the last element of the array. Calling PopBack on an empty array is undefined.
void Rx::CRxArray< TValue >::PushBack | ( | const TValue & | tValue | ) |
Appends the given element value to the end of the array. The new element is initialized as a copy of tValue.
If the new size is greater than capacity then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.
tValue | The value of the element to append. |
void Rx::CRxArray< TValue >::PushBack | ( | TValue && | tValue | ) |
Appends the given element value to the end of the array. The value is moved into the new element.
If the new size is greater than capacity then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.
tValue | [in,out] The value of the element to append. |
void Rx::CRxArray< TValue >::Reserve | ( | size_t | nNewElementCount | ) |
Increase the capacity of the array to a value that's greater or equal to nNewElementCount. If nNewElementCount is greater than the current capacity, new storage is allocated, otherwise the method does nothing.
If nNewElementCount is greater than capacity, all iterators, including the past-the-end iterator, and all references to the elements are invalidated. Otherwise, no iterators or references are invalidated.
Reserve cannot be used to reduce the capacity of the array, to that end ShrinkToFit() is provided.
Correctly using Reserve can prevent unnecessary reallocations, but inappropriate uses of Reserve (for instance, calling it before every PushBack() call) may actually increase the number of reallocations (by causing the capacity to grow linearly rather than exponentially) and result in increased computational complexity and decreased performance.
nNewElementCount | The new element count. |
|
virtual |
Sets the internal memory to zeros.
Implements Rx::Interop::Runtime30::IMemory.
void Rx::CRxArray< TValue >::Resize | ( | size_t | nNewElementCount, |
const TValue & | tValue | ||
) |
Resizes the array to contain count elements.
If the current size is greater than nNewElementCount, the array is reduced to its first nNewElementCount elements.
If the current size is less than count, additional copies of tValue are appended.
nNewElementCount | New size of the array. |
tValue | The value to initialize the new elements with. |
|
virtual |
Resizes the array to contain count elements.
If the current size is greater than nNewElementCount, the array is reduced to its first nNewElementCount elements.
If the current size is less than count, additional default-inserted elements are appended.
nNewElementCount | Number of new elements. |
Implements Rx::Interop::Runtime30::IMemory.
void Rx::CRxArray< TValue >::ShrinkToFit | ( | ) |
Requests the removal of unused capacity.
It is a non-binding request to reduce Capacity() to Size(). It depends on the implementation if the request is fulfilled.
If reallocation occurs, all iterators, including the past the end iterator, and all references to the elements are invalidated. If no reallocation takes place, no iterators or references are invalidated.
size_t Rx::CRxArray< TValue >::Size | ( | ) | const |
Returns the number of elements in the array.
void Rx::CRxArray< TValue >::Swap | ( | CRxArray< TValue > & | xArray | ) |
Exchanges the contents of the array with those of xArray. Does not invoke any move, copy, or swap operations on individual elements.
xArray | [in,out] The array to exchange the contents with. |
|
protected |