Updated Traditional Chinese translation(Hong Kong and Taiwan)
[glib.git] / glib / garray.h
blob6bc51f797ec119c78abb936f3f9a31be1cd41b10
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
27 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
28 #error "Only <glib.h> can be included directly."
29 #endif
31 #ifndef __G_ARRAY_H__
32 #define __G_ARRAY_H__
34 #include <glib/gtypes.h>
36 G_BEGIN_DECLS
38 typedef struct _GArray GArray;
39 typedef struct _GByteArray GByteArray;
40 typedef struct _GPtrArray GPtrArray;
42 struct _GArray
44 gchar *data;
45 guint len;
48 struct _GByteArray
50 guint8 *data;
51 guint len;
54 struct _GPtrArray
56 gpointer *pdata;
57 guint len;
60 /* Resizable arrays. remove fills any cleared spot and shortens the
61 * array, while preserving the order. remove_fast will distort the
62 * order by moving the last element to the position of the removed.
65 #define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
66 #define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
67 #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
68 #define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
70 GArray* g_array_new (gboolean zero_terminated,
71 gboolean clear_,
72 guint element_size);
73 GArray* g_array_sized_new (gboolean zero_terminated,
74 gboolean clear_,
75 guint element_size,
76 guint reserved_size);
77 gchar* g_array_free (GArray *array,
78 gboolean free_segment);
79 GArray *g_array_ref (GArray *array);
80 void g_array_unref (GArray *array);
81 guint g_array_get_element_size (GArray *array);
82 GArray* g_array_append_vals (GArray *array,
83 gconstpointer data,
84 guint len);
85 GArray* g_array_prepend_vals (GArray *array,
86 gconstpointer data,
87 guint len);
88 GArray* g_array_insert_vals (GArray *array,
89 guint index_,
90 gconstpointer data,
91 guint len);
92 GArray* g_array_set_size (GArray *array,
93 guint length);
94 GArray* g_array_remove_index (GArray *array,
95 guint index_);
96 GArray* g_array_remove_index_fast (GArray *array,
97 guint index_);
98 GArray* g_array_remove_range (GArray *array,
99 guint index_,
100 guint length);
101 void g_array_sort (GArray *array,
102 GCompareFunc compare_func);
103 void g_array_sort_with_data (GArray *array,
104 GCompareDataFunc compare_func,
105 gpointer user_data);
107 /* Resizable pointer array. This interface is much less complicated
108 * than the above. Add appends a pointer. Remove fills any cleared
109 * spot and shortens the array. remove_fast will again distort order.
111 #define g_ptr_array_index(array,index_) ((array)->pdata)[index_]
112 GPtrArray* g_ptr_array_new (void);
113 GPtrArray* g_ptr_array_new_with_free_func (GDestroyNotify element_free_func);
114 GPtrArray* g_ptr_array_sized_new (guint reserved_size);
115 gpointer* g_ptr_array_free (GPtrArray *array,
116 gboolean free_seg);
117 GPtrArray* g_ptr_array_ref (GPtrArray *array);
118 void g_ptr_array_unref (GPtrArray *array);
119 void g_ptr_array_set_free_func (GPtrArray *array,
120 GDestroyNotify element_free_func);
121 void g_ptr_array_set_size (GPtrArray *array,
122 gint length);
123 gpointer g_ptr_array_remove_index (GPtrArray *array,
124 guint index_);
125 gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
126 guint index_);
127 gboolean g_ptr_array_remove (GPtrArray *array,
128 gpointer data);
129 gboolean g_ptr_array_remove_fast (GPtrArray *array,
130 gpointer data);
131 void g_ptr_array_remove_range (GPtrArray *array,
132 guint index_,
133 guint length);
134 void g_ptr_array_add (GPtrArray *array,
135 gpointer data);
136 void g_ptr_array_sort (GPtrArray *array,
137 GCompareFunc compare_func);
138 void g_ptr_array_sort_with_data (GPtrArray *array,
139 GCompareDataFunc compare_func,
140 gpointer user_data);
141 void g_ptr_array_foreach (GPtrArray *array,
142 GFunc func,
143 gpointer user_data);
146 /* Byte arrays, an array of guint8. Implemented as a GArray,
147 * but type-safe.
150 GByteArray* g_byte_array_new (void);
151 GByteArray* g_byte_array_sized_new (guint reserved_size);
152 guint8* g_byte_array_free (GByteArray *array,
153 gboolean free_segment);
154 GByteArray *g_byte_array_ref (GByteArray *array);
155 void g_byte_array_unref (GByteArray *array);
156 GByteArray* g_byte_array_append (GByteArray *array,
157 const guint8 *data,
158 guint len);
159 GByteArray* g_byte_array_prepend (GByteArray *array,
160 const guint8 *data,
161 guint len);
162 GByteArray* g_byte_array_set_size (GByteArray *array,
163 guint length);
164 GByteArray* g_byte_array_remove_index (GByteArray *array,
165 guint index_);
166 GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
167 guint index_);
168 GByteArray* g_byte_array_remove_range (GByteArray *array,
169 guint index_,
170 guint length);
171 void g_byte_array_sort (GByteArray *array,
172 GCompareFunc compare_func);
173 void g_byte_array_sort_with_data (GByteArray *array,
174 GCompareDataFunc compare_func,
175 gpointer user_data);
177 G_END_DECLS
179 #endif /* __G_ARRAY_H__ */