2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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
58 import tango
.io
.Stdout
; // use the tango loging?
62 private import gtkc
.glibtypes
;
64 private import gtkc
.glib
;
67 private import glib
.ListG
;
68 private import glib
.Str
;
75 * Arrays are similar to standard C arrays, except that they grow automatically
76 * as elements are added.
77 * Array elements can be of any size (though all elements of one array are the
78 * same size), and the array can be automatically cleared to '0's and
80 * To create a new array use g_array_new().
81 * To add elements to an array, use g_array_append_val(), g_array_append_vals(),
82 * g_array_prepend_val(), and g_array_prepend_vals().
83 * To access an element of an array, use g_array_index().
84 * To set the size of an array, use g_array_set_size().
85 * To free an array, use g_array_free().
86 * Example5.Using a GArray to store gint values
89 * /+* We create a new array to store gint values.
90 * We don't want it zero-terminated or cleared to 0's. +/
91 * garray = g_array_new (FALSE, FALSE, sizeof (gint));
92 * for (i = 0; i < 10000; i++)
93 * g_array_append_val (garray, i);
94 * for (i = 0; i < 10000; i++)
95 * if (g_array_index (garray, gint, i) != i)
96 * g_print ("ERROR: got %d instead of %d\n",
97 * g_array_index (garray, gint, i), i);
98 * g_array_free (garray, TRUE);
103 /** the main Gtk struct */
104 protected GArray
* gArray
;
107 public GArray
* getArrayGStruct()
113 /** the main Gtk struct as a void* */
114 protected void* getStruct()
116 return cast(void*)gArray
;
120 * Sets our main struct and passes it to the parent class
122 public this (GArray
* gArray
)
126 if ( gArray
is null )
131 Stdout("struct gArray is null on constructor").newline
;
135 printf("struct gArray is null on constructor");
142 assert(gArray
!is null, "struct gArray is null on constructor");
144 this.gArray
= gArray
;
152 * Creates a new GArray.
154 * TRUE if the array should have an extra element at the end
157 * TRUE if GArray elements should be automatically cleared to 0
158 * when they are allocated.
160 * the size of each element in bytes.
164 public this (int zeroTerminated
, int clear
, uint elementSize
)
166 // GArray* g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size);
167 this(cast(GArray
*)g_array_new(zeroTerminated
, clear
, elementSize
) );
171 * Creates a new GArray with reserved_size elements
172 * preallocated. This avoids frequent reallocation, if you are going to
173 * add many elements to the array. Note however that the size of the
176 * TRUE if the array should have an extra element at the end with all bits cleared.
178 * TRUE if all bits in the array should be cleared to 0 on allocation.
180 * size of each element in the array.
182 * number of elements preallocated.
186 public static ArrayG
sizedNew(int zeroTerminated
, int clear
, uint elementSize
, uint reservedSize
)
188 // GArray* g_array_sized_new (gboolean zero_terminated, gboolean clear_, guint element_size, guint reserved_size);
189 return new ArrayG( g_array_sized_new(zeroTerminated
, clear
, elementSize
, reservedSize
) );
194 * Adds len elements onto the end of the array.
198 * a pointer to the elements to append to the end of the array.
200 * the number of elements to append.
204 public ArrayG
appendVals(void* data
, uint len
)
206 // GArray* g_array_append_vals (GArray *array, gconstpointer data, guint len);
207 return new ArrayG( g_array_append_vals(gArray
, data
, len
) );
212 * Adds len elements onto the start of the array.
213 * This operation is slower than g_array_append_vals() since the existing elements
214 * in the array have to be moved to make space for the new elements.
218 * a pointer to the elements to prepend to the start of the array.
220 * the number of elements to prepend.
224 public ArrayG
prependVals(void* data
, uint len
)
226 // GArray* g_array_prepend_vals (GArray *array, gconstpointer data, guint len);
227 return new ArrayG( g_array_prepend_vals(gArray
, data
, len
) );
232 * Inserts len elements into a GArray at the given index.
236 * the index to place the elements at.
238 * a pointer to the elements to insert.
240 * the number of elements to insert.
244 public ArrayG
insertVals(uint index
, void* data
, uint len
)
246 // GArray* g_array_insert_vals (GArray *array, guint index_, gconstpointer data, guint len);
247 return new ArrayG( g_array_insert_vals(gArray
, index
, data
, len
) );
251 * Removes the element at the given index from a GArray.
252 * The following elements are moved down one place.
256 * the index of the element to remove.
260 public ArrayG
removeIndex(uint index
)
262 // GArray* g_array_remove_index (GArray *array, guint index_);
263 return new ArrayG( g_array_remove_index(gArray
, index
) );
267 * Removes the element at the given index from a GArray.
268 * The last element in the array is used to fill in the space, so this function
269 * does not preserve the order of the GArray. But it is faster than
270 * g_array_remove_index().
274 * the index of the element to remove.
278 public ArrayG
removeIndexFast(uint index
)
280 // GArray* g_array_remove_index_fast (GArray *array, guint index_);
281 return new ArrayG( g_array_remove_index_fast(gArray
, index
) );
285 * Removes the given number of elements starting at the given index from a
286 * GArray. The following elements are moved to close the gap.
290 * the index of the first element to remove.
292 * the number of elements to remove.
297 public ArrayG
removeRange(uint index
, uint length
)
299 // GArray* g_array_remove_range (GArray *array, guint index_, guint length);
300 return new ArrayG( g_array_remove_range(gArray
, index
, length
) );
304 * Sorts a GArray using compare_func which should be a qsort()-style comparison
305 * function (returns less than zero for first arg is less than second arg,
306 * zero for equal, greater zero if first arg is greater than second arg).
307 * If two array elements compare equal, their order in the sorted array is
312 * comparison function.
314 public void sort(GCompareFunc compareFunc
)
316 // void g_array_sort (GArray *array, GCompareFunc compare_func);
317 g_array_sort(gArray
, compareFunc
);
321 * Like g_array_sort(), but the comparison function receives an extra user data
326 * comparison function.
328 * data to pass to compare_func.
330 public void sortWithData(GCompareDataFunc compareFunc
, void* userData
)
332 // void g_array_sort_with_data (GArray *array, GCompareDataFunc compare_func, gpointer user_data);
333 g_array_sort_with_data(gArray
, compareFunc
, userData
);
338 * Sets the size of the array, expanding it if necessary.
339 * If the array was created with clear_ set to TRUE, the new elements are set to 0.
343 * the new size of the GArray.
347 public ArrayG
setSize(uint length
)
349 // GArray* g_array_set_size (GArray *array, guint length);
350 return new ArrayG( g_array_set_size(gArray
, length
) );
354 * Frees the memory allocated for the GArray.
355 * If free_segment is TRUE it frees the memory block holding the elements
356 * as well. Pass FALSE if you want to free the GArray wrapper but preserve
357 * the underlying array for use elsewhere.
359 * If array elements contain dynamically-allocated memory, they should be freed
364 * if TRUE the actual element data is freed as well.
366 * the element data if free_segment is FALSE, otherwise NULL
368 public char[] free(int freeSegment
)
370 // gchar* g_array_free (GArray *array, gboolean free_segment);
371 return Str
.toString(g_array_free(gArray
, freeSegment
) );