GArray< Type > Class Template Reference

Growable type-safe array. More...

#include <GArray.h>

List of all members.

Public Member Functions

 GArray (int PreAlloc=0)
 Constructor.
 ~GArray ()
 Destructor.
uint32 Length () const
 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 (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.


Detailed Description

template<class Type>
class GArray< Type >

Growable type-safe 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 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.


Member Function Documentation

template<class Type >
void GArray< Type >::Add ( GArray< Type > &  a  )  [inline]

Appends an array of elements.

Parameters:
a  Array to insert

template<class Type >
void GArray< Type >::Add ( Type *  s,
int  count 
) [inline]

Appends multiple elements.

Parameters:
s  Items to insert
count  Length of array

template<class Type >
void GArray< Type >::Add ( const Type &  n  )  [inline]

template<class Type >
bool GArray< Type >::AddAt ( int  Index,
Type  n 
) [inline]

Inserts an element into the array.

Parameters:
Index  Item to insert before
n  Item to insert

template<class Type >
bool GArray< Type >::Delete ( Type  n,
bool  Ordered = false 
) [inline]

Deletes the entry 'n'.

Parameters:
n  The value of the entry to delete
Ordered  true if the order of the array matters, otherwise false.

Referenced by SystemFunctions::DeleteElement().

template<class Type >
bool GArray< Type >::DeleteAt ( uint  Index,
bool  Ordered = false 
) [inline]

Deletes an entry.

Parameters:
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().

template<class Type >
Type& GArray< Type >::New (  )  [inline]

Returns:
a reference to a new object on the end of the array

Referenced by GCompilerPriv::Expression(), GDateTime::GetDaylightSavingsInfo(), Html2::GHtml2::GetFormattedContent(), and GCompilerPriv::TokenToVarRef().

template<class Type >
Type& GArray< Type >::operator[] ( uint32  i  )  [inline]

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.


The documentation for this class was generated from the following file:

Generated on Wed Dec 1 15:41:02 2010 for Lgi by  doxygen 1.5.7.1