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 | List of all members
Burger::SimpleArray< T > Class Template Reference

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

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

Public Types

typedef Titerator
 STL compatible iterator.
 
typedef const Tconst_iterator
 STL compatible iterator.
 
typedef T value_type
 STL compatible type declaration.
 

Public Member Functions

 SimpleArray () noexcept
 Default constructor.
 
 SimpleArray (uintptr_t uDefault) noexcept
 Default constructor with a starting array.
 
TGetPtr (void) noexcept
 Obtain a pointer to the array.
 
const TGetPtr (void) const noexcept
 Obtain a constant pointer to the array.
 
Tdata (void) noexcept
 Obtain a pointer to the array.
 
const Tdata (void) const noexcept
 Obtain a constant pointer to the array.
 
Toperator[] (uintptr_t uIndex) noexcept
 Obtain a reference to an item in the array.
 
const Toperator[] (uintptr_t uIndex) const noexcept
 Obtain a constant reference to an item in the array.
 
TGetIndexedItem (uintptr_t uIndex)
 Obtain a reference to an item in the array.
 
const TGetIndexedItem (uintptr_t uIndex) const noexcept
 Obtain a constant reference to an item in the array.
 
uintptr_t capacity (void) const noexcept
 Return the number of objects the current buffer could hold.
 
uintptr_t size (void) const noexcept
 Return the valid number of objects in the array.
 
uint_t empty (void) const noexcept
 Return TRUE if the array is empty.
 
Tfront (void) noexcept
 Obtain a reference to first item in the array.
 
const Tfront (void) const noexcept
 Obtain a constant reference to first item in the array.
 
Tback (void) noexcept
 Obtain a reference to last item in the array.
 
const Tback (void) const noexcept
 Obtain a constant reference to last item in the array.
 
eError push_back (T rData) noexcept
 Append an object to the end of the array.
 
eError pop_back (void) noexcept
 Remove an object from the end of the array.
 
SimpleArray< T > & operator= (const SimpleArray< T > &rData) noexcept
 Copy an array into this one.
 
eError insert_at (uintptr_t uIndex, T rData=T()) noexcept
 Insert an object into the array.
 
uint_t remove (T rData) noexcept
 Find an item and remove it from the array.
 
uint_t contains (T rData) const noexcept
 Find an item in the array.
 
eError append (const T *pSourceData, uintptr_t uCount) noexcept
 Append an array of object to this array.
 
eError append (const SimpleArray< T > &rData) noexcept
 Append an array to this array.
 
iterator begin (void) noexcept
 Iterator for the start of the array.
 
iterator end (void) noexcept
 Iterator for the end of the array.
 
const_iterator begin (void) const noexcept
 Constant iterator for the start of the array.
 
const_iterator end (void) const noexcept
 Constant iterator for the end of the array.
 
const_iterator cbegin (void) const noexcept
 Constant iterator for the start of the array.
 
const_iterator cend (void) const noexcept
 Constant iterator for the end of the array.
 
eError erase (const_iterator it) noexcept
 Remove an entry from the array using an iterator as the index.
 
- Public Member Functions inherited from Burger::SimpleArrayBase
 SimpleArrayBase (uintptr_t uChunkSize) noexcept
 Default constructor.
 
 SimpleArrayBase (uintptr_t uChunkSize, uintptr_t uDefault) noexcept
 Default constructor with a starting array and chunk size.
 
 SimpleArrayBase (const SimpleArrayBase &rData) noexcept
 Default constructor for making a copy of another SimpleArrayBase.
 
 ~SimpleArrayBase ()
 Standard destructor.
 
SimpleArrayBaseoperator= (const SimpleArrayBase &rData) noexcept
 Copy an array into this one.
 
void clear (void) noexcept
 Remove all objects from the array.
 
eError remove_at (uintptr_t uIndex) noexcept
 Remove an object from the array.
 
eError resize (uintptr_t uNewSize) noexcept
 Resize the valid entry count of the array.
 
eError reserve (uintptr_t uNewBufferSize) noexcept
 Resize the memory used by the array.
 

Static Public Member Functions

static uintptr_t max_size (void) noexcept
 Return the maximum number of objects the buffer could ever hold.
 

Additional Inherited Members

- Protected Member Functions inherited from Burger::SimpleArrayBase
eError append (const void *pData, uintptr_t uCount) noexcept
 Append an array of object to this array.
 
- Protected Attributes inherited from Burger::SimpleArrayBase
voidm_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.
 
uintptr_t m_uChunkSize
 Size in bytes for each individual element in the array.
 

Detailed Description

template<class T>
class Burger::SimpleArray< T >

Template for creating arrays of intrinsic objects.


This template class will dynamically allocate memory as needed. Since it's assuming the data is of intrinsic values, no initialization or shutdown is performed on the elements. If this behavior is desired, use the ClassArray template instead.

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
ClassArray

Member Typedef Documentation

◆ const_iterator

template<class T >
Burger::SimpleArray< 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::SimpleArray< 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::SimpleArray< 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

◆ SimpleArray() [1/2]

template<class T >
Burger::SimpleArray< T >::SimpleArray ( )
inlinenoexcept

Default constructor.


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

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

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

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

◆ SimpleArray() [2/2]

template<class T >
Burger::SimpleArray< T >::SimpleArray ( uintptr_t uDefault)
inlinenoexcept

Default constructor with a starting array.


Initializes the array to contain uDefault number of uninitialized members.

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

Member Function Documentation

◆ append() [1/2]

template<class T >
void Burger::SimpleArray< T >::append ( const SimpleArray< T > & rData)
inlinenoexcept

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 SimpleArray to copy from.
Returns
Zero on success, or non zero on failure
See also
append(const T *,uintptr_t), resize(uintptr_t) or reserve(uintptr_t)

◆ append() [2/2]

template<class T >
void Burger::SimpleArray< T >::append ( const T * pSourceData,
uintptr_t uCount )
inlinenoexcept

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
Returns
Zero on success, or non zero on failure
See also
append(const SimpleArray&), insert_at(uintptr_t,T), resize(uintptr_t) or reserve(uintptr_t)

◆ back() [1/2]

template<class T >
const T & Burger::SimpleArray< T >::back ( void ) const
inlinenoexcept

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)

◆ back() [2/2]

template<class T >
T & Burger::SimpleArray< T >::back ( void )
inlinenoexcept

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

◆ begin() [1/2]

template<class T >
Burger::SimpleArray::const_iterator Burger::SimpleArray< T >::begin ( void ) const
inlinenoexcept

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)

◆ begin() [2/2]

template<class T >
Burger::SimpleArray::iterator Burger::SimpleArray< T >::begin ( void )
inlinenoexcept

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

◆ capacity()

template<class T >
uintptr_t Burger::SimpleArray< T >::capacity ( void ) const
inlinenoexcept

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

◆ cbegin()

template<class T >
Burger::SimpleArray::const_iterator Burger::SimpleArray< T >::cbegin ( void ) const
inlinenoexcept

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)

◆ cend()

template<class T >
Burger::SimpleArray::const_iterator Burger::SimpleArray< T >::cend ( void ) const
inlinenoexcept

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)

◆ contains()

template<class T >
uint_t Burger::SimpleArray< T >::contains ( T rData) const
inlinenoexcept

Find an item in the array.


Given an item, scan the array for an element that matches the value.

Parameters
rDataCopy of the item to search for
Returns
TRUE if an item was found, FALSE if not
See also
append(const SimpleArray&), insert_at(uintptr_t,T), resize(uintptr_t) or reserve(uintptr_t)

◆ data() [1/2]

template<class T >
const T * Burger::SimpleArray< T >::data ( void ) const
inlinenoexcept

Obtain a constant pointer to the array.


Allow direct access to the base pointer to the array. This can be nullptr if the array is empty.

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

◆ data() [2/2]

template<class T >
T * Burger::SimpleArray< T >::data ( void )
inlinenoexcept

Obtain a pointer to the array.


Allow direct access to the base pointer to the array. This can be nullptr if the array is empty.

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

◆ empty()

template<class T >
uint_t Burger::SimpleArray< T >::empty ( void ) const
inlinenoexcept

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::SimpleArray::const_iterator Burger::SimpleArray< T >::end ( void ) const
inlinenoexcept

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)

◆ end() [2/2]

template<class T >
Burger::SimpleArray::iterator Burger::SimpleArray< T >::end ( void )
inlinenoexcept

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

◆ erase()

template<class T >
Burger::eError Burger::SimpleArray< T >::erase ( const_iterator it)
inlinenoexcept

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
Returns
Zero on success, or non zero on failure
See also
remove_at(uintptr_t)

◆ front() [1/2]

template<class T >
const T & Burger::SimpleArray< T >::front ( void ) const
inlinenoexcept

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)

◆ front() [2/2]

template<class T >
T & Burger::SimpleArray< T >::front ( void )
inlinenoexcept

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

◆ GetIndexedItem() [1/2]

template<class T >
T & Burger::SimpleArray< T >::GetIndexedItem ( 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) or GetIndexedItem(uintptr_t) const

◆ GetIndexedItem() [2/2]

template<class T >
const T & Burger::SimpleArray< T >::GetIndexedItem ( uintptr_t uIndex) const
inlinenoexcept

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) const or GetIndexedItem(uintptr_t)

◆ GetPtr() [1/2]

template<class T >
const T * Burger::SimpleArray< T >::GetPtr ( void ) const
inlinenoexcept

Obtain a constant pointer to the array.


Allow direct access to the base pointer to the array. This can be nullptr if the array is empty.

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

◆ GetPtr() [2/2]

template<class T >
T * Burger::SimpleArray< T >::GetPtr ( void )
inlinenoexcept

Obtain a pointer to the array.


Allow direct access to the base pointer to the array. This can be nullptr if the array is empty.

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

◆ insert_at()

template<class T >
Burger::eError Burger::SimpleArray< T >::insert_at ( uintptr_t uIndex,
T rData = T() )
inlinenoexcept

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
Returns
Zero on success, or non zero on failure
See also
remove_at(uintptr_t), resize(uintptr_t) or reserve(uintptr_t)

◆ max_size()

template<class T >
uintptr_t Burger::SimpleArray< T >::max_size ( void )
inlinestaticnoexcept

Return the maximum number of objects the buffer could ever hold.


Given the maximum possible size of memory in the machine, return the theoretical maximum number of objects the buffer could hold.

Returns
Number of objects the buffer could possibly hold.
See also
capacity(void) const

◆ operator=()

template<class T >
SimpleArray & Burger::SimpleArray< T >::operator= ( const SimpleArray< T > & rData)
inlinenoexcept

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 SimpleArray type
Returns
*this
See also
resize(uintptr_t) or reserve(uintptr_t)

◆ operator[]() [1/2]

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

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) or GetIndexedItem(uintptr_t) const

◆ operator[]() [2/2]

template<class T >
T & Burger::SimpleArray< T >::operator[] ( uintptr_t uIndex)
inlinenoexcept

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 or GetIndexedItem(uintptr_t)

◆ pop_back()

template<class T >
Burger::eError Burger::SimpleArray< T >::pop_back ( void )
inlinenoexcept

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.

Returns
Zero on success, or non zero on failure
See also
push_back(T), remove_at(uintptr_t), resize(uintptr_t) or reserve(uintptr_t)

◆ push_back()

template<class T >
Burger::eError Burger::SimpleArray< T >::push_back ( T rData)
inlinenoexcept

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
rDataAn instance of the object to copy at the end of the array
Returns
Zero on success, or non zero on failure
See also
pop_back(void), insert_at(uintptr_t,T), resize(uintptr_t) or reserve(uintptr_t)

◆ remove()

template<class T >
uint_t Burger::SimpleArray< T >::remove ( T rData)
inlinenoexcept

Find an item and remove it from the array.


Given an item, scan the array for the first element found and then remove the item.

Note
If there are multiple copies of the item in the array, this function only removes the first occurrence, not all copies.
Parameters
rDataCopy of the item to remove
Returns
TRUE if an item was removed, FALSE if not
See also
append(const SimpleArray&), insert_at(uintptr_t,T), resize(uintptr_t) or reserve(uintptr_t)

◆ size()

template<class T >
uintptr_t Burger::SimpleArray< T >::size ( void ) const
inlinenoexcept

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