AI_Array< TYPE > Class Template Reference
[Utilities]
#include <AI_Array.h>
Detailed Description
template<class TYPE>
class AI_Array< TYPE >
A dynamic array template class, similar to the stl vector class.
Can also be set to a fixed size (SetFixedSize()) if the size of the array is known beforehand. This eliminates the memory overhead for pre-allocated elements if the array works in dynamic mode. To prevent the array from pre-allocating any memory on construction call the AI_Array(0, 0) constructor.
- Version:
- 2.0 nArray was ripped from The Nebula Device and renamed to AI_Array. Now it is possible to use the class inside and outside Nebula projects.
Public Types | |
enum | { DoubleGrowSize = (1<<0) } |
behaviour flags More... | |
typedef TYPE * | iterator |
Public Member Functions | |
AI_Array () | |
constructor with default parameters | |
AI_Array (int initialSize, int initialGrow) | |
constuctor with initial size and grow size | |
AI_Array (int initialSize, int initialGrow, TYPE initialValue) | |
constructor with initial size, grow size and initial values | |
AI_Array (const AI_Array< TYPE > &rhs) | |
copy constructor | |
~AI_Array () | |
destructor | |
AI_Array< TYPE > & | operator= (const AI_Array< TYPE > &rhs) |
assignment operator | |
TYPE & | operator[] (int index) const |
[] operator | |
void | SetFlags (int f) |
equality operator | |
int | GetFlags () const |
get behaviour flags | |
void | SetFixedSize (int size) |
clear contents and set a fixed size | |
TYPE & | PushBack (const TYPE &elm) |
push element to back of array | |
TYPE & | PushBack (void) |
push empty (uninitialized) element to back of array and return added element | |
void | PopBack (void) |
remove last element | |
void | PopBack (int num) |
remove several last elements | |
void | Append (const TYPE &elm) |
append element to array (synonym for PushBack()) | |
iterator | Reserve (int num) |
reserve 'num' elements at end of array and return pointer to first element | |
int | Size () const |
get number of elements in array | |
int | AllocSize () const |
get overall allocated size of array in number of elements | |
TYPE & | Set (int index, const TYPE &elm) |
set element at index, grow array if necessary | |
TYPE & | At (int index) |
return reference to nth element in array | |
TYPE & | Front () const |
return reference to first element | |
TYPE & | Back () const |
return reference to last element | |
bool | Empty () const |
return true if array empty | |
void | Erase (int index) |
erase element at index | |
void | EraseQuick (int index) |
quick erase, does not call operator= or destructor | |
iterator | Erase (iterator iter) |
erase element pointed to by iterator | |
iterator | EraseQuick (iterator iter) |
quick erase, does not call operator= or destructor | |
void | Insert (int index, const TYPE &elm) |
insert element at index | |
void | Clear () |
clear array (calls destructors) | |
void | Reset () |
reset array (does NOT call destructors) | |
iterator | Begin () const |
return iterator to beginning of array | |
iterator | End () const |
return iterator to end of array | |
iterator | Find (const TYPE &elm) const |
find identical element in array, return iterator | |
int | FindIndex (const TYPE &elm) const |
find identical element in array, return index | |
void | Fill (int first, int num, const TYPE &elm) |
find array range with element | |
void | Reallocate (int initialSize, int grow) |
clear contents and preallocate with new attributes |
Member Typedef Documentation
Member Enumeration Documentation
Constructor & Destructor Documentation
constuctor with initial size and grow size
Note: 'grow' can be zero to create a static preallocated array.
AI_Array< TYPE >::AI_Array | ( | int | initialSize, | |
int | grow, | |||
TYPE | initialValue | |||
) | [inline] |
constructor with initial size, grow size and initial values
Note: 'grow' can be zero to create a static preallocated array.
copy constructor
Member Function Documentation
AI_Array< TYPE > & AI_Array< TYPE >::operator= | ( | const AI_Array< TYPE > & | rhs | ) | [inline] |
assignment operator
TYPE & AI_Array< TYPE >::operator[] | ( | int | index | ) | const [inline] |
[] operator
Access an element. This method will NOT grow the array, and instead do a range check, which may throw an assertion.
void AI_Array< TYPE >::SetFlags | ( | int | f | ) | [inline] |
equality operator
set behaviour flags
int AI_Array< TYPE >::GetFlags | ( | ) | const [inline] |
get behaviour flags
void AI_Array< TYPE >::SetFixedSize | ( | int | size | ) | [inline] |
clear contents and set a fixed size
Set a new fixed size. This will throw away the current content, and create preallocate a new array which cannot grow. All elements in the array will be valid.
TYPE & AI_Array< TYPE >::PushBack | ( | const TYPE & | elm | ) | [inline] |
push element to back of array
TYPE & AI_Array< TYPE >::PushBack | ( | void | ) | [inline] |
push empty (uninitialized) element to back of array and return added element
void AI_Array< TYPE >::PopBack | ( | void | ) | [inline] |
remove last element
void AI_Array< TYPE >::PopBack | ( | int | num | ) | [inline] |
remove several last elements
void AI_Array< TYPE >::Append | ( | const TYPE & | elm | ) | [inline] |
append element to array (synonym for PushBack())
reserve 'num' elements at end of array and return pointer to first element
Make room for N new elements at the end of the array, and return a pointer to the start of the reserved area. This can be (carefully!) used as a fast shortcut to fill the array directly with data.
int AI_Array< TYPE >::Size | ( | ) | const [inline] |
get number of elements in array
int AI_Array< TYPE >::AllocSize | ( | ) | const [inline] |
get overall allocated size of array in number of elements
TYPE & AI_Array< TYPE >::Set | ( | int | index, | |
const TYPE & | elm | |||
) | [inline] |
set element at index, grow array if necessary
TYPE & AI_Array< TYPE >::At | ( | int | index | ) | [inline] |
return reference to nth element in array
Access an element. This method may grow the array if the index is outside the array range.
TYPE & AI_Array< TYPE >::Front | ( | ) | const [inline] |
return reference to first element
TYPE & AI_Array< TYPE >::Back | ( | ) | const [inline] |
return reference to last element
bool AI_Array< TYPE >::Empty | ( | ) | const [inline] |
return true if array empty
void AI_Array< TYPE >::Erase | ( | int | index | ) | [inline] |
erase element at index
void AI_Array< TYPE >::EraseQuick | ( | int | index | ) | [inline] |
quick erase, does not call operator= or destructor
Quick erase, uses memmove() and does not call assignment operators or destructor, so be careful about that!
erase element pointed to by iterator
quick erase, does not call operator= or destructor
void AI_Array< TYPE >::Insert | ( | int | index, | |
const TYPE & | elm | |||
) | [inline] |
insert element at index
void AI_Array< TYPE >::Clear | ( | ) | [inline] |
clear array (calls destructors)
The current implementation of this method does not shrink the preallocated space. It simply sets the array size to 0.
void AI_Array< TYPE >::Reset | ( | ) | [inline] |
reset array (does NOT call destructors)
This is identical with Clear(), but does NOT call destructors (it just resets the numElements member. USE WITH CARE!
return iterator to beginning of array
return iterator to end of array
AI_Array< TYPE >::iterator AI_Array< TYPE >::Find | ( | const TYPE & | elm | ) | const [inline] |
find identical element in array, return iterator
Find element in array, return iterator, or 0 if element not found.
- Parameters:
-
elm element to find
- Returns:
- element iterator, or 0 if not found
int AI_Array< TYPE >::FindIndex | ( | const TYPE & | elm | ) | const [inline] |
find identical element in array, return index
Find element in array, return element index, or -1 if element not found.
- Parameters:
-
elm element to find
- Returns:
- index to element, or -1 if not found
void AI_Array< TYPE >::Fill | ( | int | first, | |
int | num, | |||
const TYPE & | elm | |||
) | [inline] |
find array range with element
Fills an array range with the given element value. Will grow the array if necessary
- Parameters:
-
first index of first element to start fill num num elements to fill elm fill value
void AI_Array< TYPE >::Reallocate | ( | int | initialSize, | |
int | grow | |||
) | [inline] |
clear contents and preallocate with new attributes
The documentation for this class was generated from the following file: