/src/wrappers/glib/library/data_types/glib_byte_arrays.e

http://github.com/tybor/Liberty · Specman e · 189 lines · 7 code · 43 blank · 139 comment · 0 complexity · 74c7ff47379112928aa74e3f3da5154f MD5 · raw file

  1. indexing
  2. copyright: "(C) 2005 Paolo Redaelli "
  3. license: "LGPL v2 or later"
  4. date: "$Date:$"
  5. revision: "$REvision:$"
  6. class GLIB_BYTE_ARRAYS
  7. -- Prev Up Home GLib Reference Manual Next
  8. -- Top | Description
  9. -- Byte Arrays
  10. -- Byte Arrays %G —%@ arrays of bytes, which grow automatically as elements are added.
  11. -- Synopsis
  12. -- #include <glib.h>
  13. -- GByteArray;
  14. -- GByteArray* g_byte_array_new (void);
  15. -- GByteArray* g_byte_array_sized_new (guint reserved_size);
  16. -- GByteArray* g_byte_array_append (GByteArray *array,
  17. -- const guint8 *data,
  18. -- guint len);
  19. -- GByteArray* g_byte_array_prepend (GByteArray *array,
  20. -- const guint8 *data,
  21. -- guint len);
  22. -- GByteArray* g_byte_array_remove_index (GByteArray *array,
  23. -- guint index_);
  24. -- GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
  25. -- guint index_);
  26. -- GByteArray* g_byte_array_remove_range (GByteArray *array,
  27. -- guint index_,
  28. -- guint length);
  29. -- void g_byte_array_sort (GByteArray *array,
  30. -- GCompareFunc compare_func);
  31. -- void g_byte_array_sort_with_data (GByteArray *array,
  32. -- GCompareDataFunc compare_func,
  33. -- gpointer user_data);
  34. -- GByteArray* g_byte_array_set_size (GByteArray *array,
  35. -- guint length);
  36. -- guint8* g_byte_array_free (GByteArray *array,
  37. -- gboolean free_segment);
  38. -- Description
  39. -- GByteArray is based on GArray, to provide arrays of bytes which grow automatically as elements are added.
  40. -- To create a new GByteArray use g_byte_array_new().
  41. -- To add elements to a GByteArray, use g_byte_array_append(), and g_byte_array_prepend().
  42. -- To set the size of a GByteArray, use g_byte_array_set_size().
  43. -- To free a GByteArray, use g_byte_array_free().
  44. -- Example 6. Using a GByteArray
  45. -- GByteArray *gbarray;
  46. -- gint i;
  47. -- gbarray = g_byte_array_new ();
  48. -- for (i = 0; i < 10000; i++)
  49. -- g_byte_array_append (gbarray, (guint8*) "abcd", 4);
  50. -- for (i = 0; i < 10000; i++)
  51. -- {
  52. -- g_assert (gbarray->data[4*i] == 'a');
  53. -- g_assert (gbarray->data[4*i+1] == 'b');
  54. -- g_assert (gbarray->data[4*i+2] == 'c');
  55. -- g_assert (gbarray->data[4*i+3] == 'd');
  56. -- }
  57. -- g_byte_array_free (gbarray, TRUE);
  58. -- Details
  59. -- GByteArray
  60. -- typedef struct {
  61. -- guint8 *data;
  62. -- guint len;
  63. -- } GByteArray;
  64. -- The GByteArray struct allows access to the public fields of a GByteArray.
  65. -- guint8 *data; a pointer to the element data. The data may be moved as elements are added to the GByteArray.
  66. -- guint len; the number of elements in the GByteArray.
  67. -- g_byte_array_new ()
  68. -- GByteArray* g_byte_array_new (void);
  69. -- Creates a new GByteArray.
  70. -- Returns : the new GByteArray.
  71. -- g_byte_array_sized_new ()
  72. -- GByteArray* g_byte_array_sized_new (guint reserved_size);
  73. -- 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.
  74. -- reserved_size : number of bytes preallocated.
  75. -- Returns : the new GByteArray.
  76. -- g_byte_array_append ()
  77. -- GByteArray* g_byte_array_append (GByteArray *array,
  78. -- const guint8 *data,
  79. -- guint len);
  80. -- Adds the given bytes to the end of the GByteArray. The array will grow in size automatically if necessary.
  81. -- array : a GByteArray.
  82. -- data : the byte data to be added.
  83. -- len : the number of bytes to add.
  84. -- Returns : the GByteArray.
  85. -- g_byte_array_prepend ()
  86. -- GByteArray* g_byte_array_prepend (GByteArray *array,
  87. -- const guint8 *data,
  88. -- guint len);
  89. -- Adds the given data to the start of the GByteArray. The array will grow in size automatically if necessary.
  90. -- array : a GByteArray.
  91. -- data : the byte data to be added.
  92. -- len : the number of bytes to add.
  93. -- Returns : the GByteArray.
  94. -- g_byte_array_remove_index ()
  95. -- GByteArray* g_byte_array_remove_index (GByteArray *array,
  96. -- guint index_);
  97. -- Removes the byte at the given index from a GByteArray. The following bytes are moved down one place.
  98. -- array : a GByteArray.
  99. -- index_ : the index of the byte to remove.
  100. -- Returns : the GByteArray.
  101. -- g_byte_array_remove_index_fast ()
  102. -- GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
  103. -- guint index_);
  104. -- 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().
  105. -- array : a GByteArray.
  106. -- index_ : the index of the byte to remove.
  107. -- Returns : the GByteArray.
  108. -- g_byte_array_remove_range ()
  109. -- GByteArray* g_byte_array_remove_range (GByteArray *array,
  110. -- guint index_,
  111. -- guint length);
  112. -- Removes the given number of bytes starting at the given index from a GByteArray. The following elements are moved to close the gap.
  113. -- array : a GByteArray.
  114. -- index_ : the index of the first byte to remove.
  115. -- length : the number of bytes to remove.
  116. -- Returns : the GByteArray.
  117. -- Since 2.4
  118. -- g_byte_array_sort ()
  119. -- void g_byte_array_sort (GByteArray *array,
  120. -- GCompareFunc compare_func);
  121. -- Sorts a byte array, using compare_func which should be a qsort()-style comparison function (returns -1 for first arg is less than second arg, 0 for equal, 1 if first arg is greater than second arg).
  122. -- array : a GByteArray.
  123. -- compare_func : comparison function.
  124. -- g_byte_array_sort_with_data ()
  125. -- void g_byte_array_sort_with_data (GByteArray *array,
  126. -- GCompareDataFunc compare_func,
  127. -- gpointer user_data);
  128. -- Like g_byte_array_sort(), but the comparison function takes a user data argument.
  129. -- array : a GByteArray.
  130. -- compare_func : comparison function.
  131. -- user_data : data to pass to compare_func.
  132. -- g_byte_array_set_size ()
  133. -- GByteArray* g_byte_array_set_size (GByteArray *array,
  134. -- guint length);
  135. -- Sets the size of the GByteArray, expanding it if necessary.
  136. -- array : a GByteArray.
  137. -- length : the new size of the GByteArray.
  138. -- Returns : the GByteArray.
  139. -- g_byte_array_free ()
  140. -- guint8* g_byte_array_free (GByteArray *array,
  141. -- gboolean free_segment);
  142. -- Frees the memory allocated by the GByteArray. If free_segment is TRUE it frees the actual byte data.
  143. -- array : a GByteArray.
  144. -- free_segment : if TRUE the actual byte data is freed as well.
  145. -- Returns : the element data if free_segment is FALSE, otherwise NULL
  146. end