Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
Burger::ClassArray< T > Class Template Reference

Template for creating arrays of class objects. More...

Inheritance diagram for Burger::ClassArray< T >:
Inheritance graph
[legend]

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.
 

Detailed Description

template<class T>
class Burger::ClassArray< T >

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.

See also
SimpleArray

Member Typedef Documentation

◆ const_iterator

template<class T >
Burger::ClassArray< T >::const_iterator

STL compatible iterator.


Constant iterator object for using functions in <algorithm>

See also
iterator, value_type, begin(void) const or end(void) const

◆ iterator

template<class T >
Burger::ClassArray< T >::iterator

STL compatible iterator.


Iterator object for using functions in <algorithm>

See also
const_iterator, value_type, begin(void) or end(void)

◆ value_type

template<class 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.

See also
iterator or const_iterator

Constructor & Destructor Documentation

◆ ClassArray() [1/3]

template<class T >
Burger::ClassArray< T >::ClassArray ( )
inline

Default constructor.


Initializes the array to contain no data and have no members.

See also
ClassArray(uintptr_t) or ClassArray(const ClassArray& rData)

Initializes the array to contain no data and have no members.

See also
ClassArray(uintptr_t) or ClassArray(const ClassArray&)

◆ ClassArray() [2/3]

template<class T >
Burger::ClassArray< T >::ClassArray ( uintptr_t uDefault)
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

Parameters
uDefaultNumber of members to initialize the class with. Zero will generate an empty array.
See also
ClassArray() or ClassArray(const ClassArray&)

◆ ClassArray() [3/3]

template<class T >
Burger::ClassArray< T >::ClassArray ( const ClassArray< T > & rData)
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.

Parameters
rDataReference to a matching ClassArray type
See also
ClassArray() or ClassArray(uintptr_t)

◆ ~ClassArray()

template<class T >
Burger::ClassArray< T >::~ClassArray ( )
inline

Standard destructor.


Call clear() to iterate over every valid object in the array with the type T destructor and then release the memory.

See also
ClassArray(), ClassArray(uintptr_t) or ClassArray(const ClassArray&)

Member Function Documentation

◆ append() [1/2]

template<class T >
void Burger::ClassArray< T >::append ( const ClassArray< T > & rData)
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.

Parameters
rDataReference to a like typed ClassArray to copy from.
See also
append(const T *,uintptr_t), resize(uintptr_t) or reserve(uintptr_t)

◆ append() [2/2]

template<class T >
void Burger::ClassArray< T >::append ( const T * pSourceData,
uintptr_t uCount )
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.

Parameters
pSourceDataPointer to the first element in an array of objects
uCountNumber of elements in the array
See also
append(const ClassArray&), insert(uintptr_t,const T&), resize(uintptr_t) or reserve(uintptr_t)

◆ back() [1/2]

template<class T >
T & Burger::ClassArray< T >::back ( void )
inline

Obtain a reference to last item in the array.


Return a reference to the last object.

Returns
A reference to the last object in the array
See also
front(void) or back(void) const

◆ back() [2/2]

template<class T >
const T & Burger::ClassArray< T >::back ( void ) const
inline

Obtain a constant reference to last item in the array.


Return a constant reference to the last object.

Returns
A constant reference to the last object in the array
See also
front(void) const or back(void)

◆ begin() [1/2]

template<class T >
Burger::ClassArray::iterator Burger::ClassArray< T >::begin ( void )
inline

Iterator for the start of the array.


STL compatible iterator for the start of the array.

Returns
Iterator for starting a traversal of the array.
See also
end(void) or begin(void) const

◆ begin() [2/2]

template<class T >
Burger::ClassArray::const_iterator Burger::ClassArray< T >::begin ( void ) const
inline

Constant iterator for the start of the array.


STL compatible constant iterator for the start of the array.

Returns
Constant iterator for starting a traversal of the array.
See also
end(void) const or begin(void)

◆ capacity()

template<class T >
uintptr_t Burger::ClassArray< T >::capacity ( void ) const
inline

◆ cbegin()

template<class T >
const_iterator Burger::ClassArray< T >::cbegin ( void ) const
inline

◆ cend()

template<class T >
const_iterator Burger::ClassArray< T >::cend ( void ) const
inline

◆ clear()

template<class T >
void Burger::ClassArray< T >::clear ( void )
inline

Remove all objects from the array.


Call the destructor on every object in the array and then release the array memory.

See also
resize(uintptr_t) or reserve(uintptr_t)

◆ Copy()

template<class T >
void Burger::ClassArray< T >::Copy ( T * pData,
uintptr_t uCount,
const T * pSource )
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.

Parameters
pDataPointer to the array of class instances
uCountNumber of entries in the array
pSourcePointer to the array of class instances to copy from
See also
Destroy(T*,uintptr_t), Init(T*,uintptr_t) or Init(T*,uintptr_t,const T*)

◆ data() [1/2]

template<class T >
T * Burger::ClassArray< T >::data ( void )
inline

◆ data() [2/2]

template<class T >
const T * Burger::ClassArray< T >::data ( void ) const
inline

◆ Destroy()

template<class T >
void Burger::ClassArray< T >::Destroy ( T * pData,
uintptr_t uCount )
inlinestaticprivate

Destroy an array of class entries.


Iterate over an array of class instances and dispose of their contents

Parameters
pDataPointer to the array of class instances
uCountNumber of entries in the array
See also
Init(T*,uintptr_t), Init(T*,uintptr_t,const T*) or Copy(T*,uintptr_t,const T*)

◆ empty()

template<class T >
uint_t Burger::ClassArray< T >::empty ( void ) const
inline

Return TRUE if the array is empty.


If there is no valid data in the array, return TRUE.

Returns
TRUE if the valid object count is zero, FALSE if there are valid objects
See also
size(void) const

◆ end() [1/2]

template<class T >
Burger::ClassArray::iterator Burger::ClassArray< T >::end ( void )
inline

Iterator for the end of the array.


STL compatible iterator for the end of the array.

Returns
Iterator for ending a traversal of the array.
See also
begin(void) or end(void) const

◆ end() [2/2]

template<class T >
Burger::ClassArray::const_iterator Burger::ClassArray< T >::end ( void ) const
inline

Constant iterator for the end of the array.


STL compatible constant iterator for the end of the array.

Returns
Constant iterator for ending a traversal of the array.
See also
begin(void) const or end(void)

◆ erase()

template<class T >
Burger::ClassArray< T >::erase ( const_iterator it)
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

Parameters
itIterator index into an array
See also
remove_at(uintptr_t)

◆ front() [1/2]

template<class T >
T & Burger::ClassArray< T >::front ( void )
inline

Obtain a reference to first item in the array.


Return a reference to the first object.

Returns
A reference to the first object in the array
See also
back(void) or front(void) const

◆ front() [2/2]

template<class T >
const T & Burger::ClassArray< T >::front ( void ) const
inline

Obtain a constant reference to first item in the array.


Return a constant reference to the first object.

Returns
A constant reference to the first object in the array
See also
back(void) const or front(void)

◆ GetPtr() [1/2]

template<class T >
T * Burger::ClassArray< T >::GetPtr ( void )
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.

Returns
A pointer to the array.
See also
GetPtr(void) const or front(void)

◆ GetPtr() [2/2]

template<class T >
const T * Burger::ClassArray< T >::GetPtr ( void ) const
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.

Returns
A constant pointer to the array.
See also
GetPtr(void) or front(void) const

◆ Init() [1/2]

template<class T >
void Burger::ClassArray< T >::Init ( T * pData,
uintptr_t uCount )
inlinestaticprivate

Initialized an array of class entries.


Iterate over an array of class instances and initialize them with default constructors

Parameters
pDataPointer to the array of class instances
uCountNumber of entries in the array
See also
Destroy(T*,uintptr_t), Init(T*,uintptr_t,const T*) or Copy(T*,uintptr_t,const T*)

◆ Init() [2/2]

template<class T >
void Burger::ClassArray< T >::Init ( T * pData,
uintptr_t uCount,
const T * pSource )
inlinestaticprivate

Initialized an array of class entries with another array.


Iterate over an array of class instances and initialize them with copy constructors

Parameters
pDataPointer to the array of class instances
uCountNumber of entries in the array
pSourcePointer to the array of class instances to copy from
See also
Destroy(T*,uintptr_t), Init(T*,uintptr_t) or Copy(T*,uintptr_t,const T*)

◆ insert_at()

template<class T >
void Burger::ClassArray< T >::insert_at ( uintptr_t uIndex,
const T & rData = T() )
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.

Parameters
uIndexIndex into the array for the location of the object to insert.
rDataReference to the object to copy into the array
See also
remove(uintptr_t), resize(uintptr_t) or reserve(uintptr_t)

◆ max_size()

template<class T >
uintptr_t Burger::ClassArray< T >::max_size ( void )
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.

Returns
Number of objects the currently allocated buffer can hold.
See also
size(void) const

◆ operator=()

template<class T >
ClassArray & Burger::ClassArray< T >::operator= ( const ClassArray< T > & rData)
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.

Parameters
rDataReference to a matching ClassArray type
Returns
*this
See also
resize(uintptr_t) or reserve(uintptr_t)

◆ operator[]() [1/2]

template<class T >
T & Burger::ClassArray< T >::operator[] ( uintptr_t uIndex)
inline

Obtain a reference to an item in the array.


Index into the array and return a reference to the object.

Note
In _DEBUG builds, this will BURGER_ASSERT() if the uIndex value exceeds the size of the number of valid entries in the array.
Parameters
uIndexObject number in the array to retrieve a reference to.
Returns
A reference of the object indexed.
See also
operator[](uintptr_t) const

◆ operator[]() [2/2]

template<class T >
const T & Burger::ClassArray< T >::operator[] ( uintptr_t uIndex) const
inline

Obtain a constant reference to an item in the array.


Index into the array and return a constant reference to the object.

Note
In _DEBUG builds, this will BURGER_ASSERT() if the uIndex value exceeds the size of the number of valid entries in the array.
Parameters
uIndexObject number in the array to retrieve a constant reference to.
Returns
A constant reference of the object indexed.
See also
operator[](uintptr_t)

◆ pop_back()

template<class T >
void Burger::ClassArray< T >::pop_back ( void )
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.

See also
push_back(const T&), remove(uintptr_t), resize(uintptr_t) or reserve(uintptr_t)

◆ push_back()

template<class T >
void Burger::ClassArray< T >::push_back ( const T & rData)
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.

Parameters
rDataA constant reference to an object to copy at the end of the array
See also
pop_back(void), insert(uintptr_t,const T&), resize(uintptr_t) or reserve(uintptr_t)

◆ remove()

template<class T >
uint_t Burger::ClassArray< T >::remove ( const T & rData)
inline

◆ remove_at()

template<class T >
void Burger::ClassArray< T >::remove_at ( uintptr_t uIndex)
inline

Remove an object from the array.


Call the destructor on the specific object in the array and then compact the array if needed.

Parameters
uIndexIndex into the array of the object to remove.
See also
insert_at(uintptr_t,const T&), resize(uintptr_t) or reserve(uintptr_t)

◆ reserve()

template<class T >
void Burger::ClassArray< T >::reserve ( uintptr_t uNewBufferSize)
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.

Parameters
uNewBufferSizeSize in elements of the memory buffer.
See also
clear(void) or resize(uintptr_t)

◆ resize()

template<class T >
void Burger::ClassArray< T >::resize ( uintptr_t uNewSize)
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.

Parameters
uNewSizeNumber of valid objects the new array will contain.
See also
clear(void) or reserve(uintptr_t)

◆ size()

template<class T >
uintptr_t Burger::ClassArray< T >::size ( void ) const
inline

Return the valid number of objects in the array.


This value is less than or equal to the buffer size.

Returns
Number of valid objects in the array.
See also
max_size(void) const or empty(void) const

Member Data Documentation

◆ m_pData

template<class T >
T* Burger::ClassArray< T >::m_pData
private

Pointer to the array of class instances.

◆ m_uBufferSize

template<class T >
uintptr_t Burger::ClassArray< T >::m_uBufferSize
private

Maximum number of elements in the array.

◆ m_uSize

template<class T >
uintptr_t Burger::ClassArray< T >::m_uSize
private

Number of active elements in the array.