Split glib.h into many header files mostly according to the resp.
[platform/upstream/glib.git] / 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 #include <gtypes.h>
31
32 G_BEGIN_DECLS
33
34 typedef struct _GArray          GArray;
35 typedef struct _GByteArray      GByteArray;
36 typedef struct _GPtrArray       GPtrArray;
37
38 struct _GArray
39 {
40   gchar *data;
41   guint len;
42 };
43
44 struct _GByteArray
45 {
46   guint8 *data;
47   guint   len;
48 };
49
50 struct _GPtrArray
51 {
52   gpointer *pdata;
53   guint     len;
54 };
55
56 /* Resizable arrays, remove fills any cleared spot and shortens the
57  * array, while preserving the order. remove_fast will distort the
58  * order by moving the last element to the position of the removed 
59  */
60
61 #define g_array_append_val(a,v)   g_array_append_vals (a, &v, 1)
62 #define g_array_prepend_val(a,v)  g_array_prepend_vals (a, &v, 1)
63 #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &v, 1)
64 #define g_array_index(a,t,i)      (((t*) (a)->data) [(i)])
65
66 GArray* g_array_new               (gboolean         zero_terminated,
67                                    gboolean         clear,
68                                    guint            element_size);
69 GArray* g_array_sized_new         (gboolean         zero_terminated,
70                                    gboolean         clear,
71                                    guint            element_size,
72                                    guint            reserved_size);
73 gchar*  g_array_free              (GArray          *array,
74                                    gboolean         free_segment);
75 GArray* g_array_append_vals       (GArray          *array,
76                                    gconstpointer    data,
77                                    guint            len);
78 GArray* g_array_prepend_vals      (GArray          *array,
79                                    gconstpointer    data,
80                                    guint            len);
81 GArray* g_array_insert_vals       (GArray          *array,
82                                    guint            index,
83                                    gconstpointer    data,
84                                    guint            len);
85 GArray* g_array_set_size          (GArray          *array,
86                                    guint            length);
87 GArray* g_array_remove_index      (GArray          *array,
88                                    guint            index);
89 GArray* g_array_remove_index_fast (GArray          *array,
90                                    guint            index);
91
92 /* Resizable pointer array.  This interface is much less complicated
93  * than the above.  Add appends appends a pointer.  Remove fills any
94  * cleared spot and shortens the array. remove_fast will again distort
95  * order.  
96  */
97 #define     g_ptr_array_index(array,index) (array->pdata)[index]
98 GPtrArray*  g_ptr_array_new                (void);
99 GPtrArray*  g_ptr_array_sized_new          (guint        reserved_size);
100 gpointer*   g_ptr_array_free               (GPtrArray   *array,
101                                             gboolean     free_seg);
102 void        g_ptr_array_set_size           (GPtrArray   *array,
103                                             gint         length);
104 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
105                                             guint        index);
106 gpointer    g_ptr_array_remove_index_fast  (GPtrArray   *array,
107                                             guint        index);
108 gboolean    g_ptr_array_remove             (GPtrArray   *array,
109                                             gpointer     data);
110 gboolean    g_ptr_array_remove_fast        (GPtrArray   *array,
111                                             gpointer     data);
112 void        g_ptr_array_add                (GPtrArray   *array,
113                                             gpointer     data);
114
115 /* Byte arrays, an array of guint8.  Implemented as a GArray,
116  * but type-safe.
117  */
118
119 GByteArray* g_byte_array_new               (void);
120 GByteArray* g_byte_array_sized_new         (guint        reserved_size);
121 guint8*     g_byte_array_free              (GByteArray   *array,
122                                             gboolean      free_segment);
123 GByteArray* g_byte_array_append            (GByteArray   *array,
124                                             const guint8 *data,
125                                             guint         len);
126 GByteArray* g_byte_array_prepend           (GByteArray   *array,
127                                             const guint8 *data,
128                                             guint         len);
129 GByteArray* g_byte_array_set_size          (GByteArray   *array,
130                                             guint         length);
131 GByteArray* g_byte_array_remove_index      (GByteArray   *array,
132                                             guint         index);
133 GByteArray* g_byte_array_remove_index_fast (GByteArray   *array,
134                                             guint         index);
135
136 G_END_DECLS
137
138 #endif /* __G_ARRAY_H__ */
139