alternative to assert
[gtkD.git] / gtkD / src / glib / ArrayG.d
blobda184fb56729a1b3c4660e5bb2592c530eef3653
1 /*
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
26 * outPack = glib
27 * outFile = ArrayG
28 * strct = GArray
29 * realStrct=
30 * ctorStrct=
31 * clss = ArrayG
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_array_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.ListG
45 * - glib.Str
46 * structWrap:
47 * - GArray* -> ArrayG
48 * module aliases:
49 * local aliases:
52 module glib.ArrayG;
54 version(noAssert)
56 version(Tango)
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;
73 /**
74 * Description
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
79 * zero-terminated.
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
87 * GArray *garray;
88 * gint i;
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);
100 public class ArrayG
103 /** the main Gtk struct */
104 protected GArray* gArray;
107 public GArray* getArrayGStruct()
109 return gArray;
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)
124 version(noAssert)
126 if ( gArray is null )
128 int zero = 0;
129 version(Tango)
131 Stdout("struct gArray is null on constructor").newline;
133 else
135 printf("struct gArray is null on constructor");
137 zero = zero / zero;
140 else
142 assert(gArray !is null, "struct gArray is null on constructor");
144 this.gArray = gArray;
152 * Creates a new GArray.
153 * zero_terminated:
154 * TRUE if the array should have an extra element at the end
155 * which is set to 0.
156 * clear_:
157 * TRUE if GArray elements should be automatically cleared to 0
158 * when they are allocated.
159 * element_size:
160 * the size of each element in bytes.
161 * Returns:
162 * the new GArray.
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
174 * array is still 0.
175 * zero_terminated:
176 * TRUE if the array should have an extra element at the end with all bits cleared.
177 * clear_:
178 * TRUE if all bits in the array should be cleared to 0 on allocation.
179 * element_size:
180 * size of each element in the array.
181 * reserved_size:
182 * number of elements preallocated.
183 * Returns:
184 * the new GArray.
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.
195 * array:
196 * a GArray.
197 * data:
198 * a pointer to the elements to append to the end of the array.
199 * len:
200 * the number of elements to append.
201 * Returns:
202 * the GArray.
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.
215 * array:
216 * a GArray.
217 * data:
218 * a pointer to the elements to prepend to the start of the array.
219 * len:
220 * the number of elements to prepend.
221 * Returns:
222 * the GArray.
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.
233 * array:
234 * a GArray.
235 * index_:
236 * the index to place the elements at.
237 * data:
238 * a pointer to the elements to insert.
239 * len:
240 * the number of elements to insert.
241 * Returns:
242 * the GArray.
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.
253 * array:
254 * a GArray.
255 * index_:
256 * the index of the element to remove.
257 * Returns:
258 * the GArray.
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().
271 * array:
272 * a GArray.
273 * index_:
274 * the index of the element to remove.
275 * Returns:
276 * the GArray.
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.
287 * array:
288 * a GArray.
289 * index_:
290 * the index of the first element to remove.
291 * length:
292 * the number of elements to remove.
293 * Returns:
294 * the GArray.
295 * Since 2.4
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
308 * undefined.
309 * array:
310 * a GArray.
311 * compare_func:
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
322 * argument.
323 * array:
324 * a GArray.
325 * compare_func:
326 * comparison function.
327 * user_data:
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.
340 * array:
341 * a GArray.
342 * length:
343 * the new size of the GArray.
344 * Returns:
345 * 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.
358 * Note
359 * If array elements contain dynamically-allocated memory, they should be freed
360 * first.
361 * array:
362 * a GArray.
363 * free_segment:
364 * if TRUE the actual element data is freed as well.
365 * Returns:
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) );