Template for creating arrays of class objects. More...
Public Types | |
typedef T * | iterator |
STL compatible iterator. | |
typedef const T * | const_iterator |
STL compatible iterator. | |
typedef T | value_type |
STL compatible type declaration. | |
Public Member Functions | |
ClassArray () | |
Default constructor. | |
ClassArray (uintptr_t uDefault) | |
Default constructor with a starting array. | |
ClassArray (const ClassArray< T > &rData) | |
Default constructor for making a copy of another ClassArray. | |
~ClassArray () | |
Standard destructor. | |
T * | GetPtr (void) |
Obtain a pointer to the array. | |
const T * | GetPtr (void) const |
Obtain a constant pointer to the array. | |
T * | data (void) |
const T * | data (void) const |
T & | operator[] (uintptr_t uIndex) |
Obtain a reference to an item in the array. | |
const T & | operator[] (uintptr_t uIndex) const |
Obtain a constant reference to an item in the array. | |
uintptr_t | capacity (void) const |
uintptr_t | size (void) const |
Return the valid number of objects in the array. | |
uint_t | empty (void) const |
Return TRUE if the array is empty. | |
T & | front (void) |
Obtain a reference to first item in the array. | |
const T & | front (void) const |
Obtain a constant reference to first item in the array. | |
T & | back (void) |
Obtain a reference to last item in the array. | |
const T & | back (void) const |
Obtain a constant reference to last item in the array. | |
void | push_back (const T &rData) |
Append an object to the end of the array. | |
void | pop_back (void) |
Remove an object from the end of the array. | |
void | clear (void) |
Remove all objects from the array. | |
ClassArray< T > & | operator= (const ClassArray< T > &rData) |
Copy an array into this one. | |
void | remove_at (uintptr_t uIndex) |
Remove an object from the array. | |
void | insert_at (uintptr_t uIndex, const T &rData=T()) |
Insert an object into the array. | |
uint_t | remove (const T &rData) |
void | append (const T *pSourceData, uintptr_t uCount) |
Append an array of object to this array. | |
void | append (const ClassArray< T > &rData) |
Append an array to this array. | |
void | resize (uintptr_t uNewSize) |
Resize the valid entry count of the array. | |
void | reserve (uintptr_t uNewBufferSize) |
Resize the memory used by the array. | |
iterator | begin (void) |
Iterator for the start of the array. | |
iterator | end (void) |
Iterator for the end of the array. | |
const_iterator | begin (void) const |
Constant iterator for the start of the array. | |
const_iterator | end (void) const |
Constant iterator for the end of the array. | |
const_iterator | cbegin (void) const |
const_iterator | cend (void) const |
void | erase (const_iterator it) |
Remove an entry from the array using an iterator as the index. | |
Static Public Member Functions | |
static uintptr_t | max_size (void) |
Return the number of objects the current buffer could hold. | |
Static Private Member Functions | |
static void | Destroy (T *pData, uintptr_t uCount) |
Destroy an array of class entries. | |
static void | Init (T *pData, uintptr_t uCount) |
Initialized an array of class entries. | |
static void | Init (T *pData, uintptr_t uCount, const T *pSource) |
Initialized an array of class entries with another array. | |
static void | Copy (T *pData, uintptr_t uCount, const T *pSource) |
Copy an array of class entries with another array. | |
Private Attributes | |
T * | m_pData |
Pointer to the array of class instances. | |
uintptr_t | m_uSize |
Number of active elements in the array. | |
uintptr_t | m_uBufferSize |
Maximum number of elements in the array. | |
Template for creating arrays of class objects.
If a case where an array of a class type is only known at run time, this template class will dynamically allocate memory and instantiate class instances with proper shutdown and initialization.
While it uses function names that match the class vector<T>, this is a lightweight version which doesn't match 100% due to implementation for performance.
const T* Burger::ClassArray< T >::const_iterator |
STL compatible iterator.
Constant iterator object for using functions in <algorithm>
T* Burger::ClassArray< T >::iterator |
STL compatible iterator.
Iterator object for using functions in <algorithm>
T Burger::ClassArray< T >::value_type |
STL compatible type declaration.
Type declarator to use in functions in <algorithm>. It's used to create variables of T by using this typedef in the class.
|
inline |
Default constructor.
Initializes the array to contain no data and have no members.
Initializes the array to contain no data and have no members.
|
inline |
Default constructor with a starting array.
Initializes the array to contain uDefault number of members that have been initialized with the default type constructor
uDefault | Number of members to initialize the class with. Zero will generate an empty array. |
|
inline |
Default constructor for making a copy of another ClassArray.
Initializes the array to contain a copy of another ClassArray. Copy constructors will be iterated on each and every object.
rData | Reference to a matching ClassArray type |
|
inline |
Standard destructor.
Call clear() to iterate over every valid object in the array with the type T destructor and then release the memory.
|
inline |
Append an array to this array.
Given another array, iterate over the objects contained within and copy them to the end of this array. This function will increase the size of the buffer if needed.
rData | Reference to a like typed ClassArray to copy from. |
|
inline |
Append an array of object to this array.
Given a base pointer and an object count, iterate over the objects and copy them to the end of this array. This function will increase the size of the buffer if needed.
pSourceData | Pointer to the first element in an array of objects |
uCount | Number of elements in the array |
|
inline |
Obtain a reference to last item in the array.
Return a reference to the last object.
|
inline |
Obtain a constant reference to last item in the array.
Return a constant reference to the last object.
|
inline |
Iterator for the start of the array.
STL compatible iterator for the start of the array.
|
inline |
Constant iterator for the start of the array.
STL compatible constant iterator for the start of the array.
|
inline |
|
inline |
|
inline |
|
inline |
Remove all objects from the array.
Call the destructor on every object in the array and then release the array memory.
|
inlinestaticprivate |
Copy an array of class entries with another array.
Iterate over an array of class instances and copy them. Will perform a reverse copy in case the arrays overlay each other.
pData | Pointer to the array of class instances |
uCount | Number of entries in the array |
pSource | Pointer to the array of class instances to copy from |
|
inline |
|
inline |
|
inlinestaticprivate |
Destroy an array of class entries.
Iterate over an array of class instances and dispose of their contents
pData | Pointer to the array of class instances |
uCount | Number of entries in the array |
|
inline |
Return TRUE if the array is empty.
If there is no valid data in the array, return TRUE.
|
inline |
Iterator for the end of the array.
STL compatible iterator for the end of the array.
|
inline |
Constant iterator for the end of the array.
STL compatible constant iterator for the end of the array.
|
inline |
Remove an entry from the array using an iterator as the index.
Using an iterator index, delete an entry in the array. Note, this will change the end() value in an index
it | Iterator index into an array |
|
inline |
Obtain a reference to first item in the array.
Return a reference to the first object.
|
inline |
Obtain a constant reference to first item in the array.
Return a constant reference to the first object.
|
inline |
Obtain a pointer to the array.
Allow direct access to the base pointer to the array. This can be NULL if the array is empty.
|
inline |
Obtain a constant pointer to the array.
Allow direct access to the base pointer to the array. This can be NULL if the array is empty.
|
inlinestaticprivate |
Initialized an array of class entries.
Iterate over an array of class instances and initialize them with default constructors
pData | Pointer to the array of class instances |
uCount | Number of entries in the array |
|
inlinestaticprivate |
Initialized an array of class entries with another array.
Iterate over an array of class instances and initialize them with copy constructors
pData | Pointer to the array of class instances |
uCount | Number of entries in the array |
pSource | Pointer to the array of class instances to copy from |
|
inline |
Insert an object into the array.
Expand the buffer if needed and make a copy of the rData object into the array at the index uIndex.
uIndex | Index into the array for the location of the object to insert. |
rData | Reference to the object to copy into the array |
|
inlinestatic |
Return the number of objects the current buffer could hold.
The buffer size may exceed the number of valid objects, so that if the array grew, memory allocations won't be needed. This function will return the size of the true buffer.
|
inline |
Copy an array into this one.
If the copy is not itself, call clear() to erase the contents of this class and make a duplicate of every entry in the rData class into this one.
rData | Reference to a matching ClassArray type |
|
inline |
Obtain a reference to an item in the array.
Index into the array and return a reference to the object.
uIndex | Object number in the array to retrieve a reference to. |
|
inline |
Obtain a constant reference to an item in the array.
Index into the array and return a constant reference to the object.
uIndex | Object number in the array to retrieve a constant reference to. |
|
inline |
Remove an object from the end of the array.
Call the destructor on the last object in the array and reduce the array size by one.
|
inline |
Append an object to the end of the array.
Make a copy of the object at the end of the array. If there is no room for the new object, increase the size of the buffer to make room. Buffer size increases are made in groups to reduce memory allocation calls to improve performance.
rData | A constant reference to an object to copy at the end of the array |
|
inline |
|
inline |
Remove an object from the array.
Call the destructor on the specific object in the array and then compact the array if needed.
uIndex | Index into the array of the object to remove. |
|
inline |
Resize the memory used by the array.
This function sets the size of the master buffer which can exceed the number of valid entries in the array. This is a performance function in that if it's known at runtime what is the maximum memory requirements for this array, it can be pre-allocated and all functions can use this buffer until the class is disposed of without any intermediate memory allocation calls.
If the reservation size is zero, the array is released.
If the reservation forces the array to shrink, all of the truncated objects will be properly destructed. The array size will be adjusted to the match the buffer size.
uNewBufferSize | Size in elements of the memory buffer. |
|
inline |
Resize the valid entry count of the array.
If uNewSize is zero, erase all data. If uNewSize increases the size of the array, increase the buffer size if necessary and invoke the default constructor on the new objects. If the size is smaller than the existing array, call the destructors on the removed objects.
In some cases, the buffer size will be reduced if the new size is substantially smaller.
uNewSize | Number of valid objects the new array will contain. |
|
inline |
Return the valid number of objects in the array.
This value is less than or equal to the buffer size.
|
private |
Pointer to the array of class instances.
|
private |
Maximum number of elements in the array.
|
private |
Number of active elements in the array.