glib.ArrayG.ArrayG Class Reference

List of all members.

Detailed Description

Description Arrays are similar to standard C arrays, except that they grow automatically as elements are added.

Array elements can be of any size (though all elements of one array are the same size), and the array can be automatically cleared to '0's and zero-terminated. To create a new array use g_array_new(). To add elements to an array, use g_array_append_val(), g_array_append_vals(), g_array_prepend_val(), and g_array_prepend_vals(). To access an element of an array, use g_array_index(). To set the size of an array, use g_array_set_size(). To free an array, use g_array_free(). Example5.Using a GArray to store gint values GArray *garray; gint i; /+* We create a new array to store gint values. We don't want it zero-terminated or cleared to 0's. +/ garray = g_array_new (FALSE, FALSE, sizeof (gint)); for (i = 0; i < 10000; i++) g_array_append_val (garray, i); for (i = 0; i < 10000; i++) if (g_array_index (garray, gint, i) != i) g_print ("ERROR: got %d instead of %d\n", g_array_index (garray, gint, i), i); g_array_free (garray, TRUE);


Public Member Functions

GArraygetArrayGStruct ()
 this (GArray *gArray)
 Sets our main struct and passes it to the parent class.
 this (int zeroTerminated, int clear, uint elementSize)
 Creates a new GArray.
ArrayG appendVals (void *data, uint len)
 Adds len elements onto the end of the array.
ArrayG prependVals (void *data, uint len)
 Adds len elements onto the start of the array.
ArrayG insertVals (uint index, void *data, uint len)
 Inserts len elements into a GArray at the given index.
ArrayG removeIndex (uint index)
 Removes the element at the given index from a GArray.
ArrayG removeIndexFast (uint index)
 Removes the element at the given index from a GArray.
ArrayG removeRange (uint index, uint length)
 Removes the given number of elements starting at the given index from a GArray.
void sort (GCompareFunc compareFunc)
 Sorts a GArray using compare_func which should be a qsort()-style comparison function (returns less than zero for first arg is less than second arg, zero for equal, greater zero if first arg is greater than second arg).
void sortWithData (GCompareDataFunc compareFunc, void *userData)
 Like g_array_sort(), but the comparison function receives an extra user data argument.
ArrayG setSize (uint length)
 Sets the size of the array, expanding it if necessary.
char[] free (int freeSegment)
 Frees the memory allocated for the GArray.

Static Public Member Functions

static ArrayG sizedNew (int zeroTerminated, int clear, uint elementSize, uint reservedSize)
 Creates a new GArray with reserved_size elements preallocated.

Protected Member Functions

void * getStruct ()
 the main Gtk struct as a void*

Protected Attributes

GArraygArray
 the main Gtk struct


Constructor & Destructor Documentation

glib.ArrayG.ArrayG.this ( GArray gArray  ) 

Sets our main struct and passes it to the parent class.

glib.ArrayG.ArrayG.this ( int  zeroTerminated,
int  clear,
uint  elementSize 
)

Creates a new GArray.

zero_terminated: TRUE if the array should have an extra element at the end which is set to 0. clear_: TRUE if GArray elements should be automatically cleared to 0 when they are allocated. element_size: the size of each element in bytes. Returns: the new GArray.


Member Function Documentation

ArrayG glib.ArrayG.ArrayG.appendVals ( void *  data,
uint  len 
)

Adds len elements onto the end of the array.

array: a GArray. data: a pointer to the elements to append to the end of the array. len: the number of elements to append. Returns: the GArray.

char [] glib.ArrayG.ArrayG.free ( int  freeSegment  ) 

Frees the memory allocated for the GArray.

If free_segment is TRUE it frees the memory block holding the elements as well. Pass FALSE if you want to free the GArray wrapper but preserve the underlying array for use elsewhere. Note If array elements contain dynamically-allocated memory, they should be freed first. array: a GArray. free_segment: if TRUE the actual element data is freed as well. Returns: the element data if free_segment is FALSE, otherwise NULL

GArray* glib.ArrayG.ArrayG.getArrayGStruct (  ) 

void* glib.ArrayG.ArrayG.getStruct (  )  [protected]

the main Gtk struct as a void*

ArrayG glib.ArrayG.ArrayG.insertVals ( uint  index,
void *  data,
uint  len 
)

Inserts len elements into a GArray at the given index.

array: a GArray. index_: the index to place the elements at. data: a pointer to the elements to insert. len: the number of elements to insert. Returns: the GArray.

ArrayG glib.ArrayG.ArrayG.prependVals ( void *  data,
uint  len 
)

Adds len elements onto the start of the array.

This operation is slower than g_array_append_vals() since the existing elements in the array have to be moved to make space for the new elements. array: a GArray. data: a pointer to the elements to prepend to the start of the array. len: the number of elements to prepend. Returns: the GArray.

ArrayG glib.ArrayG.ArrayG.removeIndex ( uint  index  ) 

Removes the element at the given index from a GArray.

The following elements are moved down one place. array: a GArray. index_: the index of the element to remove. Returns: the GArray.

ArrayG glib.ArrayG.ArrayG.removeIndexFast ( uint  index  ) 

Removes the element at the given index from a GArray.

The last element in the array is used to fill in the space, so this function does not preserve the order of the GArray. But it is faster than g_array_remove_index(). array: a GArray. index_: the index of the element to remove. Returns: the GArray.

ArrayG glib.ArrayG.ArrayG.removeRange ( uint  index,
uint  length 
)

Removes the given number of elements starting at the given index from a GArray.

The following elements are moved to close the gap. array: a GArray. index_: the index of the first element to remove. length: the number of elements to remove. Returns: the GArray. Since 2.4

ArrayG glib.ArrayG.ArrayG.setSize ( uint  length  ) 

Sets the size of the array, expanding it if necessary.

If the array was created with clear_ set to TRUE, the new elements are set to 0. array: a GArray. length: the new size of the GArray. Returns: the GArray.

static ArrayG glib.ArrayG.ArrayG.sizedNew ( int  zeroTerminated,
int  clear,
uint  elementSize,
uint  reservedSize 
) [static]

Creates a new GArray with reserved_size elements preallocated.

This avoids frequent reallocation, if you are going to add many elements to the array. Note however that the size of the array is still 0. zero_terminated: TRUE if the array should have an extra element at the end with all bits cleared. clear_: TRUE if all bits in the array should be cleared to 0 on allocation. element_size: size of each element in the array. reserved_size: number of elements preallocated. Returns: the new GArray.

void glib.ArrayG.ArrayG.sort ( GCompareFunc  compareFunc  ) 

Sorts a GArray using compare_func which should be a qsort()-style comparison function (returns less than zero for first arg is less than second arg, zero for equal, greater zero if first arg is greater than second arg).

If two array elements compare equal, their order in the sorted array is undefined. array: a GArray. compare_func: comparison function.

void glib.ArrayG.ArrayG.sortWithData ( GCompareDataFunc  compareFunc,
void *  userData 
)

Like g_array_sort(), but the comparison function receives an extra user data argument.

array: a GArray. compare_func: comparison function. user_data: data to pass to compare_func.


Member Data Documentation

GArray* glib.ArrayG.ArrayG.gArray [protected]

the main Gtk struct


SourceForge.net Logo DSource.org Logo digitalmars.com Logo