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