#include <GArray.h>
Public Member Functions | |
GArray (int PreAlloc=0) | |
Constructor. | |
~GArray () | |
Destructor. | |
int | Length () |
Returns the number of used entries. | |
bool | Length (uint32 i) |
Sets the length of available entries. | |
Type & | operator[] (uint32 i) |
Returns a reference a given entry. | |
void | DeleteObjects () |
Delete all the entries as if they are pointers to objects. | |
void | DeleteArrays () |
Delete all the entries as if they are pointers to arrays. | |
int | IndexOf (Type n) |
Find the index of entry 'n'. | |
bool | HasItem (Type n) |
Returns true if the item 'n' is in the array. | |
bool | DeleteAt (uint Index, bool Ordered=false) |
Deletes an entry. | |
bool | Delete (Type n, bool Ordered=false) |
Deletes the entry 'n'. | |
void | Add (Type n) |
Appends an element. | |
bool | AddAt (int Index, Type n) |
Inserts an element into the array. | |
void | Sort (int(*Compare)(Type *, Type *)) |
Sorts the array. |
You can store simple objects inline in this array, but all their contents are initialized to the octet 0x00. Which limits use to objects that don't have a virtual table and don't need construction (constructors are not called).
The objects are copied around during use so you can't assume their pointer will remain the same over time either. However when objects are deleted from the array their destructors WILL be called. This allows you to have simple objects that have dynamically allocated pointers that are freed properly. A good example of this type of object is the GVariant class.
If you want to store objects with a virtual table, or that need their constructor to be called then you should create the GArray with pointers to the objects instead of inline objects. And to clean up the memory you can call GArray::DeleteObjects or GArray::DeleteArrays.
|
Appends an element.
|
|
Inserts an element into the array.
|
|
Deletes the entry 'n'.
|
|
Deletes an entry.
|
|
Returns a reference a given entry. If the entry is off the end of the array, it will grow to make it valid. |