#include <GArray.h>
Public Member Functions | |
GArray (int PreAlloc=0) | |
Constructor. | |
~GArray () | |
Destructor. | |
uint32 | Length () const |
Returns the number of used entries. | |
void | SetFixedLength () |
Makes the length fixed.. | |
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 (const Type &n) |
Appends an element. | |
void | Add (Type *s, int count) |
Appends multiple elements. | |
void | Add (GArray< Type > &a) |
Appends an array of elements. | |
bool | AddAt (int Index, Type n) |
Inserts an element into the array. | |
void | Sort (int(*Compare)(Type *, Type *)) |
Sorts the array. | |
Type & | New () |
Type * | Release () |
Returns the memory held by the array and sets itself to empty. |
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 or GAutoString 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.
Returns a reference a given entry.
If the entry is off the end of the array and "fixed" is false, it will grow to make it valid.
Reimplemented in GToken.
Referenced by GToken::operator[]().
bool GArray< Type >::DeleteAt | ( | uint | Index, | |
bool | Ordered = false | |||
) | [inline] |
Deletes an entry.
Index | The index of the entry to delete |
Ordered | true if the order of the array matters, otherwise false. |
Referenced by GCompilerPriv::AsmExpression(), GXmlTag::DelAttr(), GArray< unsigned short * >::Delete(), and LgiFindFile().
bool GArray< Type >::Delete | ( | Type | n, | |
bool | Ordered = false | |||
) | [inline] |
Deletes the entry 'n'.
n | The value of the entry to delete |
Ordered | true if the order of the array matters, otherwise false. |
Referenced by SystemFunctions::DeleteElement().
void GArray< Type >::Add | ( | const Type & | n | ) | [inline] |
Appends an element.
n | Item to insert |
Referenced by GHashTbl< unsigned short *, GTypeDef * >::Add(), GFileSystem::Delete(), GFileAssoc::GetActions(), GDateTime::GetDaylightSavingsInfo(), GFileAssoc::GetExtensions(), GCompiledCode::GetMethod(), LgiExecute(), LgiFindFile(), LgiGetOs(), LgiRecursiveFileSearch(), GApp::OnCommandLine(), Html2::GHtml2::OnContent(), GWindow::OnDrop(), GList::OnMouseClick(), GProcess::Run(), GListItem::Select(), and SystemFunctions::Sprintf().
void GArray< Type >::Add | ( | Type * | s, | |
int | count | |||
) | [inline] |
Appends multiple elements.
s | Items to insert |
count | Length of array |
Appends an array of elements.
a | Array to insert |
bool GArray< Type >::AddAt | ( | int | Index, | |
Type | n | |||
) | [inline] |
Inserts an element into the array.
Index | Item to insert before |
n | Item to insert |
Type& GArray< Type >::New | ( | ) | [inline] |
Referenced by GCompilerPriv::Expression(), GDateTime::GetDaylightSavingsInfo(), and LgiDetectLinks().