Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

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.
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.


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 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 Type  n  )  [inline]
 

Appends an element.

Parameters:
n  Item to insert

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.

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.

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, it will grow to make it valid.


The documentation for this class was generated from the following file:
Generated on Wed Oct 26 14:46:56 2005 for Lgi by  doxygen 1.4.1