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.1 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/*
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25#ifndef __G_ARRAY_H__
26#define __G_ARRAY_H__
27
28#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
29#error "Only <glib.h> can be included directly."
30#endif
31
32#include <glib/gtypes.h>
33
34G_BEGIN_DECLS
35
36typedef struct _GBytes GBytes;
37typedef struct _GArray GArray;
38typedef struct _GByteArray GByteArray;
39typedef struct _GPtrArray GPtrArray;
40
41struct _GArray
42{
43 gchar *data;
44 guint len;
45};
46
47struct _GByteArray
48{
49 guint8 *data;
50 guint len;
51};
52
53struct _GPtrArray
54{
55 gpointer *pdata;
56 guint len;
57};
58
59/* Resizable arrays. remove fills any cleared spot and shortens the
60 * array, while preserving the order. remove_fast will distort the
61 * order by moving the last element to the position of the removed.
62 */
63
64#define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
65#define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
66#define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
67#define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
68
69GLIB_AVAILABLE_IN_ALL
70GArray* g_array_new (gboolean zero_terminated,
71 gboolean clear_,
72 guint element_size);
73GLIB_AVAILABLE_IN_2_64
74gpointer g_array_steal (GArray *array,
75 gsize *len);
76GLIB_AVAILABLE_IN_ALL
77GArray* g_array_sized_new (gboolean zero_terminated,
78 gboolean clear_,
79 guint element_size,
80 guint reserved_size);
81GLIB_AVAILABLE_IN_2_62
82GArray* g_array_copy (GArray *array);
83GLIB_AVAILABLE_IN_ALL
84gchar* g_array_free (GArray *array,
85 gboolean free_segment);
86GLIB_AVAILABLE_IN_ALL
87GArray *g_array_ref (GArray *array);
88GLIB_AVAILABLE_IN_ALL
89void g_array_unref (GArray *array);
90GLIB_AVAILABLE_IN_ALL
91guint g_array_get_element_size (GArray *array);
92GLIB_AVAILABLE_IN_ALL
93GArray* g_array_append_vals (GArray *array,
94 gconstpointer data,
95 guint len);
96GLIB_AVAILABLE_IN_ALL
97GArray* g_array_prepend_vals (GArray *array,
98 gconstpointer data,
99 guint len);
100GLIB_AVAILABLE_IN_ALL
101GArray* g_array_insert_vals (GArray *array,
102 guint index_,
103 gconstpointer data,
104 guint len);
105GLIB_AVAILABLE_IN_ALL
106GArray* g_array_set_size (GArray *array,
107 guint length);
108GLIB_AVAILABLE_IN_ALL
109GArray* g_array_remove_index (GArray *array,
110 guint index_);
111GLIB_AVAILABLE_IN_ALL
112GArray* g_array_remove_index_fast (GArray *array,
113 guint index_);
114GLIB_AVAILABLE_IN_ALL
115GArray* g_array_remove_range (GArray *array,
116 guint index_,
117 guint length);
118GLIB_AVAILABLE_IN_ALL
119void g_array_sort (GArray *array,
120 GCompareFunc compare_func);
121GLIB_AVAILABLE_IN_ALL
122void g_array_sort_with_data (GArray *array,
123 GCompareDataFunc compare_func,
124 gpointer user_data);
125GLIB_AVAILABLE_IN_2_62
126gboolean g_array_binary_search (GArray *array,
127 gconstpointer target,
128 GCompareFunc compare_func,
129 guint *out_match_index);
130GLIB_AVAILABLE_IN_ALL
131void g_array_set_clear_func (GArray *array,
132 GDestroyNotify clear_func);
133
134/* Resizable pointer array. This interface is much less complicated
135 * than the above. Add appends a pointer. Remove fills any cleared
136 * spot and shortens the array. remove_fast will again distort order.
137 */
138#define g_ptr_array_index(array,index_) ((array)->pdata)[index_]
139GLIB_AVAILABLE_IN_ALL
140GPtrArray* g_ptr_array_new (void);
141GLIB_AVAILABLE_IN_ALL
142GPtrArray* g_ptr_array_new_with_free_func (GDestroyNotify element_free_func);
143GLIB_AVAILABLE_IN_2_64
144gpointer* g_ptr_array_steal (GPtrArray *array,
145 gsize *len);
146GLIB_AVAILABLE_IN_2_62
147GPtrArray *g_ptr_array_copy (GPtrArray *array,
148 GCopyFunc func,
149 gpointer user_data);
150GLIB_AVAILABLE_IN_ALL
151GPtrArray* g_ptr_array_sized_new (guint reserved_size);
152GLIB_AVAILABLE_IN_ALL
153GPtrArray* g_ptr_array_new_full (guint reserved_size,
154 GDestroyNotify element_free_func);
155GLIB_AVAILABLE_IN_ALL
156gpointer* g_ptr_array_free (GPtrArray *array,
157 gboolean free_seg);
158GLIB_AVAILABLE_IN_ALL
159GPtrArray* g_ptr_array_ref (GPtrArray *array);
160GLIB_AVAILABLE_IN_ALL
161void g_ptr_array_unref (GPtrArray *array);
162GLIB_AVAILABLE_IN_ALL
163void g_ptr_array_set_free_func (GPtrArray *array,
164 GDestroyNotify element_free_func);
165GLIB_AVAILABLE_IN_ALL
166void g_ptr_array_set_size (GPtrArray *array,
167 gint length);
168GLIB_AVAILABLE_IN_ALL
169gpointer g_ptr_array_remove_index (GPtrArray *array,
170 guint index_);
171GLIB_AVAILABLE_IN_ALL
172gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
173 guint index_);
174GLIB_AVAILABLE_IN_2_58
175gpointer g_ptr_array_steal_index (GPtrArray *array,
176 guint index_);
177GLIB_AVAILABLE_IN_2_58
178gpointer g_ptr_array_steal_index_fast (GPtrArray *array,
179 guint index_);
180GLIB_AVAILABLE_IN_ALL
181gboolean g_ptr_array_remove (GPtrArray *array,
182 gpointer data);
183GLIB_AVAILABLE_IN_ALL
184gboolean g_ptr_array_remove_fast (GPtrArray *array,
185 gpointer data);
186GLIB_AVAILABLE_IN_ALL
187GPtrArray *g_ptr_array_remove_range (GPtrArray *array,
188 guint index_,
189 guint length);
190GLIB_AVAILABLE_IN_ALL
191void g_ptr_array_add (GPtrArray *array,
192 gpointer data);
193GLIB_AVAILABLE_IN_2_62
194void g_ptr_array_extend (GPtrArray *array_to_extend,
195 GPtrArray *array,
196 GCopyFunc func,
197 gpointer user_data);
198GLIB_AVAILABLE_IN_2_62
199void g_ptr_array_extend_and_steal (GPtrArray *array_to_extend,
200 GPtrArray *array);
201GLIB_AVAILABLE_IN_2_40
202void g_ptr_array_insert (GPtrArray *array,
203 gint index_,
204 gpointer data);
205GLIB_AVAILABLE_IN_ALL
206void g_ptr_array_sort (GPtrArray *array,
207 GCompareFunc compare_func);
208GLIB_AVAILABLE_IN_ALL
209void g_ptr_array_sort_with_data (GPtrArray *array,
210 GCompareDataFunc compare_func,
211 gpointer user_data);
212GLIB_AVAILABLE_IN_ALL
213void g_ptr_array_foreach (GPtrArray *array,
214 GFunc func,
215 gpointer user_data);
216GLIB_AVAILABLE_IN_2_54
217gboolean g_ptr_array_find (GPtrArray *haystack,
218 gconstpointer needle,
219 guint *index_);
220GLIB_AVAILABLE_IN_2_54
221gboolean g_ptr_array_find_with_equal_func (GPtrArray *haystack,
222 gconstpointer needle,
223 GEqualFunc equal_func,
224 guint *index_);
225
226
227/* Byte arrays, an array of guint8. Implemented as a GArray,
228 * but type-safe.
229 */
230
231GLIB_AVAILABLE_IN_ALL
232GByteArray* g_byte_array_new (void);
233GLIB_AVAILABLE_IN_ALL
234GByteArray* g_byte_array_new_take (guint8 *data,
235 gsize len);
236GLIB_AVAILABLE_IN_2_64
237guint8* g_byte_array_steal (GByteArray *array,
238 gsize *len);
239GLIB_AVAILABLE_IN_ALL
240GByteArray* g_byte_array_sized_new (guint reserved_size);
241GLIB_AVAILABLE_IN_ALL
242guint8* g_byte_array_free (GByteArray *array,
243 gboolean free_segment);
244GLIB_AVAILABLE_IN_ALL
245GBytes* g_byte_array_free_to_bytes (GByteArray *array);
246GLIB_AVAILABLE_IN_ALL
247GByteArray *g_byte_array_ref (GByteArray *array);
248GLIB_AVAILABLE_IN_ALL
249void g_byte_array_unref (GByteArray *array);
250GLIB_AVAILABLE_IN_ALL
251GByteArray* g_byte_array_append (GByteArray *array,
252 const guint8 *data,
253 guint len);
254GLIB_AVAILABLE_IN_ALL
255GByteArray* g_byte_array_prepend (GByteArray *array,
256 const guint8 *data,
257 guint len);
258GLIB_AVAILABLE_IN_ALL
259GByteArray* g_byte_array_set_size (GByteArray *array,
260 guint length);
261GLIB_AVAILABLE_IN_ALL
262GByteArray* g_byte_array_remove_index (GByteArray *array,
263 guint index_);
264GLIB_AVAILABLE_IN_ALL
265GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
266 guint index_);
267GLIB_AVAILABLE_IN_ALL
268GByteArray* g_byte_array_remove_range (GByteArray *array,
269 guint index_,
270 guint length);
271GLIB_AVAILABLE_IN_ALL
272void g_byte_array_sort (GByteArray *array,
273 GCompareFunc compare_func);
274GLIB_AVAILABLE_IN_ALL
275void g_byte_array_sort_with_data (GByteArray *array,
276 GCompareDataFunc compare_func,
277 gpointer user_data);
278
279G_END_DECLS
280
281#endif /* __G_ARRAY_H__ */
282

source code of include/glib-2.0/glib/garray.h