nArray< TYPE > Class Template Reference
[Data Types]
#include <narray.h>
Inheritance diagram for nArray< TYPE >:

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
|
|||||
|
|
Member Enumeration Documentation
|
|||||
|
behavior flags
|
Constructor & Destructor Documentation
|
|||||||||
|
constructor with default parameters
|
|
||||||||||||||||
|
constructor with initial size and grow size Note: 'grow' can be zero to create a static preallocated array. |
|
||||||||||||||||||||
|
constructor with initial size, grow size and initial values Note: 'grow' can be zero to create a static preallocated array. |
|
||||||||||
|
copy constructor
|
|
|||||||||
|
destructor
|
Member Function Documentation
|
||||||||||
|
assignment operator
|
|
||||||||||
|
[] operator Access an element. This method will NOT grow the array, and instead do a range check, which may throw an assertion. |
|
||||||||||
|
equality operator The equality operator returns true if all elements are identical. The TYPE class must support the equality operator. |
|
||||||||||
|
inequality operator The inequality operator returns true if at least one element in the array is different, or the array sizes are different. |
|
||||||||||
|
set behavior flags
|
|
|||||||||
|
get behavior flags
|
|
||||||||||
|
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. |
|
||||||||||
|
push element to back of array
|
|
||||||||||
|
append element to array (synonym for PushBack())
|
|
||||||||||
|
append the contents of an array to this array
|
|
||||||||||
|
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. |
|
|||||||||
|
get number of elements in array
|
|
|||||||||
|
get overall allocated size of array in number of elements
|
|
||||||||||||||||
|
set element at index, grow array if necessary
|
|
||||||||||
|
return reference to nth element in array Access an element. This method may grow the array if the index is outside the array range. |
|
|||||||||
|
return reference to first element
|
|
|||||||||
|
return reference to last element
|
|
|||||||||
|
return true if array empty
|
|
||||||||||
|
erase element at 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! |
|
||||||||||
|
erase element pointed to by iterator
|
|
||||||||||
|
quick erase, does not call operator= or destructor
|
|
||||||||||||||||
|
insert element at index
|
|
||||||||||
|
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). |
|
|||||||||
|
clear array (calls destructors) The current implementation of this method does not shrink the preallocated space. It simply sets the array size to 0. |
|
|||||||||
|
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
|
|
||||||||||
|
find identical element in array, return iterator Find element in array, return iterator, or 0 if element not found.
|
|
||||||||||
|
find identical element in array, return index Find element in array, return element index, or -1 if element not found.
|
|
||||||||||||||||||||
|
find array range with element Fills an array range with the given element value. Will grow the array if necessary
|
|
||||||||||||||||
|
clear contents and preallocate with new attributes
|
|
||||||||||
|
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! |
|
|||||||||
|
sort the array Sorts the array. This just calls the STL sort algorithm. |
|
||||||||||
|
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 |
The documentation for this class was generated from the following file: