garray.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* GLIB - Library of useful routines for C programming
  2. * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  19. * file for a list of people on the GLib Team. See the ChangeLog
  20. * files for a list of changes. These files are distributed with
  21. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  22. */
  23. #ifndef __G_ARRAY_H__
  24. #define __G_ARRAY_H__
  25. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #include <glib/gtypes.h>
  29. G_BEGIN_DECLS
  30. typedef struct _GBytes GBytes;
  31. typedef struct _GArray GArray;
  32. typedef struct _GByteArray GByteArray;
  33. typedef struct _GPtrArray GPtrArray;
  34. struct _GArray
  35. {
  36. gchar *data;
  37. guint len;
  38. };
  39. struct _GByteArray
  40. {
  41. guint8 *data;
  42. guint len;
  43. };
  44. struct _GPtrArray
  45. {
  46. gpointer *pdata;
  47. guint len;
  48. };
  49. /* Resizable arrays. remove fills any cleared spot and shortens the
  50. * array, while preserving the order. remove_fast will distort the
  51. * order by moving the last element to the position of the removed.
  52. */
  53. #define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
  54. #define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
  55. #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
  56. #define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
  57. GLIB_AVAILABLE_IN_ALL
  58. GArray* g_array_new (gboolean zero_terminated,
  59. gboolean clear_,
  60. guint element_size);
  61. GLIB_AVAILABLE_IN_ALL
  62. GArray* g_array_sized_new (gboolean zero_terminated,
  63. gboolean clear_,
  64. guint element_size,
  65. guint reserved_size);
  66. GLIB_AVAILABLE_IN_ALL
  67. gchar* g_array_free (GArray *array,
  68. gboolean free_segment);
  69. GLIB_AVAILABLE_IN_ALL
  70. GArray *g_array_ref (GArray *array);
  71. GLIB_AVAILABLE_IN_ALL
  72. void g_array_unref (GArray *array);
  73. GLIB_AVAILABLE_IN_ALL
  74. guint g_array_get_element_size (GArray *array);
  75. GLIB_AVAILABLE_IN_ALL
  76. GArray* g_array_append_vals (GArray *array,
  77. gconstpointer data,
  78. guint len);
  79. GLIB_AVAILABLE_IN_ALL
  80. GArray* g_array_prepend_vals (GArray *array,
  81. gconstpointer data,
  82. guint len);
  83. GLIB_AVAILABLE_IN_ALL
  84. GArray* g_array_insert_vals (GArray *array,
  85. guint index_,
  86. gconstpointer data,
  87. guint len);
  88. GLIB_AVAILABLE_IN_ALL
  89. GArray* g_array_set_size (GArray *array,
  90. guint length);
  91. GLIB_AVAILABLE_IN_ALL
  92. GArray* g_array_remove_index (GArray *array,
  93. guint index_);
  94. GLIB_AVAILABLE_IN_ALL
  95. GArray* g_array_remove_index_fast (GArray *array,
  96. guint index_);
  97. GLIB_AVAILABLE_IN_ALL
  98. GArray* g_array_remove_range (GArray *array,
  99. guint index_,
  100. guint length);
  101. GLIB_AVAILABLE_IN_ALL
  102. void g_array_sort (GArray *array,
  103. GCompareFunc compare_func);
  104. GLIB_AVAILABLE_IN_ALL
  105. void g_array_sort_with_data (GArray *array,
  106. GCompareDataFunc compare_func,
  107. gpointer user_data);
  108. GLIB_AVAILABLE_IN_ALL
  109. void g_array_set_clear_func (GArray *array,
  110. GDestroyNotify clear_func);
  111. /* Resizable pointer array. This interface is much less complicated
  112. * than the above. Add appends a pointer. Remove fills any cleared
  113. * spot and shortens the array. remove_fast will again distort order.
  114. */
  115. #define g_ptr_array_index(array,index_) ((array)->pdata)[index_]
  116. GLIB_AVAILABLE_IN_ALL
  117. GPtrArray* g_ptr_array_new (void);
  118. GLIB_AVAILABLE_IN_ALL
  119. GPtrArray* g_ptr_array_new_with_free_func (GDestroyNotify element_free_func);
  120. GLIB_AVAILABLE_IN_ALL
  121. GPtrArray* g_ptr_array_sized_new (guint reserved_size);
  122. GLIB_AVAILABLE_IN_ALL
  123. GPtrArray* g_ptr_array_new_full (guint reserved_size,
  124. GDestroyNotify element_free_func);
  125. GLIB_AVAILABLE_IN_ALL
  126. gpointer* g_ptr_array_free (GPtrArray *array,
  127. gboolean free_seg);
  128. GLIB_AVAILABLE_IN_ALL
  129. GPtrArray* g_ptr_array_ref (GPtrArray *array);
  130. GLIB_AVAILABLE_IN_ALL
  131. void g_ptr_array_unref (GPtrArray *array);
  132. GLIB_AVAILABLE_IN_ALL
  133. void g_ptr_array_set_free_func (GPtrArray *array,
  134. GDestroyNotify element_free_func);
  135. GLIB_AVAILABLE_IN_ALL
  136. void g_ptr_array_set_size (GPtrArray *array,
  137. gint length);
  138. GLIB_AVAILABLE_IN_ALL
  139. gpointer g_ptr_array_remove_index (GPtrArray *array,
  140. guint index_);
  141. GLIB_AVAILABLE_IN_ALL
  142. gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
  143. guint index_);
  144. GLIB_AVAILABLE_IN_ALL
  145. gboolean g_ptr_array_remove (GPtrArray *array,
  146. gpointer data);
  147. GLIB_AVAILABLE_IN_ALL
  148. gboolean g_ptr_array_remove_fast (GPtrArray *array,
  149. gpointer data);
  150. GLIB_AVAILABLE_IN_ALL
  151. GPtrArray *g_ptr_array_remove_range (GPtrArray *array,
  152. guint index_,
  153. guint length);
  154. GLIB_AVAILABLE_IN_ALL
  155. void g_ptr_array_add (GPtrArray *array,
  156. gpointer data);
  157. GLIB_AVAILABLE_IN_2_40
  158. void g_ptr_array_insert (GPtrArray *array,
  159. gint index_,
  160. gpointer data);
  161. GLIB_AVAILABLE_IN_ALL
  162. void g_ptr_array_sort (GPtrArray *array,
  163. GCompareFunc compare_func);
  164. GLIB_AVAILABLE_IN_ALL
  165. void g_ptr_array_sort_with_data (GPtrArray *array,
  166. GCompareDataFunc compare_func,
  167. gpointer user_data);
  168. GLIB_AVAILABLE_IN_ALL
  169. void g_ptr_array_foreach (GPtrArray *array,
  170. GFunc func,
  171. gpointer user_data);
  172. /* Byte arrays, an array of guint8. Implemented as a GArray,
  173. * but type-safe.
  174. */
  175. GLIB_AVAILABLE_IN_ALL
  176. GByteArray* g_byte_array_new (void);
  177. GLIB_AVAILABLE_IN_ALL
  178. GByteArray* g_byte_array_new_take (guint8 *data,
  179. gsize len);
  180. GLIB_AVAILABLE_IN_ALL
  181. GByteArray* g_byte_array_sized_new (guint reserved_size);
  182. GLIB_AVAILABLE_IN_ALL
  183. guint8* g_byte_array_free (GByteArray *array,
  184. gboolean free_segment);
  185. GLIB_AVAILABLE_IN_ALL
  186. GBytes* g_byte_array_free_to_bytes (GByteArray *array);
  187. GLIB_AVAILABLE_IN_ALL
  188. GByteArray *g_byte_array_ref (GByteArray *array);
  189. GLIB_AVAILABLE_IN_ALL
  190. void g_byte_array_unref (GByteArray *array);
  191. GLIB_AVAILABLE_IN_ALL
  192. GByteArray* g_byte_array_append (GByteArray *array,
  193. const guint8 *data,
  194. guint len);
  195. GLIB_AVAILABLE_IN_ALL
  196. GByteArray* g_byte_array_prepend (GByteArray *array,
  197. const guint8 *data,
  198. guint len);
  199. GLIB_AVAILABLE_IN_ALL
  200. GByteArray* g_byte_array_set_size (GByteArray *array,
  201. guint length);
  202. GLIB_AVAILABLE_IN_ALL
  203. GByteArray* g_byte_array_remove_index (GByteArray *array,
  204. guint index_);
  205. GLIB_AVAILABLE_IN_ALL
  206. GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
  207. guint index_);
  208. GLIB_AVAILABLE_IN_ALL
  209. GByteArray* g_byte_array_remove_range (GByteArray *array,
  210. guint index_,
  211. guint length);
  212. GLIB_AVAILABLE_IN_ALL
  213. void g_byte_array_sort (GByteArray *array,
  214. GCompareFunc compare_func);
  215. GLIB_AVAILABLE_IN_ALL
  216. void g_byte_array_sort_with_data (GByteArray *array,
  217. GCompareDataFunc compare_func,
  218. gpointer user_data);
  219. G_END_DECLS
  220. #endif /* __G_ARRAY_H__ */