![]() |
Houdini Development Toolkit - Version 6.5Side Effects Software Inc. 2004 |
This is a class template that implements a resizable array of pointers to arbitrary objects. The template parameter <Thing> represents the type of object, and is called Thing. You can instantiate this class with a pointer to any object or type, such as:
UT_PtrArray<GeoPoint*> myPtrArray1; UT_PtrArray<const char*> myPtrArray2;
constructors
The default constructor does not allocate any memory for the array. If you know the size of the array a priori, you can pass it to the constructor as an integer.
A copy constructor is also provided.
unsigned int append()
Appends an uninitialised element to the current entries and returns its index in the array.
unsigned int append(Thing t)
Appends the given element to the current entries and returns its index in the array.
unsigned int insert(unsigned idx)
Inserts an uninitialised element at the specified position, shifting the rest of the elements to make space for the new element. Returns the given index.
unsigned int insert(Thing T, unsigned idx)
Inserts the given element at the specified position, shifting the rest of the elements to make space for the new element. Returns the given index.
unsigned int multipleInsert(unsigned idx, unsigned count)
Inserts an uninitialised element count times starting at position idx. Returns the given index.
int remove(Thing t)
Remove the given element from the list and fill the gap by shifting the subsequent elements down by one position. Returns the index if successful.
int remove(unsigned idx)
As above, except specify the element by its index
unsigned int entries()
Return the number of elements in the array.
unsigned int size()
Return the number of elements that we have allocated space for. This is at least entries(), but possibly more because UT_PtrArray grows the array in chucks.
int resize(unsigned sz, unsigned short copyFlag=1)
Shrink or grow the array to sz elements. If the copyFlag is 1 (default), the data in the array is copied to the newly sized array.
int find(Thing t, unsigned s=0)
Search for the given element starting at index s. Return the found elements index if found, -1 otherwise.
Thing last()
return the last entry in the array.
=
Assign one array to another array by copying each element using pointer assignment.
==
compare two arrays and return 1 if they are equal, 0 otherwise. Two elements are compared using the pointer '==' operator. Arrays of different size by equal number of entries are checked for member-wise equality.
[],()
subscript operators to access or overwrite the element at the given position. Warning: No bound checking is done if you request a subscript that is out of range.
unsigned int apply(int (*fcn)(Thing t, void *d), void *d)
Apply the given function fcn to each element of the array as long as the function returns 0. If the fcn returns 1, apply() stops traversing the list and returns the current index. Otherwise, on success apply() returns the number of entries in the array.
... UT_PtrArray<UT_String *> string_array; UT_String *string_ptr; int i; for( i=9; i>=0; i-- ) { string_ptr = new UT_String( "foo" ); string_array.append( string_ptr ); } for( i=9; i>=0; i-- ) { cerr << *string_array( i ) << endl; } ...