I've no idea here...
[gtkD.git] / src / glib / PtrArray.d
blobf3f467b71a4de1ddf3e252573bd8c58faa07d2a1
1 /*
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
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 * local aliases:
51 module glib.PtrArray;
53 private import glib.glibtypes;
55 private import lib.glib;
57 private import glib.ListG;
59 /**
60 * Description
61 * Pointer Arrays are similar to Arrays but are used only for storing pointers.
62 * Note
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
76 * GPtrArray *gparray;
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);
87 public class PtrArray
90 /** the main Gtk struct */
91 protected GPtrArray* gPtrArray;
94 public GPtrArray* getPtrArrayStruct()
96 return gPtrArray;
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.
120 * Returns:
121 * the new GPtrArray.
123 public this ()
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
133 * array is still 0.
134 * reserved_size:
135 * number of pointers preallocated.
136 * Returns:
137 * the new GPtrArray.
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.
148 * array:
149 * a GPtrArray.
150 * data:
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
163 * was not found.
164 * array:
165 * a GPtrArray.
166 * data:
167 * the pointer to remove.
168 * Returns:
169 * TRUE if the pointer is removed. FALSE if the pointer is not found
170 * in the array.
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.
181 * array:
182 * a GPtrArray.
183 * index_:
184 * the index of the pointer to remove.
185 * Returns:
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
200 * was not found.
201 * array:
202 * a GPtrArray.
203 * data:
204 * the pointer to remove.
205 * Returns:
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().
219 * array:
220 * a GPtrArray.
221 * index_:
222 * the index of the pointer to remove.
223 * Returns:
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.
235 * array:
236 * a GPtrArray.
237 * index_:
238 * the index of the first pointer to remove.
239 * length:
240 * the number of pointers to remove.
241 * Since 2.4
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
254 * undefined.
255 * Note
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.
258 * array:
259 * a GPtrArray.
260 * compare_func:
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
271 * argument.
272 * Note
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
275 * the array.
276 * array:
277 * a GPtrArray.
278 * compare_func:
279 * comparison function.
280 * user_data:
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.
292 * array:
293 * a GPtrArray.
294 * length:
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.
306 * array:
307 * a GPtrArray.
308 * free_seg:
309 * if TRUE the array of pointers (pdata) is freed.
310 * Returns:
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.
322 * array:
323 * a GPtrArray
324 * func:
325 * the function to call for each array element
326 * user_data:
327 * user data to pass to the function
328 * Since 2.4
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);