williamr@2
|
1 |
/* GLIB - Library of useful routines for C programming
|
williamr@2
|
2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
williamr@2
|
3 |
* Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* This library is free software; you can redistribute it and/or
|
williamr@2
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
williamr@2
|
7 |
* License as published by the Free Software Foundation; either
|
williamr@2
|
8 |
* version 2 of the License, or (at your option) any later version.
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This library is distributed in the hope that it will be useful,
|
williamr@2
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
williamr@2
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
williamr@2
|
13 |
* Lesser General Public License for more details.
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
williamr@2
|
16 |
* License along with this library; if not, write to the
|
williamr@2
|
17 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
williamr@2
|
18 |
* Boston, MA 02111-1307, USA.
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
|
williamr@2
|
21 |
/*
|
williamr@2
|
22 |
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
williamr@2
|
23 |
* file for a list of people on the GLib Team. See the ChangeLog
|
williamr@2
|
24 |
* files for a list of changes. These files are distributed with
|
williamr@2
|
25 |
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
williamr@2
|
26 |
*/
|
williamr@2
|
27 |
|
williamr@2
|
28 |
#ifndef __G_ARRAY_H__
|
williamr@2
|
29 |
#define __G_ARRAY_H__
|
williamr@2
|
30 |
|
williamr@2
|
31 |
#include <_ansi.h>
|
williamr@2
|
32 |
#include <glib/gtypes.h>
|
williamr@2
|
33 |
|
williamr@2
|
34 |
G_BEGIN_DECLS
|
williamr@2
|
35 |
|
williamr@2
|
36 |
typedef struct _GArray GArray;
|
williamr@2
|
37 |
typedef struct _GByteArray GByteArray;
|
williamr@2
|
38 |
typedef struct _GPtrArray GPtrArray;
|
williamr@2
|
39 |
|
williamr@2
|
40 |
struct _GArray
|
williamr@2
|
41 |
{
|
williamr@2
|
42 |
gchar *data;
|
williamr@2
|
43 |
guint len;
|
williamr@2
|
44 |
};
|
williamr@2
|
45 |
|
williamr@2
|
46 |
struct _GByteArray
|
williamr@2
|
47 |
{
|
williamr@2
|
48 |
guint8 *data;
|
williamr@2
|
49 |
guint len;
|
williamr@2
|
50 |
};
|
williamr@2
|
51 |
|
williamr@2
|
52 |
struct _GPtrArray
|
williamr@2
|
53 |
{
|
williamr@2
|
54 |
gpointer *pdata;
|
williamr@2
|
55 |
guint len;
|
williamr@2
|
56 |
};
|
williamr@2
|
57 |
|
williamr@2
|
58 |
/* Resizable arrays. remove fills any cleared spot and shortens the
|
williamr@2
|
59 |
* array, while preserving the order. remove_fast will distort the
|
williamr@2
|
60 |
* order by moving the last element to the position of the removed.
|
williamr@2
|
61 |
*/
|
williamr@2
|
62 |
|
williamr@2
|
63 |
#define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
|
williamr@2
|
64 |
#define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
|
williamr@2
|
65 |
#define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
|
williamr@2
|
66 |
#define g_array_index(a,t,i) (((t*) (a)->data) [(i)])
|
williamr@2
|
67 |
|
williamr@2
|
68 |
IMPORT_C GArray* g_array_new (gboolean zero_terminated,
|
williamr@2
|
69 |
gboolean clear_,
|
williamr@2
|
70 |
guint element_size);
|
williamr@2
|
71 |
IMPORT_C GArray* g_array_sized_new (gboolean zero_terminated,
|
williamr@2
|
72 |
gboolean clear_,
|
williamr@2
|
73 |
guint element_size,
|
williamr@2
|
74 |
guint reserved_size);
|
williamr@2
|
75 |
IMPORT_C gchar* g_array_free (GArray *array,
|
williamr@2
|
76 |
gboolean free_segment);
|
williamr@2
|
77 |
IMPORT_C GArray* g_array_append_vals (GArray *array,
|
williamr@2
|
78 |
gconstpointer data,
|
williamr@2
|
79 |
guint len);
|
williamr@2
|
80 |
IMPORT_C GArray* g_array_prepend_vals (GArray *array,
|
williamr@2
|
81 |
gconstpointer data,
|
williamr@2
|
82 |
guint len);
|
williamr@2
|
83 |
IMPORT_C GArray* g_array_insert_vals (GArray *array,
|
williamr@2
|
84 |
guint index_,
|
williamr@2
|
85 |
gconstpointer data,
|
williamr@2
|
86 |
guint len);
|
williamr@2
|
87 |
IMPORT_C GArray* g_array_set_size (GArray *array,
|
williamr@2
|
88 |
guint length);
|
williamr@2
|
89 |
IMPORT_C GArray* g_array_remove_index (GArray *array,
|
williamr@2
|
90 |
guint index_);
|
williamr@2
|
91 |
IMPORT_C GArray* g_array_remove_index_fast (GArray *array,
|
williamr@2
|
92 |
guint index_);
|
williamr@2
|
93 |
IMPORT_C GArray* g_array_remove_range (GArray *array,
|
williamr@2
|
94 |
guint index_,
|
williamr@2
|
95 |
guint length);
|
williamr@2
|
96 |
IMPORT_C void g_array_sort (GArray *array,
|
williamr@2
|
97 |
GCompareFunc compare_func);
|
williamr@2
|
98 |
IMPORT_C void g_array_sort_with_data (GArray *array,
|
williamr@2
|
99 |
GCompareDataFunc compare_func,
|
williamr@2
|
100 |
gpointer user_data);
|
williamr@2
|
101 |
|
williamr@2
|
102 |
/* Resizable pointer array. This interface is much less complicated
|
williamr@2
|
103 |
* than the above. Add appends a pointer. Remove fills any cleared
|
williamr@2
|
104 |
* spot and shortens the array. remove_fast will again distort order.
|
williamr@2
|
105 |
*/
|
williamr@2
|
106 |
#define g_ptr_array_index(array,index_) ((array)->pdata)[index_]
|
williamr@2
|
107 |
IMPORT_C GPtrArray* g_ptr_array_new (void);
|
williamr@2
|
108 |
IMPORT_C GPtrArray* g_ptr_array_sized_new (guint reserved_size);
|
williamr@2
|
109 |
IMPORT_C gpointer* g_ptr_array_free (GPtrArray *array,
|
williamr@2
|
110 |
gboolean free_seg);
|
williamr@2
|
111 |
IMPORT_C void g_ptr_array_set_size (GPtrArray *array,
|
williamr@2
|
112 |
gint length);
|
williamr@2
|
113 |
IMPORT_C gpointer g_ptr_array_remove_index (GPtrArray *array,
|
williamr@2
|
114 |
guint index_);
|
williamr@2
|
115 |
IMPORT_C gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
|
williamr@2
|
116 |
guint index_);
|
williamr@2
|
117 |
IMPORT_C gboolean g_ptr_array_remove (GPtrArray *array,
|
williamr@2
|
118 |
gpointer data);
|
williamr@2
|
119 |
IMPORT_C gboolean g_ptr_array_remove_fast (GPtrArray *array,
|
williamr@2
|
120 |
gpointer data);
|
williamr@2
|
121 |
IMPORT_C void g_ptr_array_remove_range (GPtrArray *array,
|
williamr@2
|
122 |
guint index_,
|
williamr@2
|
123 |
guint length);
|
williamr@2
|
124 |
IMPORT_C void g_ptr_array_add (GPtrArray *array,
|
williamr@2
|
125 |
gpointer data);
|
williamr@2
|
126 |
IMPORT_C void g_ptr_array_sort (GPtrArray *array,
|
williamr@2
|
127 |
GCompareFunc compare_func);
|
williamr@2
|
128 |
IMPORT_C void g_ptr_array_sort_with_data (GPtrArray *array,
|
williamr@2
|
129 |
GCompareDataFunc compare_func,
|
williamr@2
|
130 |
gpointer user_data);
|
williamr@2
|
131 |
IMPORT_C void g_ptr_array_foreach (GPtrArray *array,
|
williamr@2
|
132 |
GFunc func,
|
williamr@2
|
133 |
gpointer user_data);
|
williamr@2
|
134 |
|
williamr@2
|
135 |
|
williamr@2
|
136 |
/* Byte arrays, an array of guint8. Implemented as a GArray,
|
williamr@2
|
137 |
* but type-safe.
|
williamr@2
|
138 |
*/
|
williamr@2
|
139 |
|
williamr@2
|
140 |
IMPORT_C GByteArray* g_byte_array_new (void);
|
williamr@2
|
141 |
IMPORT_C GByteArray* g_byte_array_sized_new (guint reserved_size);
|
williamr@2
|
142 |
IMPORT_C guint8* g_byte_array_free (GByteArray *array,
|
williamr@2
|
143 |
gboolean free_segment);
|
williamr@2
|
144 |
IMPORT_C GByteArray* g_byte_array_append (GByteArray *array,
|
williamr@2
|
145 |
const guint8 *data,
|
williamr@2
|
146 |
guint len);
|
williamr@2
|
147 |
IMPORT_C GByteArray* g_byte_array_prepend (GByteArray *array,
|
williamr@2
|
148 |
const guint8 *data,
|
williamr@2
|
149 |
guint len);
|
williamr@2
|
150 |
IMPORT_C GByteArray* g_byte_array_set_size (GByteArray *array,
|
williamr@2
|
151 |
guint length);
|
williamr@2
|
152 |
IMPORT_C GByteArray* g_byte_array_remove_index (GByteArray *array,
|
williamr@2
|
153 |
guint index_);
|
williamr@2
|
154 |
IMPORT_C GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
|
williamr@2
|
155 |
guint index_);
|
williamr@2
|
156 |
IMPORT_C GByteArray* g_byte_array_remove_range (GByteArray *array,
|
williamr@2
|
157 |
guint index_,
|
williamr@2
|
158 |
guint length);
|
williamr@2
|
159 |
IMPORT_C void g_byte_array_sort (GByteArray *array,
|
williamr@2
|
160 |
GCompareFunc compare_func);
|
williamr@2
|
161 |
IMPORT_C void g_byte_array_sort_with_data (GByteArray *array,
|
williamr@2
|
162 |
GCompareDataFunc compare_func,
|
williamr@2
|
163 |
gpointer user_data);
|
williamr@2
|
164 |
|
williamr@2
|
165 |
|
williamr@2
|
166 |
G_END_DECLS
|
williamr@2
|
167 |
|
williamr@2
|
168 |
#endif /* __G_ARRAY_H__ */
|
williamr@2
|
169 |
|