newspeoplefor developersdocumentationdownloads

nArray< TYPE > Class Template Reference
[Data Types]

#include <narray.h>

Inheritance diagram for nArray< TYPE >:

nAnimKeyArray< TYPE > nThreadSafeArray< TYPE > List of all members.

Detailed Description

template<class TYPE>
class nArray< 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 nArray(0, 0) constructor.

(C) 2002 RadonLabs GmbH

Definition at line 23 of file narray.h.


Public Types

typedef TYPE * iterator
enum  { DoubleGrowSize = (1<<0) }
 behavior flags More...

Public Member Functions

 nArray ()
 constructor with default parameters
 nArray (int initialSize, int initialGrow)
 constructor with initial size and grow size
 nArray (int initialSize, int initialGrow, const TYPE &initialValue)
 constructor with initial size, grow size and initial values
 nArray (const nArray< TYPE > &rhs)
 copy constructor
 ~nArray ()
 destructor
nArray< TYPE > & operator= (const nArray< TYPE > &rhs)
 assignment operator
TYPE & operator[] (int index) const
 [] operator
bool operator== (const nArray< TYPE > &rhs) const
 equality operator
bool operator!= (const nArray< TYPE > &rhs) const
 inequality operator
void SetFlags (int f)
 set behavior flags
int GetFlags () const
 get behavior flags
void SetFixedSize (int size)
 clear contents and set a fixed size
TYPE & PushBack (const TYPE &elm)
 push element to back of array
void Append (const TYPE &elm)
 append element to array (synonym for PushBack())
void AppendArray (const nArray< TYPE > &rhs)
 append the contents of an array to this array
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 InsertSorted (const TYPE &elm)
 insert element into sorted array
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
nArray< TYPE > Difference (const nArray< TYPE > &rhs) const
 returns new array with elements which are not in rhs (slow!)
void Sort ()
 sort the array
int BinarySearchIndex (const TYPE &elm) const
 do a binary search, requires a sorted array

Member Typedef Documentation

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

Definition at line 26 of file narray.h.


Member Enumeration Documentation

template<class TYPE>
anonymous enum
 

behavior flags

Enumerator:
DoubleGrowSize 

Definition at line 29 of file narray.h.


Constructor & Destructor Documentation

template<class TYPE>
nArray< TYPE >::nArray  ) 
 

constructor with default parameters

Definition at line 149 of file narray.h.

template<class TYPE>
nArray< TYPE >::nArray int  initialSize,
int  grow
 

constructor with initial size and grow size

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

Definition at line 163 of file narray.h.

template<class TYPE>
nArray< TYPE >::nArray int  initialSize,
int  grow,
const TYPE &  initialValue
 

constructor with initial size, grow size and initial values

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

Definition at line 185 of file narray.h.

template<class TYPE>
nArray< TYPE >::nArray const nArray< TYPE > &  rhs  ) 
 

copy constructor

Definition at line 294 of file narray.h.

template<class TYPE>
nArray< TYPE >::~nArray  ) 
 

destructor

Definition at line 308 of file narray.h.


Member Function Documentation

template<class TYPE>
nArray< TYPE > & nArray< TYPE >::operator= const nArray< TYPE > &  rhs  ) 
 

assignment operator

Definition at line 379 of file narray.h.

template<class TYPE>
TYPE & nArray< TYPE >::operator[] int  index  )  const
 

[] operator

Access an element. This method will NOT grow the array, and instead do a range check, which may throw an assertion.

Definition at line 724 of file narray.h.

template<class TYPE>
bool nArray< TYPE >::operator== const nArray< TYPE > &  rhs  )  const
 

equality operator

The equality operator returns true if all elements are identical. The TYPE class must support the equality operator.

Definition at line 737 of file narray.h.

template<class TYPE>
bool nArray< TYPE >::operator!= const nArray< TYPE > &  rhs  )  const
 

inequality operator

The inequality operator returns true if at least one element in the array is different, or the array sizes are different.

Definition at line 762 of file narray.h.

template<class TYPE>
void nArray< TYPE >::SetFlags int  f  ) 
 

set behavior flags

Definition at line 318 of file narray.h.

template<class TYPE>
int nArray< TYPE >::GetFlags  )  const
 

get behavior flags

Definition at line 328 of file narray.h.

template<class TYPE>
void nArray< TYPE >::SetFixedSize int  size  ) 
 

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.

Definition at line 362 of file narray.h.

template<class TYPE>
TYPE & nArray< TYPE >::PushBack const TYPE &  elm  ) 
 

push element to back of array

Definition at line 568 of file narray.h.

template<class TYPE>
void nArray< TYPE >::Append const TYPE &  elm  ) 
 

append element to array (synonym for PushBack())

Definition at line 585 of file narray.h.

template<class TYPE>
void nArray< TYPE >::AppendArray const nArray< TYPE > &  rhs  ) 
 

append the contents of an array to this array

Definition at line 601 of file narray.h.

template<class TYPE>
nArray< TYPE >::iterator nArray< TYPE >::Reserve int  num  ) 
 

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.

Definition at line 623 of file narray.h.

template<class TYPE>
int nArray< TYPE >::Size  )  const
 

get number of elements in array

Definition at line 689 of file narray.h.

template<class TYPE>
int nArray< TYPE >::AllocSize  )  const
 

get overall allocated size of array in number of elements

Definition at line 699 of file narray.h.

template<class TYPE>
TYPE & nArray< TYPE >::Set int  index,
const TYPE &  elm
 

set element at index, grow array if necessary

  • 12-05-2004 brucem Close bug #203 by removing an assert that prevented this from auto-growing. Assumed intent was for auto-growth given the use of CheckIndex.

Definition at line 677 of file narray.h.

template<class TYPE>
TYPE & nArray< TYPE >::At int  index  ) 
 

return reference to nth element in array

Access an element. This method may grow the array if the index is outside the array range.

Definition at line 711 of file narray.h.

template<class TYPE>
TYPE & nArray< TYPE >::Front  )  const
 

return reference to first element

Definition at line 772 of file narray.h.

template<class TYPE>
TYPE & nArray< TYPE >::Back  )  const
 

return reference to last element

Definition at line 783 of file narray.h.

template<class TYPE>
bool nArray< TYPE >::Empty  )  const
 

return true if array empty

Definition at line 794 of file narray.h.

template<class TYPE>
void nArray< TYPE >::Erase int  index  ) 
 

erase element at index

Definition at line 804 of file narray.h.

template<class TYPE>
void nArray< TYPE >::EraseQuick int  index  ) 
 

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!

Definition at line 827 of file narray.h.

template<class TYPE>
iterator nArray< TYPE >::Erase iterator  iter  ) 
 

erase element pointed to by iterator

template<class TYPE>
iterator nArray< TYPE >::EraseQuick iterator  iter  ) 
 

quick erase, does not call operator= or destructor

template<class TYPE>
void nArray< TYPE >::Insert int  index,
const TYPE &  elm
 

insert element at index

Definition at line 873 of file narray.h.

template<class TYPE>
void nArray< TYPE >::InsertSorted const TYPE &  elm  ) 
 

insert element into sorted array

This inserts the element into a sorted array. In the current implementation this is a slow operation O(n). This should be optimized to O(log n).

Definition at line 1118 of file narray.h.

template<class TYPE>
void nArray< TYPE >::Clear  ) 
 

clear array (calls destructors)

The current implementation of this method does not shrink the preallocated space. It simply sets the array size to 0.

Definition at line 895 of file narray.h.

template<class TYPE>
void nArray< TYPE >::Reset  ) 
 

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!

Definition at line 912 of file narray.h.

template<class TYPE>
nArray< TYPE >::iterator nArray< TYPE >::Begin  )  const
 

return iterator to beginning of array

Definition at line 922 of file narray.h.

template<class TYPE>
nArray< TYPE >::iterator nArray< TYPE >::End  )  const
 

return iterator to end of array

Definition at line 932 of file narray.h.

template<class TYPE>
nArray< TYPE >::iterator nArray< TYPE >::Find const TYPE &  elm  )  const
 

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

Definition at line 947 of file narray.h.

template<class TYPE>
int nArray< TYPE >::FindIndex const TYPE &  elm  )  const
 

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

Definition at line 970 of file narray.h.

template<class TYPE>
void nArray< TYPE >::Fill int  first,
int  num,
const TYPE &  elm
 

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

Definition at line 994 of file narray.h.

template<class TYPE>
void nArray< TYPE >::Reallocate int  initialSize,
int  grow
 

clear contents and preallocate with new attributes

Definition at line 338 of file narray.h.

template<class TYPE>
nArray< TYPE > nArray< TYPE >::Difference const nArray< TYPE > &  rhs  )  const
 

returns new array with elements which are not in rhs (slow!)

Returns a new array with all element which are in rhs, but not in this. Be careful, this method may be very slow with large arrays!

Definition at line 1028 of file narray.h.

template<class TYPE>
void nArray< TYPE >::Sort  ) 
 

sort the array

Sorts the array. This just calls the STL sort algorithm.

Definition at line 1049 of file narray.h.

template<class TYPE>
int nArray< TYPE >::BinarySearchIndex const TYPE &  elm  )  const
 

do a binary search, requires a sorted array

Does a binary search on the array, returns the index of the identical element, or -1 if not found

Definition at line 1061 of file narray.h.


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

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.