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
47 * - GPtrArray* -> PtrArray
58 import tango
.io
.Stdout
; // use the tango loging?
62 private import gtkc
.glibtypes
;
64 private import gtkc
.glib
;
67 private import glib
.ListG
;
74 * Pointer Arrays are similar to Arrays but are used only for storing pointers.
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
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()
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
)
126 if ( gPtrArray
is null )
131 Stdout("struct gPtrArray is null on constructor").newline
;
135 printf("struct gPtrArray is null on constructor");
142 assert(gPtrArray
!is null, "struct gPtrArray is null on constructor");
144 this.gPtrArray
= gPtrArray
;
152 * Creates a new GPtrArray.
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
168 * number of pointers preallocated.
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.
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
200 * the pointer to remove.
202 * TRUE if the pointer is removed. FALSE if the pointer is not found
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.
217 * the index of the pointer to remove.
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
237 * the pointer to remove.
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().
255 * the index of the pointer to remove.
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.
271 * the index of the first pointer to remove.
273 * the number of pointers to remove.
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
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.
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
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
312 * comparison function.
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.
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.
342 * if TRUE the array of pointers (pdata) is freed.
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.
358 * the function to call for each array element
360 * user data to pass to the function
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
);