Public Member Functions | |
| vtArray (unsigned int size=0) | |
| vtArray (const vtArray< E > &) | |
| virtual | ~vtArray () |
| unsigned int | GetSize () const |
| unsigned int | GetMaxSize () const |
| bool | SetSize (unsigned int) |
| bool | SetMaxSize (unsigned int) |
| unsigned int | GetElemSize () const |
| E * | GetData () const |
| bool | IsEmpty () const |
| E & | GetAt (unsigned int i) const |
| bool | SetAt (unsigned int i, E) |
| vtArray< E > & | operator= (const vtArray< E > &) |
| E & | operator[] (unsigned int i) |
| const E & | operator[] (unsigned int i) const |
| void | Empty () |
| bool | RemoveAt (unsigned int i, int n=1) |
| int | Append (const E &) |
| int | Append (const vtArray< E > &) |
| int | Find (const E &) const |
Protected Member Functions | |
| virtual bool | Grow (unsigned int) |
| virtual void | DestructItems (unsigned int first, unsigned int last) |
Protected Attributes | |
| unsigned int | m_Size |
| unsigned int | m_MaxSize |
| E * | m_Data |
Note that construction and destruction is not done automatically if the entities are class objects. You can provide this destruction yourself by overriding the DestructItems method, but it is easier to use this template for objects with simple value semantics such as basic types (int, float..), structs, and pointers. If you do create a subclass like this:
class MyArray : public vtArray<MyObject *> {};
A full working example is:
class MyArray : public vtArray<MyObject *> { virtual ~MyArray() { Empty(); free(m_Data); m_Data = NULL; m_MaxSize = 0; } virtual void DestructItems(unsigned int first, unsigned int last) { for (unsigned int i = first; i <= last; i++) delete GetAt(i); } };
|
||||||||||
|
Creates and initializes an empty array (array with no elements).
|
|
||||||||||
|
Creates and initializes an array from another (of the same type).
|
|
|||||||||
|
Destructor for array class. |
|
||||||||||
|
Concatenates the contents of the source array into the destination array. The destination array is enlarged if possible. When an object array is appended, the objects are multiply referenced (not duplicated).
|
|
||||||||||
|
Appends one element onto the end of the array. If the array is dynamically managed, it is enlarged to accomodate another element if necessary.
|
|
||||||||||||||||
|
Called by the array implementation when array items are deleted. The default implementation does _not_ call the destructors for the array items. This will not work if your array elements do memory deallocation in their destructors. Override this function to explicitly call the destructors properly if you need this functionality.
|
|
|||||||||
|
Removes the elements in the array but not the array data area. An array is considered empty if it has no elements.
|
|
||||||||||
|
Compares each element of the array to the input element and returns the index of the first one that matches. Comparison of elements is done using operator== (which must be defined for your element class if you want to use Find).
|
|
||||||||||
|
Gets the i'th element of the array.
|
|
||||||||||
|
Enlarge the array to accomodate growto elements. If the array can already hold this many elements, nothing is done. Otherwise, the data area of the array is enlarged (reallocating if necessary) so that growto contiguous elements can be stored.
|
|
|||||||||
|
Determines whether an array has elements or not
|
|
||||||||||||||||
|
Removes the i'th element of the array. The following elements are shuffled up to eliminate the unused space.
|
|
||||||||||||||||
|
Sets the i'th element of the array to the given value. The number of bytes copied is determined by the element size of the array specified at initialization time. If the array is not large enough, it is extended to become 1 1/2 times its current size.
|
|
||||||||||
|
If the array is user-managed, MaxSize establishes the maximum number of elements that can be stored. If the array is dynamically managed by the system, setting the maximum size enlarges its data area to accomodate the required number of elements.
|
|
||||||||||
|
Set the current array size. If the array is dynamically managed, it will be enlarged to accomodate the new size. If not, the array size cannot be set beyond the current maximum size. When the array size is enlarged, we should call constructors for the new empty elements. We don't do that yet.
|
1.4.5