25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

180 lines
7.1 KiB

  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, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  21. * file for a list of people on the GLib Team. See the ChangeLog
  22. * files for a list of changes. These files are distributed with
  23. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  24. */
  25. #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #ifndef __G_ARRAY_H__
  29. #define __G_ARRAY_H__
  30. #include <glib/gtypes.h>
  31. G_BEGIN_DECLS
  32. typedef struct _GArray GArray;
  33. typedef struct _GByteArray GByteArray;
  34. typedef struct _GPtrArray GPtrArray;
  35. struct _GArray
  36. {
  37. gchar *data;
  38. guint len;
  39. };
  40. struct _GByteArray
  41. {
  42. guint8 *data;
  43. guint len;
  44. };
  45. struct _GPtrArray
  46. {
  47. gpointer *pdata;
  48. guint len;
  49. };
  50. /* Resizable arrays. remove fills any cleared spot and shortens the
  51. * array, while preserving the order. remove_fast will distort the
  52. * order by moving the last element to the position of the removed.
  53. */
  54. #define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
  55. #define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
  56. #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
  57. #define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
  58. GArray* g_array_new (gboolean zero_terminated,
  59. gboolean clear_,
  60. guint element_size);
  61. GArray* g_array_sized_new (gboolean zero_terminated,
  62. gboolean clear_,
  63. guint element_size,
  64. guint reserved_size);
  65. gchar* g_array_free (GArray *array,
  66. gboolean free_segment);
  67. GArray *g_array_ref (GArray *array);
  68. void g_array_unref (GArray *array);
  69. guint g_array_get_element_size (GArray *array);
  70. GArray* g_array_append_vals (GArray *array,
  71. gconstpointer data,
  72. guint len);
  73. GArray* g_array_prepend_vals (GArray *array,
  74. gconstpointer data,
  75. guint len);
  76. GArray* g_array_insert_vals (GArray *array,
  77. guint index_,
  78. gconstpointer data,
  79. guint len);
  80. GArray* g_array_set_size (GArray *array,
  81. guint length);
  82. GArray* g_array_remove_index (GArray *array,
  83. guint index_);
  84. GArray* g_array_remove_index_fast (GArray *array,
  85. guint index_);
  86. GArray* g_array_remove_range (GArray *array,
  87. guint index_,
  88. guint length);
  89. void g_array_sort (GArray *array,
  90. GCompareFunc compare_func);
  91. void g_array_sort_with_data (GArray *array,
  92. GCompareDataFunc compare_func,
  93. gpointer user_data);
  94. /* Resizable pointer array. This interface is much less complicated
  95. * than the above. Add appends a pointer. Remove fills any cleared
  96. * spot and shortens the array. remove_fast will again distort order.
  97. */
  98. #define g_ptr_array_index(array,index_) ((array)->pdata)[index_]
  99. GPtrArray* g_ptr_array_new (void);
  100. GPtrArray* g_ptr_array_new_with_free_func (GDestroyNotify element_free_func);
  101. GPtrArray* g_ptr_array_sized_new (guint reserved_size);
  102. gpointer* g_ptr_array_free (GPtrArray *array,
  103. gboolean free_seg);
  104. GPtrArray* g_ptr_array_ref (GPtrArray *array);
  105. void g_ptr_array_unref (GPtrArray *array);
  106. void g_ptr_array_set_free_func (GPtrArray *array,
  107. GDestroyNotify element_free_func);
  108. void g_ptr_array_set_size (GPtrArray *array,
  109. gint length);
  110. gpointer g_ptr_array_remove_index (GPtrArray *array,
  111. guint index_);
  112. gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
  113. guint index_);
  114. gboolean g_ptr_array_remove (GPtrArray *array,
  115. gpointer data);
  116. gboolean g_ptr_array_remove_fast (GPtrArray *array,
  117. gpointer data);
  118. void g_ptr_array_remove_range (GPtrArray *array,
  119. guint index_,
  120. guint length);
  121. void g_ptr_array_add (GPtrArray *array,
  122. gpointer data);
  123. void g_ptr_array_sort (GPtrArray *array,
  124. GCompareFunc compare_func);
  125. void g_ptr_array_sort_with_data (GPtrArray *array,
  126. GCompareDataFunc compare_func,
  127. gpointer user_data);
  128. void g_ptr_array_foreach (GPtrArray *array,
  129. GFunc func,
  130. gpointer user_data);
  131. /* Byte arrays, an array of guint8. Implemented as a GArray,
  132. * but type-safe.
  133. */
  134. GByteArray* g_byte_array_new (void);
  135. GByteArray* g_byte_array_sized_new (guint reserved_size);
  136. guint8* g_byte_array_free (GByteArray *array,
  137. gboolean free_segment);
  138. GByteArray *g_byte_array_ref (GByteArray *array);
  139. void g_byte_array_unref (GByteArray *array);
  140. GByteArray* g_byte_array_append (GByteArray *array,
  141. const guint8 *data,
  142. guint len);
  143. GByteArray* g_byte_array_prepend (GByteArray *array,
  144. const guint8 *data,
  145. guint len);
  146. GByteArray* g_byte_array_set_size (GByteArray *array,
  147. guint length);
  148. GByteArray* g_byte_array_remove_index (GByteArray *array,
  149. guint index_);
  150. GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
  151. guint index_);
  152. GByteArray* g_byte_array_remove_range (GByteArray *array,
  153. guint index_,
  154. guint length);
  155. void g_byte_array_sort (GByteArray *array,
  156. GCompareFunc compare_func);
  157. void g_byte_array_sort_with_data (GByteArray *array,
  158. GCompareDataFunc compare_func,
  159. gpointer user_data);
  160. G_END_DECLS
  161. #endif /* __G_ARRAY_H__ */