# TMCArray< T > Class Template Reference
[MCCore]

Inheritance diagram for TMCArray< T >:

List of all members.

## Public Types
typedef T | TTemplateType
typedef T | TValueType
| The template type on which the array is based.
typedef TMCIterator< T, TMCArray< T > > | iterator
typedef TMCConstIterator< T, TMCArray< T > > | const_iterator
## Public Member Functions
| TMCArray (void)
| A type that represents the data type stored in the array.
| TMCArray (uint32 initialCount, boolean initialZeroMem)
| TMCArray (uint32 initialCount, uint32 initialSpace, uint32 initialGrowSize, boolean initialZeroMem)
| TMCArray (const TMCArray< T > &inFromArray)
| TMCArray (T *const &baseAddress, boolean inAquireMemory, uint32 elemCount, uint32 elemSpace)
| TMCArray (TMCArray< T > &array, uint32 elemStart, uint32 elemCount)
| ~TMCArray (void)
TMCArray< T > & | operator= (const TMCArray< T > &fromArray)
void | ArrayAlias (T *baseAddress, uint32 elemCount)
| Frees existing Data, then references an existing array without taking ownership.
void | ArrayAlias (T *baseAddress, uint32 elemCount, uint32 elemSpace)
| The number of array elements in use in that memory.
void | ArrayAlias (void *baseAddress, uint32 elemCount, uint32 elemSpace)
void | ArrayAlias (TMCArray< T > &sourceArray)
void | ArrayFree (void)
boolean | IsValid (void) const
int8 * | BaseAddress (void)
const int8 * | BaseAddress (void) const
uint32 | GetElemSize (void) const
uint32 | GetGrowSize (void) const
uint32 | GetElemSpace (void) const
uint32 | GetElemCount (void) const
boolean | GetZeroMem (void) const
boolean | ExternalMemory ()
boolean | GetSmartGrow (void) const
T * | ArrayData (void)
const T * | ArrayData (void) const
boolean | IsInArray (const T *data) const
void | SetZeroMem (boolean z)
void | SetValid (boolean valid)
void | SetGrowSize (uint32 g)
void | SetSmartGrow ()
boolean | SetElemSpace (uint32 n)
boolean | SetElemCount (MCSize nAsMCSize)
boolean | AddElemCount (uint32 n)
const_iterator | Begin (void) const
iterator | Begin (void)
const_iterator | End (void) const
iterator | End (void)
T & | FirstElem (void)
const T & | FirstElem (void) const
T & | LastElem (void)
const T & | LastElem (void) const
void | Erase (const iterator &elementToErase)
void | Erase (const iterator &start, const iterator &end)
boolean | CopyElems (const TMCArray< T > &fromArray, uint32 startIndex, uint32 nbItems, uint32 insertIndex)
boolean | Append (const TMCArray< T > &fromArray)
void | FillWithValue (const T &inValue, uint32 inStart=kBeginIndex, uint32 inLength=kUnusedIndex)
void | Swap (TMCArray< T > &fromArray)
T * | Pointer (MCSize i)
const T * | Pointer (MCSize i) const
T & | operator[] (MCSize i)
const T & | operator[] (MCSize i) const
void | Assign (int32 elemCount, const T &value)
| Sets the value of a number of elements of the array, grows the array if necessary.
void | AssignArithmeticalSuite (int32 elemCount, const T &u0, const T &a)
void | SetElem (uint32 index, const T &data)
void | GetElem (uint32 index, T &data) const
boolean | AddElem (const T &data)
boolean | InsertElem (uint32 index, const T &data)
boolean | InsertElem (uint32 index, uint32 count, const T &data)
void | RemoveElem (MCSize index, MCSize count)
uint32 | FindElem (const T &item) const
int32 | DichoSearch (const int32 beginIndex, const int32 endIndex, const T &item) const
int32 | DichoSearch (const T &item) const
boolean | CompactArray (void)
void | ReorderArray (const TMCArray< int32 > &reoderedIndex)
## Protected Member Functions
boolean | ArrayAlloc (uint32 initialCount, uint32 initialSpace, uint32 initialGrowSize, boolean initialZeroMem)
boolean | ArrayAllocFromBuffer (T *baseAddress, boolean inAquireMemory, uint32 elemCount, uint32 elemSpace)
void | UpdateDataPointer (void)
void | ZeroInternals (void)
## Protected Attributes
uint32 | fElemCount
| The number of elements in use.
uint32 | fElemSpace
| The number of elements allocated (unconstructed).
uint32 | fArrayFlags
| Flags that control the behavior of the array.
T * | fArrayData
| The memory block used by the array.

## Detailed Description

### template<class T>
class TMCArray< T >

TMCArray is an array used to store simple types, structs or classes that don't need a constructor nor a destructor. For example, you can use it with int32, TVector3, TMCString255, but not with TMCDynamicString (memory leaks on destruction).

Indexes to access the Array classes are ZERO based (array[0] gives you the first element)

Arrays grows dynamically as you add elements, so it is very dangerous to keep pointers to elements of the array: if the array is reallocated, your pointers will become invalid. In this case, you should use indexes. For better efficiency, preallocate the number of elements you'll need (or use an estimation of the space if possible).
In eSmartGrow mode (the default), the size of the extra space added when the array is reallocated (the grow size) depends on the number of elements already in the array. Otherwise, a constant grow size is used.

Other array classes are: TMCPtrArray, TMCCountedPtrArray, TMCClassArray and TMCExtensibleArray, TMCStaticArray and TMCStaticClassArray.

## Member Typedef Documentation

template<class T>

typedef TMCConstIterator<T, TMCArray<T> > TMCArray< T >::const_iterator

template<class T>

typedef TMCIterator<T, TMCArray<T> > TMCArray< T >::iterator

Declare iterator types for this array

template<class T>

typedef T TMCArray< T >::TTemplateType

template<class T>

typedef T TMCArray< T >::TValueType

The template type on which the array is based.

## Constructor & Destructor Documentation

template<class T >

TMCArray< T >::TMCArray | ( | void |  | ) | `[inline]`

A type that represents the data type stored in the array.

Creates an empty array

template<class T >

TMCArray< T >::TMCArray | ( | uint32 | initialCount,
|  | boolean | initialZeroMem |
| ) |  |  | `[inline]`

Constructs an array with a certain number of elements already accessible

Parameters:

  | initialCount | initial number of array elements.
  | initialZeroMem | Zero the memory allocated for array storage ?

template<class T >

TMCArray< T >::TMCArray | ( | uint32 | initialCount,
|  | uint32 | initialSpace,
|  | uint32 | initialGrowSize,
|  | boolean | initialZeroMem |
| ) |  |  | `[inline]`

Constructs an array with a certain number of elements already accessible, and/or some extra space to extend the array without reallocating it.

Note:
  This constructor turns off eSmartGrow, so the grow size is constant

Parameters:

  | initialCount | Initial number of array elements.
  | initialSpace | Pre-allocate space for this many elements (must be bigger than initialCount).
  | initialGrowSize | How many elements to grow the array when we grow past the end
  | initialZeroMem | Zero the memory allocated for array storage ?

template<class T>

TMCArray< T >::TMCArray | ( | const TMCArray< T > & | inFromArray | ) | `[inline]`

Copy constructor: Construct an array from an existing array.

template<class T>

TMCArray< T >::TMCArray | ( | T *const & | baseAddress,
|  | boolean | inAquireMemory,
|  | uint32 | elemCount,
|  | uint32 | elemSpace |
| ) |  |  | `[inline]`

Constructs an array from existing memory.

Note:
  : If you pass inAquireMemory = false then this array CANNOT grow past elemSpace, and will not free the memory passed in.

Parameters:

  | baseAddress | External memory to use for this array.
  | inAquireMemory | Should we take possession this memory.
  | elemCount | The number of array elements in use in that memory.
  | elemSpace | The number of array elements that can be used in that memory.

template<class T>

TMCArray< T >::TMCArray | ( | TMCArray< T > & | array,
|  | uint32 | elemStart,
|  | uint32 | elemCount |
| ) |  |  | `[inline]`

Constructs an alias to an existing array.

Note:
  : This array CANNOT grow past elemSpace, and will not free the memory passed in. Also this array is an alias to the array passed in NOT a copy so be carefull.

Parameters:

  | array | Alias elements from this array.
  | elemStart | Start alias here.
  | elemCount | Alias this many elements.

template<class T >

TMCArray< T >::~TMCArray | ( | void |  | ) | `[inline]`

Frees the memory used by the array (if it owns it).

## Member Function Documentation

template<class T>

boolean TMCArray< T >::AddElem | ( | const T & | data | ) | `[inline]`

Add an element to the end of the array and assign it the data reference that is passed in.

template<class T >

boolean TMCArray< T >::AddElemCount | ( | uint32 | n | ) | `[inline]`

Adds the passed in number of elements to the array.

template<class T>

boolean TMCArray< T >::Append | ( | const TMCArray< T > & | fromArray | ) | `[inline]`

Append one array on to the end of another.

template<class T>

void TMCArray< T >::ArrayAlias | ( | TMCArray< T > & | sourceArray | ) | `[inline]`

template<class T>

void TMCArray< T >::ArrayAlias | ( | void * | baseAddress,
|  | uint32 | elemCount,
|  | uint32 | elemSpace |
| ) |  |  | `[inline]`

The number of array elements in use in that memory.

Parameters:

  | elemCount | External memory to use for this array.

template<class T>

void TMCArray< T >::ArrayAlias | ( | T * | baseAddress,
|  | uint32 | elemCount,
|  | uint32 | elemSpace |
| ) |  |  | `[inline]`

The number of array elements in use in that memory.

Parameters:

  | elemCount | External memory to use for this array.

template<class T>

void TMCArray< T >::ArrayAlias | ( | T * | baseAddress,
|  | uint32 | elemCount |
| ) |  |  | `[inline]`

Frees existing Data, then references an existing array without taking ownership.

Parameters:

  | elemCount | External memory to use for this array.

template<class T >

boolean TMCArray< T >::ArrayAlloc | ( | uint32 | initialCount,
|  | uint32 | initialSpace,
|  | uint32 | initialGrowSize,
|  | boolean | initialZeroMem |
| ) |  |  | `[inline, protected]`

!!! DO NOT CALL THIS !!!

template<class T>

boolean TMCArray< T >::ArrayAllocFromBuffer | ( | T * | baseAddress,
|  | boolean | inAquireMemory,
|  | uint32 | elemCount,
|  | uint32 | elemSpace |
| ) |  |  | `[inline, protected]`

!!! DO NOT CALL THIS !!!

template<class T>

const T* TMCArray< T >::ArrayData | ( | void |  | ) | const`[inline]`

Returns a pointer to the first element

template<class T>

T* TMCArray< T >::ArrayData | ( | void |  | ) | `[inline]`

Returns a pointer to the first element

template<class T >

void TMCArray< T >::ArrayFree | ( | void |  | ) | `[inline]`

Frees all the memory held by this array (unless it uses external memory). And sets the element count to 0.

template<class T>

void TMCArray< T >::Assign | ( | int32 | elemCount,
|  | const T & | value |
| ) |  |  | `[inline]`

Sets the value of a number of elements of the array, grows the array if necessary.

Sets the value of a number of elements of the array.

template<class T>

void TMCArray< T >::AssignArithmeticalSuite | ( | int32 | elemCount,
|  | const T & | u0,
|  | const T & | a |
| ) |  |  | `[inline]`

template<class T>

const int8* TMCArray< T >::BaseAddress | ( | void |  | ) | const`[inline]`

Returns the address at which the elements of the array begin

template<class T>

int8* TMCArray< T >::BaseAddress | ( | void |  | ) | `[inline]`

Returns the address at which the elements of the array begin

template<class T>

iterator TMCArray< T >::Begin | ( | void |  | ) | `[inline]`

Returns an iterator initialized to the beginning of the array.

template<class T>

const_iterator TMCArray< T >::Begin | ( | void |  | ) | const`[inline]`

Returns an iterator initialized to the beginning of the array.

template<class T>

boolean TMCArray< T >::CompactArray | ( | void |  | ) | `[inline]`

Get rid of any space that has been allocated by the array and isn't being used.

template<class T>

boolean TMCArray< T >::CopyElems | ( | const TMCArray< T > & | fromArray,
|  | uint32 | startIndex,
|  | uint32 | nbItems,
|  | uint32 | insertIndex |
| ) |  |  | `[inline]`

Copy elements from one array to another.

template<class T>

int32 TMCArray< T >::DichoSearch | ( | const T & | item | ) | const`[inline]`

template<class T>

int32 TMCArray< T >::DichoSearch | ( | const int32 | beginIndex,
|  | const int32 | endIndex,
|  | const T & | item |
| ) |  |  | const`[inline]`

Finds the index of an instance of item in the array.

Returns:
  kUnusedIndex if item is not in the array, otherwise a valid index

template<class T>

iterator TMCArray< T >::End | ( | void |  | ) | `[inline]`

Returns an iterator initialized to the end of the array.

template<class T>

const_iterator TMCArray< T >::End | ( | void |  | ) | const`[inline]`

Returns an iterator initialized to the end of the array.

template<class T >

void TMCArray< T >::Erase | ( | const iterator & | start,
|  | const iterator & | end |
| ) |  |  | `[inline]`

Erases a range of elements in the array from the startIterator to the endIterator.

template<class T>

void TMCArray< T >::Erase | ( | const iterator & | elementToErase | ) | `[inline]`

Erases a single element in the array that is referenced by the iterator.

template<class T>

boolean TMCArray< T >::ExternalMemory | ( |  | ) | `[inline]`

Returns true if the array doesn't own its memory

template<class T>

void TMCArray< T >::FillWithValue | ( | const T & | inValue,
|  | uint32 | inStart = `kBeginIndex`,
|  | uint32 | inLength = `kUnusedIndex` |
| ) |  |  | `[inline]`

Fill an array range with the value passed in.

template<class T>

uint32 TMCArray< T >::FindElem | ( | const T & | item | ) | const`[inline]`

Finds the index of the first instance of item in the array (if it exists).

Parameters:

  | item | the item to serch for

Returns:
  kUnusedIndex if item is not in the array, otherwise a valid index

template<class T>

const T& TMCArray< T >::FirstElem | ( | void |  | ) | const`[inline]`

Returns a reference to the first element in the array.

template<class T>

T& TMCArray< T >::FirstElem | ( | void |  | ) | `[inline]`

Returns a reference to the first element in the array.

template<class T>

void TMCArray< T >::GetElem | ( | uint32 | index,
|  | T & | data |
| ) |  |  | const`[inline]`

Get the contents of arrray index into the passed in data reference.

template<class T>

uint32 TMCArray< T >::GetElemCount | ( | void |  | ) | const`[inline]`

Returns the actual number of (valid) elements in the array. Those elements can be accessed with the operator []

template<class T>

uint32 TMCArray< T >::GetElemSize | ( | void |  | ) | const`[inline]`

Returns the size of one element

template<class T>

uint32 TMCArray< T >::GetElemSpace | ( | void |  | ) | const`[inline]`

Returns the number of elements that can be stored in the array (before the next reallocation)

template<class T>

uint32 TMCArray< T >::GetGrowSize | ( | void |  | ) | const`[inline]`

Returns the size by which the array grows

template<class T>

boolean TMCArray< T >::GetSmartGrow | ( | void |  | ) | const`[inline]`

Returns true if the grow size is dynamic

template<class T>

boolean TMCArray< T >::GetZeroMem | ( | void |  | ) | const`[inline]`

Returns true if the newly allocated memory should be initialized with zero

template<class T>

boolean TMCArray< T >::InsertElem | ( | uint32 | index,
|  | uint32 | count,
|  | const T & | data |
| ) |  |  | `[inline]`

Inserts elements at the given index

Parameters:

  | index | where to insert
  | count | number to insert
  | data | the data to insert

template<class T>

boolean TMCArray< T >::InsertElem | ( | uint32 | index,
|  | const T & | data |
| ) |  |  | `[inline]`

Inserts one element at the given index

Parameters:

  | index | where to insert
  | data | the data to insert

template<class T>

boolean TMCArray< T >::IsInArray | ( | const T * | data | ) | const`[inline]`

Returns true if the element is in the array

template<class T>

boolean TMCArray< T >::IsValid | ( | void |  | ) | const`[inline]`

IsValid(): Check to see if the class is valid.

template<class T>

const T& TMCArray< T >::LastElem | ( | void |  | ) | const`[inline]`

Returns a reference to the last element in the array.

template<class T>

T& TMCArray< T >::LastElem | ( | void |  | ) | `[inline]`

Returns a reference to the last element in the array.

template<class T>

TMCArray< T > & TMCArray< T >::operator= | ( | const TMCArray< T > & | fromArray | ) | `[inline]`

operator= Assignment operator copies all the data from one array to another.

template<class T>

const T& TMCArray< T >::operator[] | ( | MCSize | i | ) | const`[inline]`

Returns a reference to the data at the passed in index.

template<class T>

T& TMCArray< T >::operator[] | ( | MCSize | i | ) | `[inline]`

Returns a reference to the data at the passed in index.

template<class T>

const T* TMCArray< T >::Pointer | ( | MCSize | i | ) | const`[inline]`

Returns a pointer to the data at the passed in index.

template<class T>

T* TMCArray< T >::Pointer | ( | MCSize | i | ) | `[inline]`

Returns a pointer to the data at the passed in index.

template<class T >

void TMCArray< T >::RemoveElem | ( | MCSize | index,
|  | MCSize | count |
| ) |  |  | `[inline]`

Remove one or more elements from the array starting from the passed in index.

template<class T >

void TMCArray< T >::ReorderArray | ( | const TMCArray< int32 > & | reoderedIndex | ) | `[inline]`

template<class T>

void TMCArray< T >::SetElem | ( | uint32 | index,
|  | const T & | data |
| ) |  |  | `[inline]`

Set the contents of arrray index to the passed in data reference.

template<class T >

boolean TMCArray< T >::SetElemCount | ( | MCSize | nAsMCSize | ) | `[inline]`

Set the number of elements in the array.

template<class T >

boolean TMCArray< T >::SetElemSpace | ( | uint32 | n | ) | `[inline]`

Sets the number of elements to have memory allocated for.

Note:
  This memory is unconstructed, uninitialized (if GetZeroMem is false) and isn't considered part of the array until the element count reaches the memory.

template<class T>

void TMCArray< T >::SetGrowSize | ( | uint32 | g | ) | `[inline]`

Sets the growSize (and sets the eSmartGrow flag to false)

template<class T>

void TMCArray< T >::SetSmartGrow | ( |  | ) | `[inline]`

Sets the eSmartGrow flag and computes the maximum grow size (in elements count)

template<class T>

void TMCArray< T >::SetValid | ( | boolean | valid | ) | `[inline]`

Sets the valid flag to true

template<class T>

void TMCArray< T >::SetZeroMem | ( | boolean | z | ) | `[inline]`

Sets whether the newly allocated memory should be initialized with zero

template<class T>

void TMCArray< T >::Swap | ( | TMCArray< T > & | fromArray | ) | `[inline]`

Swaps the contents of two arrays.

template<class T>

void TMCArray< T >::UpdateDataPointer | ( | void |  | ) | `[inline, protected]`

template<class T>

void TMCArray< T >::ZeroInternals | ( | void |  | ) | `[inline, protected]`

## Member Data Documentation

template<class T>

T* TMCArray< T >::fArrayData`[protected]`

The memory block used by the array.

template<class T>

uint32 TMCArray< T >::fArrayFlags`[protected]`

Flags that control the behavior of the array.

template<class T>

uint32 TMCArray< T >::fElemCount`[protected]`

The number of elements in use.

template<class T>

uint32 TMCArray< T >::fElemSpace`[protected]`

The number of elements allocated (unconstructed).

The documentation for this class was generated from the following file:

- MCArray.h