2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit 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
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Arrays.html
53 private import glib
.glibtypes
;
55 private import lib
.glib
;
57 private import glib
.ListG
;
58 private import glib
.Str
;
62 * Arrays are similar to standard C arrays, except that they grow automatically
63 * as elements are added.
64 * Array elements can be of any size (though all elements of one array are the
65 * same size), and the array can be automatically cleared to '0's and
67 * To create a new array use g_array_new().
68 * To add elements to an array, use g_array_append_val(), g_array_append_vals(),
69 * g_array_prepend_val(), and g_array_prepend_vals().
70 * To access an element of an array, use g_array_index().
71 * To set the size of an array, use g_array_set_size().
72 * To free an array, use g_array_free().
73 * Example5.Using a GArray to store gint values
76 * /+* We create a new array to store gint values.
77 * We don't want it zero-terminated or cleared to 0's. +/
78 * garray = g_array_new (FALSE, FALSE, sizeof (gint));
79 * for (i = 0; i < 10000; i++)
80 * g_array_append_val (garray, i);
81 * for (i = 0; i < 10000; i++)
82 * if (g_array_index (garray, gint, i) != i)
83 * g_print ("ERROR: got %d instead of %d\n",
84 * g_array_index (garray, gint, i), i);
85 * g_array_free (garray, TRUE);
90 /** the main Gtk struct */
91 protected GArray
* gArray
;
94 public GArray
* getArrayGStruct()
100 /** the main Gtk struct as a void* */
101 protected void* getStruct()
103 return cast(void*)gArray
;
107 * Sets our main struct and passes it to the parent class
109 public this (GArray
* gArray
)
111 this.gArray
= gArray
;
119 * Creates a new GArray.
121 * TRUE if the array should have an extra element at the end
124 * TRUE if GArray elements should be automatically cleared to 0
125 * when they are allocated.
127 * the size of each element in bytes.
131 public this (int zeroTerminated
, int clear
, uint elementSize
)
133 // GArray* g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size);
134 this(cast(GArray
*)g_array_new(zeroTerminated
, clear
, elementSize
) );
138 * Creates a new GArray with reserved_size elements
139 * preallocated. This avoids frequent reallocation, if you are going to
140 * add many elements to the array. Note however that the size of the
143 * TRUE if the array should have an extra element at the end with all bits cleared.
145 * TRUE if all bits in the array should be cleared to 0 on allocation.
147 * size of each element in the array.
149 * number of elements preallocated.
153 public static ArrayG
sizedNew(int zeroTerminated
, int clear
, uint elementSize
, uint reservedSize
)
155 // GArray* g_array_sized_new (gboolean zero_terminated, gboolean clear_, guint element_size, guint reserved_size);
156 return new ArrayG( g_array_sized_new(zeroTerminated
, clear
, elementSize
, reservedSize
) );
161 * Adds len elements onto the end of the array.
165 * a pointer to the elements to append to the end of the array.
167 * the number of elements to append.
171 public ArrayG
appendVals(void* data
, uint len
)
173 // GArray* g_array_append_vals (GArray *array, gconstpointer data, guint len);
174 return new ArrayG( g_array_append_vals(gArray
, data
, len
) );
179 * Adds len elements onto the start of the array.
180 * This operation is slower than g_array_append_vals() since the existing elements
181 * in the array have to be moved to make space for the new elements.
185 * a pointer to the elements to prepend to the start of the array.
187 * the number of elements to prepend.
191 public ArrayG
prependVals(void* data
, uint len
)
193 // GArray* g_array_prepend_vals (GArray *array, gconstpointer data, guint len);
194 return new ArrayG( g_array_prepend_vals(gArray
, data
, len
) );
199 * Inserts len elements into a GArray at the given index.
203 * the index to place the elements at.
205 * a pointer to the elements to insert.
207 * the number of elements to insert.
211 public ArrayG
insertVals(uint index
, void* data
, uint len
)
213 // GArray* g_array_insert_vals (GArray *array, guint index_, gconstpointer data, guint len);
214 return new ArrayG( g_array_insert_vals(gArray
, index
, data
, len
) );
218 * Removes the element at the given index from a GArray.
219 * The following elements are moved down one place.
223 * the index of the element to remove.
227 public ArrayG
removeIndex(uint index
)
229 // GArray* g_array_remove_index (GArray *array, guint index_);
230 return new ArrayG( g_array_remove_index(gArray
, index
) );
234 * Removes the element at the given index from a GArray.
235 * The last element in the array is used to fill in the space, so this function
236 * does not preserve the order of the GArray. But it is faster than
237 * g_array_remove_index().
241 * the index of the element to remove.
245 public ArrayG
removeIndexFast(uint index
)
247 // GArray* g_array_remove_index_fast (GArray *array, guint index_);
248 return new ArrayG( g_array_remove_index_fast(gArray
, index
) );
252 * Removes the given number of elements starting at the given index from a
253 * GArray. The following elements are moved to close the gap.
257 * the index of the first element to remove.
259 * the number of elements to remove.
264 public ArrayG
removeRange(uint index
, uint length
)
266 // GArray* g_array_remove_range (GArray *array, guint index_, guint length);
267 return new ArrayG( g_array_remove_range(gArray
, index
, length
) );
271 * Sorts a GArray using compare_func which should be a qsort()-style comparison
272 * function (returns less than zero for first arg is less than second arg,
273 * zero for equal, greater zero if first arg is greater than second arg).
274 * If two array elements compare equal, their order in the sorted array is
279 * comparison function.
281 public void sort(GCompareFunc compareFunc
)
283 // void g_array_sort (GArray *array, GCompareFunc compare_func);
284 g_array_sort(gArray
, compareFunc
);
288 * Like g_array_sort(), but the comparison function receives an extra user data
293 * comparison function.
295 * data to pass to compare_func.
297 public void sortWithData(GCompareDataFunc compareFunc
, void* userData
)
299 // void g_array_sort_with_data (GArray *array, GCompareDataFunc compare_func, gpointer user_data);
300 g_array_sort_with_data(gArray
, compareFunc
, userData
);
305 * Sets the size of the array, expanding it if necessary.
306 * If the array was created with clear_ set to TRUE, the new elements are set to 0.
310 * the new size of the GArray.
314 public ArrayG
setSize(uint length
)
316 // GArray* g_array_set_size (GArray *array, guint length);
317 return new ArrayG( g_array_set_size(gArray
, length
) );
321 * Frees the memory allocated for the GArray.
322 * If free_segment is TRUE it frees the memory block holding the elements
323 * as well. Pass FALSE if you want to free the GArray wrapper but preserve
324 * the underlying array for use elsewhere.
326 * If array elements contain dynamically-allocated memory, they should be freed
331 * if TRUE the actual element data is freed as well.
333 * the element data if free_segment is FALSE, otherwise NULL
335 public char[] free(int freeSegment
)
337 // gchar* g_array_free (GArray *array, gboolean free_segment);
338 return Str
.toString(g_array_free(gArray
, freeSegment
) );