alternative to assert
[gtkD.git] / gtkD / src / glib / PtrArray.d
blob75f14de94acb05ca80ea251e79c09fddc1997d6b
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-Pointer-Arrays.html
26 * outPack = glib
27 * outFile = PtrArray
28 * strct = GPtrArray
29 * realStrct=
30 * ctorStrct=
31 * clss = PtrArray
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_ptr_array_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.ListG
45 * structWrap:
46 * - GList* -> ListG
47 * - GPtrArray* -> PtrArray
48 * module aliases:
49 * local aliases:
52 module glib.PtrArray;
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;
72 /**
73 * Description
74 * Pointer Arrays are similar to Arrays but are used only for storing pointers.
75 * Note
76 * If you remove elements from the array, elements at the end of the array
77 * are moved into the space previously occupied by the removed element.
78 * This means that you should not rely on the index of particular elements
79 * remaining the same. You should also be careful when deleting elements while
80 * iterating over the array.
81 * To create a pointer array, use g_ptr_array_new().
82 * To add elements to a pointer array, use g_ptr_array_add().
83 * To remove elements from a pointer array, use g_ptr_array_remove(),
84 * g_ptr_array_remove_index() or g_ptr_array_remove_index_fast().
85 * To access an element of a pointer array, use g_ptr_array_index().
86 * To set the size of a pointer array, use g_ptr_array_set_size().
87 * To free a pointer array, use g_ptr_array_free().
88 * Example7.Using a GPtrArray
89 * GPtrArray *gparray;
90 * gchar *string1 = "one", *string2 = "two", *string3 = "three";
91 * gparray = g_ptr_array_new ();
92 * g_ptr_array_add (gparray, (gpointer) string1);
93 * g_ptr_array_add (gparray, (gpointer) string2);
94 * g_ptr_array_add (gparray, (gpointer) string3);
95 * if (g_ptr_array_index (gparray, 0) != (gpointer) string1)
96 * g_print ("ERROR: got %p instead of %p\n",
97 * g_ptr_array_index (gparray, 0), string1);
98 * g_ptr_array_free (gparray, TRUE);
100 public class PtrArray
103 /** the main Gtk struct */
104 protected GPtrArray* gPtrArray;
107 public GPtrArray* getPtrArrayStruct()
109 return gPtrArray;
113 /** the main Gtk struct as a void* */
114 protected void* getStruct()
116 return cast(void*)gPtrArray;
120 * Sets our main struct and passes it to the parent class
122 public this (GPtrArray* gPtrArray)
124 version(noAssert)
126 if ( gPtrArray is null )
128 int zero = 0;
129 version(Tango)
131 Stdout("struct gPtrArray is null on constructor").newline;
133 else
135 printf("struct gPtrArray is null on constructor");
137 zero = zero / zero;
140 else
142 assert(gPtrArray !is null, "struct gPtrArray is null on constructor");
144 this.gPtrArray = gPtrArray;
152 * Creates a new GPtrArray.
153 * Returns:
154 * the new GPtrArray.
156 public this ()
158 // GPtrArray* g_ptr_array_new (void);
159 this(cast(GPtrArray*)g_ptr_array_new() );
163 * Creates a new GPtrArray with reserved_size pointers
164 * preallocated. This avoids frequent reallocation, if you are going to
165 * add many pointers to the array. Note however that the size of the
166 * array is still 0.
167 * reserved_size:
168 * number of pointers preallocated.
169 * Returns:
170 * the new GPtrArray.
172 public static PtrArray sizedNew(uint reservedSize)
174 // GPtrArray* g_ptr_array_sized_new (guint reserved_size);
175 return new PtrArray( g_ptr_array_sized_new(reservedSize) );
179 * Adds a pointer to the end of the pointer array.
180 * The array will grow in size automatically if necessary.
181 * array:
182 * a GPtrArray.
183 * data:
184 * the pointer to add.
186 public void add(void* data)
188 // void g_ptr_array_add (GPtrArray *array, gpointer data);
189 g_ptr_array_add(gPtrArray, data);
193 * Removes the first occurrence of the given pointer from the pointer array.
194 * The following elements are moved down one place.
195 * It returns TRUE if the pointer was removed, or FALSE if the pointer
196 * was not found.
197 * array:
198 * a GPtrArray.
199 * data:
200 * the pointer to remove.
201 * Returns:
202 * TRUE if the pointer is removed. FALSE if the pointer is not found
203 * in the array.
205 public int remove(void* data)
207 // gboolean g_ptr_array_remove (GPtrArray *array, gpointer data);
208 return g_ptr_array_remove(gPtrArray, data);
212 * Removes the pointer at the given index from the pointer array.
213 * The following elements are moved down one place.
214 * array:
215 * a GPtrArray.
216 * index_:
217 * the index of the pointer to remove.
218 * Returns:
219 * the pointer which was removed.
221 public void* removeIndex(uint index)
223 // gpointer g_ptr_array_remove_index (GPtrArray *array, guint index_);
224 return g_ptr_array_remove_index(gPtrArray, index);
228 * Removes the first occurrence of the given pointer from the pointer array.
229 * The last element in the array is used to fill in the space, so this function
230 * does not preserve the order of the array. But it is faster than
231 * g_ptr_array_remove().
232 * It returns TRUE if the pointer was removed, or FALSE if the pointer
233 * was not found.
234 * array:
235 * a GPtrArray.
236 * data:
237 * the pointer to remove.
238 * Returns:
239 * TRUE if the pointer was found in the array.
241 public int removeFast(void* data)
243 // gboolean g_ptr_array_remove_fast (GPtrArray *array, gpointer data);
244 return g_ptr_array_remove_fast(gPtrArray, data);
248 * Removes the pointer at the given index from the pointer array.
249 * The last element in the array is used to fill in the space, so this function
250 * does not preserve the order of the array. But it is faster than
251 * g_ptr_array_remove_index().
252 * array:
253 * a GPtrArray.
254 * index_:
255 * the index of the pointer to remove.
256 * Returns:
257 * the pointer which was removed.
259 public void* removeIndexFast(uint index)
261 // gpointer g_ptr_array_remove_index_fast (GPtrArray *array, guint index_);
262 return g_ptr_array_remove_index_fast(gPtrArray, index);
266 * Removes the given number of pointers starting at the given index from a
267 * GPtrArray. The following elements are moved to close the gap.
268 * array:
269 * a GPtrArray.
270 * index_:
271 * the index of the first pointer to remove.
272 * length:
273 * the number of pointers to remove.
274 * Since 2.4
276 public void removeRange(uint index, uint length)
278 // void g_ptr_array_remove_range (GPtrArray *array, guint index_, guint length);
279 g_ptr_array_remove_range(gPtrArray, index, length);
283 * Sorts the array, using compare_func which should be a qsort()-style comparison
284 * function (returns less than zero for first arg is less than second arg,
285 * zero for equal, greater than zero if irst arg is greater than second arg).
286 * If two array elements compare equal, their order in the sorted array is
287 * undefined.
288 * Note
289 * The comparison function for g_ptr_array_sort() doesn't take the pointers
290 * from the array as arguments, it takes pointers to the pointers in the array.
291 * array:
292 * a GPtrArray.
293 * compare_func:
294 * comparison function.
296 public void sort(GCompareFunc compareFunc)
298 // void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func);
299 g_ptr_array_sort(gPtrArray, compareFunc);
303 * Like g_ptr_array_sort(), but the comparison function has an extra user data
304 * argument.
305 * Note
306 * The comparison function for g_ptr_array_sort_with_data() doesn't take the
307 * pointers from the array as arguments, it takes pointers to the pointers in
308 * the array.
309 * array:
310 * a GPtrArray.
311 * compare_func:
312 * comparison function.
313 * user_data:
314 * data to pass to compare_func.
316 public void sortWithData(GCompareDataFunc compareFunc, void* userData)
318 // void g_ptr_array_sort_with_data (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
319 g_ptr_array_sort_with_data(gPtrArray, compareFunc, userData);
323 * Sets the size of the array, expanding it if necessary.
324 * New elements are set to NULL.
325 * array:
326 * a GPtrArray.
327 * length:
328 * the new length of the pointer array.
330 public void setSize(int length)
332 // void g_ptr_array_set_size (GPtrArray *array, gint length);
333 g_ptr_array_set_size(gPtrArray, length);
338 * Frees all of the memory allocated for the pointer array.
339 * array:
340 * a GPtrArray.
341 * free_seg:
342 * if TRUE the array of pointers (pdata) is freed.
343 * Returns:
344 * NULL if free_seg is TRUE, otherwise the array of
345 * pointers (pdata) is returned.
347 public void** free(int freeSeg)
349 // gpointer* g_ptr_array_free (GPtrArray *array, gboolean free_seg);
350 return g_ptr_array_free(gPtrArray, freeSeg);
354 * Calls a function for each element of a GPtrArray.
355 * array:
356 * a GPtrArray
357 * func:
358 * the function to call for each array element
359 * user_data:
360 * user data to pass to the function
361 * Since 2.4
363 public void foreac(GFunc func, void* userData)
365 // void g_ptr_array_foreach (GPtrArray *array, GFunc func, gpointer user_data);
366 g_ptr_array_foreach(gPtrArray, func, userData);