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-Pointer-Arrays.html
47 * - GPtrArray* -> PtrArray
53 private import glib
.glibtypes
;
55 private import lib
.glib
;
57 private import glib
.ListG
;
61 * Pointer Arrays are similar to Arrays but are used only for storing pointers.
63 * If you remove elements from the array, elements at the end of the array
64 * are moved into the space previously occupied by the removed element.
65 * This means that you should not rely on the index of particular elements
66 * remaining the same. You should also be careful when deleting elements while
67 * iterating over the array.
68 * To create a pointer array, use g_ptr_array_new().
69 * To add elements to a pointer array, use g_ptr_array_add().
70 * To remove elements from a pointer array, use g_ptr_array_remove(),
71 * g_ptr_array_remove_index() or g_ptr_array_remove_index_fast().
72 * To access an element of a pointer array, use g_ptr_array_index().
73 * To set the size of a pointer array, use g_ptr_array_set_size().
74 * To free a pointer array, use g_ptr_array_free().
75 * Example7.Using a GPtrArray
77 * gchar *string1 = "one", *string2 = "two", *string3 = "three";
78 * gparray = g_ptr_array_new ();
79 * g_ptr_array_add (gparray, (gpointer) string1);
80 * g_ptr_array_add (gparray, (gpointer) string2);
81 * g_ptr_array_add (gparray, (gpointer) string3);
82 * if (g_ptr_array_index (gparray, 0) != (gpointer) string1)
83 * g_print ("ERROR: got %p instead of %p\n",
84 * g_ptr_array_index (gparray, 0), string1);
85 * g_ptr_array_free (gparray, TRUE);
90 /** the main Gtk struct */
91 protected GPtrArray
* gPtrArray
;
94 public GPtrArray
* getPtrArrayStruct()
100 /** the main Gtk struct as a void* */
101 protected void* getStruct()
103 return cast(void*)gPtrArray
;
107 * Sets our main struct and passes it to the parent class
109 public this (GPtrArray
* gPtrArray
)
111 this.gPtrArray
= gPtrArray
;
119 * Creates a new GPtrArray.
125 // GPtrArray* g_ptr_array_new (void);
126 this(cast(GPtrArray
*)g_ptr_array_new() );
130 * Creates a new GPtrArray with reserved_size pointers
131 * preallocated. This avoids frequent reallocation, if you are going to
132 * add many pointers to the array. Note however that the size of the
135 * number of pointers preallocated.
139 public static PtrArray
sizedNew(uint reservedSize
)
141 // GPtrArray* g_ptr_array_sized_new (guint reserved_size);
142 return new PtrArray( g_ptr_array_sized_new(reservedSize
) );
146 * Adds a pointer to the end of the pointer array.
147 * The array will grow in size automatically if necessary.
151 * the pointer to add.
153 public void add(void* data
)
155 // void g_ptr_array_add (GPtrArray *array, gpointer data);
156 g_ptr_array_add(gPtrArray
, data
);
160 * Removes the first occurrence of the given pointer from the pointer array.
161 * The following elements are moved down one place.
162 * It returns TRUE if the pointer was removed, or FALSE if the pointer
167 * the pointer to remove.
169 * TRUE if the pointer is removed. FALSE if the pointer is not found
172 public int remove(void* data
)
174 // gboolean g_ptr_array_remove (GPtrArray *array, gpointer data);
175 return g_ptr_array_remove(gPtrArray
, data
);
179 * Removes the pointer at the given index from the pointer array.
180 * The following elements are moved down one place.
184 * the index of the pointer to remove.
186 * the pointer which was removed.
188 public void* removeIndex(uint index
)
190 // gpointer g_ptr_array_remove_index (GPtrArray *array, guint index_);
191 return g_ptr_array_remove_index(gPtrArray
, index
);
195 * Removes the first occurrence of the given pointer from the pointer array.
196 * The last element in the array is used to fill in the space, so this function
197 * does not preserve the order of the array. But it is faster than
198 * g_ptr_array_remove().
199 * It returns TRUE if the pointer was removed, or FALSE if the pointer
204 * the pointer to remove.
206 * TRUE if the pointer was found in the array.
208 public int removeFast(void* data
)
210 // gboolean g_ptr_array_remove_fast (GPtrArray *array, gpointer data);
211 return g_ptr_array_remove_fast(gPtrArray
, data
);
215 * Removes the pointer at the given index from the pointer array.
216 * The last element in the array is used to fill in the space, so this function
217 * does not preserve the order of the array. But it is faster than
218 * g_ptr_array_remove_index().
222 * the index of the pointer to remove.
224 * the pointer which was removed.
226 public void* removeIndexFast(uint index
)
228 // gpointer g_ptr_array_remove_index_fast (GPtrArray *array, guint index_);
229 return g_ptr_array_remove_index_fast(gPtrArray
, index
);
233 * Removes the given number of pointers starting at the given index from a
234 * GPtrArray. The following elements are moved to close the gap.
238 * the index of the first pointer to remove.
240 * the number of pointers to remove.
243 public void removeRange(uint index
, uint length
)
245 // void g_ptr_array_remove_range (GPtrArray *array, guint index_, guint length);
246 g_ptr_array_remove_range(gPtrArray
, index
, length
);
250 * Sorts the array, using compare_func which should be a qsort()-style comparison
251 * function (returns less than zero for first arg is less than second arg,
252 * zero for equal, greater than zero if irst arg is greater than second arg).
253 * If two array elements compare equal, their order in the sorted array is
256 * The comparison function for g_ptr_array_sort() doesn't take the pointers
257 * from the array as arguments, it takes pointers to the pointers in the array.
261 * comparison function.
263 public void sort(GCompareFunc compareFunc
)
265 // void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func);
266 g_ptr_array_sort(gPtrArray
, compareFunc
);
270 * Like g_ptr_array_sort(), but the comparison function has an extra user data
273 * The comparison function for g_ptr_array_sort_with_data() doesn't take the
274 * pointers from the array as arguments, it takes pointers to the pointers in
279 * comparison function.
281 * data to pass to compare_func.
283 public void sortWithData(GCompareDataFunc compareFunc
, void* userData
)
285 // void g_ptr_array_sort_with_data (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
286 g_ptr_array_sort_with_data(gPtrArray
, compareFunc
, userData
);
290 * Sets the size of the array, expanding it if necessary.
291 * New elements are set to NULL.
295 * the new length of the pointer array.
297 public void setSize(int length
)
299 // void g_ptr_array_set_size (GPtrArray *array, gint length);
300 g_ptr_array_set_size(gPtrArray
, length
);
305 * Frees all of the memory allocated for the pointer array.
309 * if TRUE the array of pointers (pdata) is freed.
311 * NULL if free_seg is TRUE, otherwise the array of
312 * pointers (pdata) is returned.
314 public void** free(int freeSeg
)
316 // gpointer* g_ptr_array_free (GPtrArray *array, gboolean free_seg);
317 return g_ptr_array_free(gPtrArray
, freeSeg
);
321 * Calls a function for each element of a GPtrArray.
325 * the function to call for each array element
327 * user data to pass to the function
330 public void foreac(GFunc func
, void* userData
)
332 // void g_ptr_array_foreach (GPtrArray *array, GFunc func, gpointer user_data);
333 g_ptr_array_foreach(gPtrArray
, func
, userData
);