AI_Array< TYPE > Class Template Reference
[Utilities]

#include <AI_Array.h>

List of all members.


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.
(C) 2002 RadonLabs GmbH, Jindrich Rohlik

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

template<class TYPE>
typedef TYPE* AI_Array< TYPE >::iterator


Member Enumeration Documentation

template<class TYPE>
anonymous enum

behaviour flags

Enumerator:
DoubleGrowSize 


Constructor & Destructor Documentation

template<class TYPE>
AI_Array< TYPE >::AI_Array (  )  [inline]

constructor with default parameters

template<class TYPE>
AI_Array< TYPE >::AI_Array ( int  initialSize,
int  grow 
) [inline]

constuctor with initial size and grow size

Note: 'grow' can be zero to create a static preallocated array.

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

template<class TYPE>
AI_Array< TYPE >::AI_Array ( const AI_Array< TYPE > &  rhs  )  [inline]

copy constructor

template<class TYPE>
AI_Array< TYPE >::~AI_Array (  )  [inline]

destructor


Member Function Documentation

template<class TYPE>
AI_Array< TYPE > & AI_Array< TYPE >::operator= ( const AI_Array< TYPE > &  rhs  )  [inline]

assignment operator

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

template<class TYPE>
void AI_Array< TYPE >::SetFlags ( int  f  )  [inline]

equality operator

set behaviour flags

template<class TYPE>
int AI_Array< TYPE >::GetFlags (  )  const [inline]

get behaviour flags

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

template<class TYPE>
TYPE & AI_Array< TYPE >::PushBack ( const TYPE &  elm  )  [inline]

push element to back of array

template<class TYPE>
TYPE & AI_Array< TYPE >::PushBack ( void   )  [inline]

push empty (uninitialized) element to back of array and return added element

template<class TYPE>
void AI_Array< TYPE >::PopBack ( void   )  [inline]

remove last element

template<class TYPE>
void AI_Array< TYPE >::PopBack ( int  num  )  [inline]

remove several last elements

template<class TYPE>
void AI_Array< TYPE >::Append ( const TYPE &  elm  )  [inline]

append element to array (synonym for PushBack())

template<class TYPE>
AI_Array< TYPE >::iterator AI_Array< TYPE >::Reserve ( int  num  )  [inline]

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.

template<class TYPE>
int AI_Array< TYPE >::Size (  )  const [inline]

get number of elements in array

template<class TYPE>
int AI_Array< TYPE >::AllocSize (  )  const [inline]

get overall allocated size of array in number of elements

template<class TYPE>
TYPE & AI_Array< TYPE >::Set ( int  index,
const TYPE &  elm 
) [inline]

set element at index, grow array if necessary

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

template<class TYPE>
TYPE & AI_Array< TYPE >::Front (  )  const [inline]

return reference to first element

template<class TYPE>
TYPE & AI_Array< TYPE >::Back (  )  const [inline]

return reference to last element

template<class TYPE>
bool AI_Array< TYPE >::Empty (  )  const [inline]

return true if array empty

template<class TYPE>
void AI_Array< TYPE >::Erase ( int  index  )  [inline]

erase element at index

template<class TYPE>
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!

template<class TYPE>
iterator AI_Array< TYPE >::Erase ( iterator  iter  ) 

erase element pointed to by iterator

template<class TYPE>
iterator AI_Array< TYPE >::EraseQuick ( iterator  iter  ) 

quick erase, does not call operator= or destructor

template<class TYPE>
void AI_Array< TYPE >::Insert ( int  index,
const TYPE &  elm 
) [inline]

insert element at index

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

template<class TYPE>
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!

template<class TYPE>
AI_Array< TYPE >::iterator AI_Array< TYPE >::Begin (  )  const [inline]

return iterator to beginning of array

template<class TYPE>
AI_Array< TYPE >::iterator AI_Array< TYPE >::End (  )  const [inline]

return iterator to end of array

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

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

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

template<class TYPE>
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: