#include <cascade/util/CascadeArray.h>
Inheritance diagram for CascadeArray:
Public Types | |
typedef int() | ArraySortFunction (const void *inItem1, const void *inItem2) |
Public Member Functions | |
CascadeArray (u32 inItemSize, u32 inDesiredItemCount=0) | |
virtual | ~CascadeArray () |
destructor | |
u32 | Count () const |
virtual bool | Append (void *inItem, u32 &outIndex) |
virtual bool | Insert (void *inItem, u32 &ioIndex) |
virtual bool | Remove (void *inItemToRemove) |
bool | RemoveAtIndex (u32 inIndex) |
void | Empty (void) |
bool | Swap (u32 inIndex1, u32 inIndex2) |
bool | AdjustAllocation (u32 inDesiredItemCount) |
true if both items were found and swapped, false otherwise | |
void | TrimAllocation (void) |
virtual bool | FetchItem (u32 inIndex, void *outItem) const |
virtual void | Sort (ArraySortFunction *inFunction) |
Protected Attributes | |
u32 | mItemSize |
u32 | mArraySize |
u32 | mCount |
void * | mData |
Implements an array of aribtrary-sized (but uniformly-sized within a single array) objects in a contiguous memory buffer. Access and append operations are fast. Insertion and removal may require moving other array items in memory. For faster insert/removal/sort and somewhat slower access, consider CascadeList [not yet implemented].
Memory allocation for array storage is automatic, using a strategy of doubling the array size when it needs to grow. The AdjustAllocation() function is provided for instances where the approximate number of items is known in advance of inserting items. TrimAllocation() can also be called to compact the allocated memory to house only items currently in the array, when further additions to the array are not anticipated.
|
sorting comparison function prototype The Sort function must be passed a comparison function suitable for comparing the type of data in the array. This is the prototype.
|
|
constructor Constructs an array of items of size inItemSize
|
|
destructor
|
|
true if both items were found and swapped, false otherwise re-size internal storage Re-sizes the array's internal storage. This function may be called if the approximate size of the array is known, to avoid multiple resizings as items are added. May fail if memory allocation fails.
|
|
append an item to the array Append the supplied item to the array. This may fail because memory may have to be allocated to hold the new item. The index of the newly-appended item is returned in the outIndex parameter if the append was successful
Reimplemented in CascadeTemplateArray< T >, CascadeTemplateArray< Vessel * >, CascadeTemplateArray< TimerEntry >, CascadeTemplateArray< VideoStream >, CascadeTemplateArray< CascadeFSObject * >, CascadeTemplateArray< AudioStream >, CascadeTemplateArray< RepaintEntry >, CascadeTemplateArray< char * >, CascadeTemplateArray< CascadeAppMessageSink * >, and CascadeTemplateArray< ProgramRecord * >. |
|
|
|
empty the array Makes the array empty.
|
|
return a copy of the item at index Returns a copy of the item at the supplied index. May fail if the index is invalid
Reimplemented in CascadeTemplateArray< T >, CascadeTemplateArray< Vessel * >, CascadeTemplateArray< TimerEntry >, CascadeTemplateArray< VideoStream >, CascadeTemplateArray< CascadeFSObject * >, CascadeTemplateArray< AudioStream >, CascadeTemplateArray< RepaintEntry >, CascadeTemplateArray< char * >, CascadeTemplateArray< CascadeAppMessageSink * >, and CascadeTemplateArray< ProgramRecord * >. |
|
insert an item into the array Insert the supplied item into the array. This may fail because memory may have to be allocated to hold the new item. The index of the newly-inserted item is returned in the ioIndex parameter if the insertion was successful
Reimplemented in CascadeTemplateArray< T >, CascadeTemplateArray< Vessel * >, CascadeTemplateArray< TimerEntry >, CascadeTemplateArray< VideoStream >, CascadeTemplateArray< CascadeFSObject * >, CascadeTemplateArray< AudioStream >, CascadeTemplateArray< RepaintEntry >, CascadeTemplateArray< char * >, CascadeTemplateArray< CascadeAppMessageSink * >, and CascadeTemplateArray< ProgramRecord * >. |
|
remove an item Removes the given item from the array. If the item cannot be found in the array, nothing happens
Reimplemented in CascadeTemplateArray< T >, CascadeTemplateArray< Vessel * >, CascadeTemplateArray< TimerEntry >, CascadeTemplateArray< VideoStream >, CascadeTemplateArray< CascadeFSObject * >, CascadeTemplateArray< AudioStream >, CascadeTemplateArray< RepaintEntry >, CascadeTemplateArray< char * >, CascadeTemplateArray< CascadeAppMessageSink * >, and CascadeTemplateArray< ProgramRecord * >. |
|
remove an item Removes the item at the given index from the array. If the index is invalid, nothing happens and this function returns false
|
|
sort the array Sort sorts the contents of the array using a QuickSort, using the supplied function to compare items.
|
|
swaps two items Swaps the position of two items in the array if both supplied indexes are valid.
|
|
re-size array's internal storage to fit contained items Re-sizes the array's internal storage to fit items already in the array. (Future insertions or appends will cause the memory to grow again.) |
|
|
|
|
|
|
|
|