glib.ByteArray.ByteArray Class Reference

List of all members.

Detailed Description

Description GByteArray is based on GArray, to provide arrays of bytes which grow automatically as elements are added.

To create a new GByteArray use g_byte_array_new(). To add elements to a GByteArray, use g_byte_array_append(), and g_byte_array_prepend(). To set the size of a GByteArray, use g_byte_array_set_size(). To free a GByteArray, use g_byte_array_free(). Example8.Using a GByteArray GByteArray *gbarray; gint i; gbarray = g_byte_array_new (); for (i = 0; i < 10000; i++) g_byte_array_append (gbarray, (guint8*) "abcd", 4); for (i = 0; i < 10000; i++) { g_assert (gbarray->data[4*i] == 'a'); g_assert (gbarray->data[4*i+1] == 'b'); g_assert (gbarray->data[4*i+2] == 'c'); g_assert (gbarray->data[4*i+3] == 'd'); } g_byte_array_free (gbarray, TRUE);


Public Member Functions

GByteArraygetByteArrayStruct ()
 this (GByteArray *gByteArray)
 Sets our main struct and passes it to the parent class.
 this ()
 Creates a new GByteArray.
GByteArrayappend (byte *data, uint len)
 Adds the given bytes to the end of the GByteArray.
GByteArrayprepend (byte *data, uint len)
 Adds the given data to the start of the GByteArray.
GByteArrayremoveIndex (uint index)
 Removes the byte at the given index from a GByteArray.
GByteArrayremoveIndexFast (uint index)
 Removes the byte at the given index from a GByteArray.
GByteArrayremoveRange (uint index, uint length)
 Removes the given number of bytes starting at the given index from a GByteArray.
void sort (GCompareFunc compareFunc)
 Sorts a byte array, 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 than zero if first arg is greater than second arg).
void sortWithData (GCompareDataFunc compareFunc, void *userData)
 Like g_byte_array_sort(), but the comparison function takes an extra user data argument.
GByteArraysetSize (uint length)
 Sets the size of the GByteArray, expanding it if necessary.
byte * free (int freeSegment)
 Frees the memory allocated by the GByteArray.

Static Public Member Functions

static GByteArraysizedNew (uint reservedSize)
 Creates a new GByteArray with reserved_size bytes preallocated.

Protected Member Functions

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

Protected Attributes

GByteArraygByteArray
 the main Gtk struct


Constructor & Destructor Documentation

glib.ByteArray.ByteArray.this ( GByteArray gByteArray  ) 

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

glib.ByteArray.ByteArray.this (  ) 

Creates a new GByteArray.

Returns: the new GByteArray.


Member Function Documentation

GByteArray* glib.ByteArray.ByteArray.append ( byte *  data,
uint  len 
)

Adds the given bytes to the end of the GByteArray.

The array will grow in size automatically if necessary. array: a GByteArray. data: the byte data to be added. len: the number of bytes to add. Returns: the GByteArray.

byte* glib.ByteArray.ByteArray.free ( int  freeSegment  ) 

Frees the memory allocated by the GByteArray.

If free_segment is TRUE it frees the actual byte data. array: a GByteArray. free_segment: if TRUE the actual byte data is freed as well. Returns: the element data if free_segment is FALSE, otherwise NULL

GByteArray* glib.ByteArray.ByteArray.getByteArrayStruct (  ) 

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

the main Gtk struct as a void*

GByteArray* glib.ByteArray.ByteArray.prepend ( byte *  data,
uint  len 
)

Adds the given data to the start of the GByteArray.

The array will grow in size automatically if necessary. array: a GByteArray. data: the byte data to be added. len: the number of bytes to add. Returns: the GByteArray.

GByteArray* glib.ByteArray.ByteArray.removeIndex ( uint  index  ) 

Removes the byte at the given index from a GByteArray.

The following bytes are moved down one place. array: a GByteArray. index_: the index of the byte to remove. Returns: the GByteArray.

GByteArray* glib.ByteArray.ByteArray.removeIndexFast ( uint  index  ) 

Removes the byte at the given index from a GByteArray.

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

GByteArray* glib.ByteArray.ByteArray.removeRange ( uint  index,
uint  length 
)

Removes the given number of bytes starting at the given index from a GByteArray.

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

GByteArray* glib.ByteArray.ByteArray.setSize ( uint  length  ) 

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

array: a GByteArray. length: the new size of the GByteArray. Returns: the GByteArray.

static GByteArray* glib.ByteArray.ByteArray.sizedNew ( uint  reservedSize  )  [static]

Creates a new GByteArray with reserved_size bytes preallocated.

This avoids frequent reallocation, if you are going to add many bytes to the array. Note however that the size of the array is still 0. reserved_size: number of bytes preallocated. Returns: the new GByteArray.

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

Sorts a byte array, 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 than 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 GByteArray. compare_func: comparison function.

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

Like g_byte_array_sort(), but the comparison function takes an extra user data argument.

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


Member Data Documentation

GByteArray* glib.ByteArray.ByteArray.gByteArray [protected]

the main Gtk struct


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