PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/src/wrappers/glib/library/data_types/glib_arrays.e

http://github.com/tybor/Liberty
Specman e | 288 lines | 7 code | 65 blank | 216 comment | 0 complexity | a895b3a9b04464e35571068bf287bcad MD5 | raw file
  1indexing
  2	copyright: "(C) 2005 Paolo Redaelli "
  3	license: "LGPL v2 or later"
  4	date: "$Date:$"
  5	revision: "$REvision:$"
  6
  7class GLIB_ARRAYS
  8-- Prev 	Up 	Home 	GLib Reference Manual 	Next
  9-- Top  |  Description
 10-- Arrays
 11
 12-- Arrays %G รข€”%@ arrays of arbitrary elements which grow automatically as elements are added.
 13	
 14-- Synopsis
 15
 16-- #include <glib.h>
 17
 18
 19--             GArray;
 20-- GArray*     g_array_new                     (gboolean zero_terminated,
 21--                                              gboolean clear_,
 22--                                              guint element_size);
 23-- GArray*     g_array_sized_new               (gboolean zero_terminated,
 24--                                              gboolean clear_,
 25--                                              guint element_size,
 26--                                              guint reserved_size);
 27-- #define     g_array_append_val              (a,v)
 28-- GArray*     g_array_append_vals             (GArray *array,
 29--                                              gconstpointer data,
 30--                                              guint len);
 31-- #define     g_array_prepend_val             (a,v)
 32-- GArray*     g_array_prepend_vals            (GArray *array,
 33--                                              gconstpointer data,
 34--                                              guint len);
 35-- #define     g_array_insert_val              (a,i,v)
 36-- GArray*     g_array_insert_vals             (GArray *array,
 37--                                              guint index_,
 38--                                              gconstpointer data,
 39--                                              guint len);
 40-- GArray*     g_array_remove_index            (GArray *array,
 41--                                              guint index_);
 42-- GArray*     g_array_remove_index_fast       (GArray *array,
 43--                                              guint index_);
 44-- GArray*     g_array_remove_range            (GArray *array,
 45--                                              guint index_,
 46--                                              guint length);
 47-- void        g_array_sort                    (GArray *array,
 48--                                              GCompareFunc compare_func);
 49-- void        g_array_sort_with_data          (GArray *array,
 50--                                              GCompareDataFunc compare_func,
 51--                                              gpointer user_data);
 52-- #define     g_array_index                   (a,t,i)
 53-- GArray*     g_array_set_size                (GArray *array,
 54--                                              guint length);
 55-- gchar*      g_array_free                    (GArray *array,
 56--                                              gboolean free_segment);
 57
 58-- Description
 59
 60-- Arrays are similar to standard C arrays, except that they grow automatically as elements are added.
 61
 62-- Array elements can be of any size (though all elements of one array are the same size), and the array can be automatically cleared to '0's and zero-terminated.
 63
 64-- To create a new array use g_array_new().
 65
 66-- To add elements to an array, use g_array_append_val(), g_array_append_vals(), g_array_prepend_val(), and g_array_prepend_vals().
 67
 68-- To access an element of an array, use g_array_index().
 69
 70-- To set the size of an array, use g_array_set_size().
 71
 72-- To free an array, use g_array_free().
 73
 74-- Example 3. Using a GArray to store gint values
 75
 76--   GArray *garray;
 77--   gint i;
 78
 79--   /* We create a new array to store gint values.
 80--      We don't want it zero-terminated or cleared to 0's. */
 81--   garray = g_array_new (FALSE, FALSE, sizeof (gint));
 82--   for (i = 0; i < 10000; i++)
 83--     g_array_append_val (garray, i);
 84
 85--   for (i = 0; i < 10000; i++)
 86--     if (g_array_index (garray, gint, i) != i)
 87--       g_print ("ERROR: got %d instead of %d\n",
 88--                g_array_index (garray, gint, i), i);
 89
 90--   g_array_free (garray, TRUE);
 91
 92-- Details
 93-- GArray
 94
 95-- typedef struct {
 96--   gchar *data;
 97--   guint len;
 98-- } GArray;
 99
100-- Contains the public fields of an Array.
101-- gchar *data; 	a pointer to the element data. The data may be moved as elements are added to the GArray.
102-- guint len; 	the number of elements in the GArray.
103-- g_array_new ()
104
105-- GArray*     g_array_new                     (gboolean zero_terminated,
106--                                              gboolean clear_,
107--                                              guint element_size);
108
109-- Creates a new GArray.
110-- zero_terminated : 	TRUE if the array should have an extra element at the end which is set to 0.
111-- clear_ : 	TRUE if GArray elements should be automatically cleared to 0 when they are allocated.
112-- element_size : 	the size of each element in bytes.
113-- Returns : 	the new GArray.
114-- g_array_sized_new ()
115
116-- GArray*     g_array_sized_new               (gboolean zero_terminated,
117--                                              gboolean clear_,
118--                                              guint element_size,
119--                                              guint reserved_size);
120
121-- Creates a new GArray with reserved_size elements preallocated. This avoids frequent reallocation, if you are going to add many elements to the array. Note however that the size of the array is still 0.
122-- zero_terminated : 	TRUE if the array should have an extra element at the end with all bits cleared.
123-- clear_ : 	TRUE if all bits in the array should be cleared to 0 on allocation.
124-- element_size : 	size of each element in the array.
125-- reserved_size : 	number of elements preallocated.
126-- Returns : 	the new GArray.
127-- g_array_append_val()
128
129-- #define     g_array_append_val(a,v)
130
131-- Adds the value on to the end of the array. The array will grow in size automatically if necessary.
132-- Note
133
134-- g_array_append_val() is a macro which uses a reference to the value parameter v. This means that you cannot use it with literal values such as "27". You must use variables.
135-- a : 	a GArray.
136-- v : 	the value to append to the GArray.
137-- Returns : 	the GArray.
138-- g_array_append_vals ()
139
140-- GArray*     g_array_append_vals             (GArray *array,
141--                                              gconstpointer data,
142--                                              guint len);
143
144-- Adds len elements onto the end of the array.
145-- array : 	a GArray.
146-- data : 	a pointer to the elements to append to the end of the array.
147-- len : 	the number of elements to append.
148-- Returns : 	the GArray.
149-- g_array_prepend_val()
150
151-- #define     g_array_prepend_val(a,v)
152
153-- Adds the value on to the start of the array. The array will grow in size automatically if necessary.
154
155-- This operation is slower than g_array_append_val() since the existing elements in the array have to be moved to make space for the new element.
156-- Note
157
158-- g_array_prepend_val() is a macro which uses a reference to the value parameter v. This means that you cannot use it with literal values such as "27". You must use variables.
159-- a : 	a GArray.
160-- v : 	the value to prepend to the GArray.
161-- Returns : 	the GArray.
162-- g_array_prepend_vals ()
163
164-- GArray*     g_array_prepend_vals            (GArray *array,
165--                                              gconstpointer data,
166--                                              guint len);
167
168-- Adds len elements onto the start of the array.
169
170-- This operation is slower than g_array_append_vals() since the existing elements in the array have to be moved to make space for the new elements.
171-- array : 	a GArray.
172-- data : 	a pointer to the elements to prepend to the start of the array.
173-- len : 	the number of elements to prepend.
174-- Returns : 	the GArray.
175-- g_array_insert_val()
176
177-- #define     g_array_insert_val(a,i,v)
178
179-- Inserts an element into an array at the given index.
180-- Note
181
182-- g_array_insert_val() is a macro which uses a reference to the value parameter v. This means that you cannot use it with literal values such as "27". You must use variables.
183-- a : 	a GArray.
184-- i : 	the index to place the element at.
185-- v : 	the value to insert into the array.
186-- Returns : 	the GArray.
187-- g_array_insert_vals ()
188
189-- GArray*     g_array_insert_vals             (GArray *array,
190--                                              guint index_,
191--                                              gconstpointer data,
192--                                              guint len);
193
194-- Inserts len elements into a GArray at the given index.
195-- array : 	a GArray.
196-- index_ : 	the index to place the elements at.
197-- data : 	a pointer to the elements to insert.
198-- len : 	the number of elements to insert.
199-- Returns : 	the GArray.
200-- g_array_remove_index ()
201
202-- GArray*     g_array_remove_index            (GArray *array,
203--                                              guint index_);
204
205-- Removes the element at the given index from a GArray. The following elements are moved down one place.
206-- array : 	a GArray.
207-- index_ : 	the index of the element to remove.
208-- Returns : 	the GArray.
209-- g_array_remove_index_fast ()
210
211-- GArray*     g_array_remove_index_fast       (GArray *array,
212--                                              guint index_);
213
214-- Removes the element at the given index from a GArray. The last element in the array is used to fill in the space, so this function does not preserve the order of the GArray. But it is faster than g_array_remove_index().
215-- array : 	a GArray.
216-- index_ : 	the index of the element to remove.
217-- Returns : 	the GArray.
218-- g_array_remove_range ()
219
220-- GArray*     g_array_remove_range            (GArray *array,
221--                                              guint index_,
222--                                              guint length);
223
224-- Removes the given number of elements starting at the given index from a GArray. The following elements are moved to close the gap.
225-- array : 	a GArray.
226-- index_ : 	the index of the first element to remove.
227-- length : 	the number of elements to remove.
228-- Returns : 	the GArray.
229
230-- Since 2.4
231-- g_array_sort ()
232
233-- void        g_array_sort                    (GArray *array,
234--                                              GCompareFunc compare_func);
235
236-- Sorts a GArray using compare_func which should be a qsort()-style comparison function (returns -1 for first arg is less than second arg, 0 for equal, 1 if first arg is greater than second arg).
237-- array : 	a GArray.
238-- compare_func : 	comparison function.
239-- g_array_sort_with_data ()
240
241-- void        g_array_sort_with_data          (GArray *array,
242--                                              GCompareDataFunc compare_func,
243--                                              gpointer user_data);
244
245-- Like g_array_sort(), but the comparison function receives a user data argument.
246-- array : 	a GArray.
247-- compare_func : 	comparison function.
248-- user_data : 	data to pass to compare_func.
249-- g_array_index()
250
251-- #define     g_array_index(a,t,i)
252
253-- Returns the element of a GArray at the given index. The return value is cast to the given type.
254
255-- Example 4. Getting a pointer to an element in a GArray
256
257--   EDayViewEvent *event;
258
259--   /* This gets a pointer to the 3rd element in the array of EDayViewEvent
260--      structs. */
261--   event = &g_array_index (events, EDayViewEvent, 3);
262
263-- a : 	a GArray.
264-- t : 	the type of the elements.
265-- i : 	the index of the element to return.
266-- Returns : 	the element of the GArray at the index given by i.
267-- g_array_set_size ()
268
269-- GArray*     g_array_set_size                (GArray *array,
270--                                              guint length);
271
272-- Sets the size of the array, expanding it if necessary. If the array was created with clear_ set to TRUE, the new elements are set to 0.
273-- array : 	a GArray.
274-- length : 	the new size of the GArray.
275-- Returns : 	the GArray.
276-- g_array_free ()
277
278-- gchar*      g_array_free                    (GArray *array,
279--                                              gboolean free_segment);
280
281-- Frees the memory allocated for the GArray. If free_segment is TRUE it frees the memory block holding the elements as well. Pass FALSE if you want to free the GArray wrapper but preserve the underlying array for use elsewhere.
282-- Note
283
284-- If array elements contain dynamically-allocated memory, they should be freed first.
285-- array : 	a GArray.
286-- free_segment : 	if TRUE the actual element data is freed as well.
287-- Returns : 	the element data if free_segment is FALSE, otherwise NULL
288end