I've no idea here...
[gtkD.git] / src / glib / ArrayG.d
blobae0df01468fa364afe4068c766a811338ac3445b
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-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 * local aliases:
51 module glib.ArrayG;
53 private import glib.glibtypes;
55 private import lib.glib;
57 private import glib.ListG;
58 private import glib.Str;
60 /**
61 * Description
62 * Arrays are similar to standard C arrays, except that they grow automatically
63 * as elements are added.
64 * Array elements can be of any size (though all elements of one array are the
65 * same size), and the array can be automatically cleared to '0's and
66 * zero-terminated.
67 * To create a new array use g_array_new().
68 * To add elements to an array, use g_array_append_val(), g_array_append_vals(),
69 * g_array_prepend_val(), and g_array_prepend_vals().
70 * To access an element of an array, use g_array_index().
71 * To set the size of an array, use g_array_set_size().
72 * To free an array, use g_array_free().
73 * Example5.Using a GArray to store gint values
74 * GArray *garray;
75 * gint i;
76 * /+* We create a new array to store gint values.
77 * We don't want it zero-terminated or cleared to 0's. +/
78 * garray = g_array_new (FALSE, FALSE, sizeof (gint));
79 * for (i = 0; i < 10000; i++)
80 * g_array_append_val (garray, i);
81 * for (i = 0; i < 10000; i++)
82 * if (g_array_index (garray, gint, i) != i)
83 * g_print ("ERROR: got %d instead of %d\n",
84 * g_array_index (garray, gint, i), i);
85 * g_array_free (garray, TRUE);
87 public class ArrayG
90 /** the main Gtk struct */
91 protected GArray* gArray;
94 public GArray* getArrayGStruct()
96 return gArray;
100 /** the main Gtk struct as a void* */
101 protected void* getStruct()
103 return cast(void*)gArray;
107 * Sets our main struct and passes it to the parent class
109 public this (GArray* gArray)
111 this.gArray = gArray;
119 * Creates a new GArray.
120 * zero_terminated:
121 * TRUE if the array should have an extra element at the end
122 * which is set to 0.
123 * clear_:
124 * TRUE if GArray elements should be automatically cleared to 0
125 * when they are allocated.
126 * element_size:
127 * the size of each element in bytes.
128 * Returns:
129 * the new GArray.
131 public this (int zeroTerminated, int clear, uint elementSize)
133 // GArray* g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size);
134 this(cast(GArray*)g_array_new(zeroTerminated, clear, elementSize) );
138 * Creates a new GArray with reserved_size elements
139 * preallocated. This avoids frequent reallocation, if you are going to
140 * add many elements to the array. Note however that the size of the
141 * array is still 0.
142 * zero_terminated:
143 * TRUE if the array should have an extra element at the end with all bits cleared.
144 * clear_:
145 * TRUE if all bits in the array should be cleared to 0 on allocation.
146 * element_size:
147 * size of each element in the array.
148 * reserved_size:
149 * number of elements preallocated.
150 * Returns:
151 * the new GArray.
153 public static ArrayG sizedNew(int zeroTerminated, int clear, uint elementSize, uint reservedSize)
155 // GArray* g_array_sized_new (gboolean zero_terminated, gboolean clear_, guint element_size, guint reserved_size);
156 return new ArrayG( g_array_sized_new(zeroTerminated, clear, elementSize, reservedSize) );
161 * Adds len elements onto the end of the array.
162 * array:
163 * a GArray.
164 * data:
165 * a pointer to the elements to append to the end of the array.
166 * len:
167 * the number of elements to append.
168 * Returns:
169 * the GArray.
171 public ArrayG appendVals(void* data, uint len)
173 // GArray* g_array_append_vals (GArray *array, gconstpointer data, guint len);
174 return new ArrayG( g_array_append_vals(gArray, data, len) );
179 * Adds len elements onto the start of the array.
180 * This operation is slower than g_array_append_vals() since the existing elements
181 * in the array have to be moved to make space for the new elements.
182 * array:
183 * a GArray.
184 * data:
185 * a pointer to the elements to prepend to the start of the array.
186 * len:
187 * the number of elements to prepend.
188 * Returns:
189 * the GArray.
191 public ArrayG prependVals(void* data, uint len)
193 // GArray* g_array_prepend_vals (GArray *array, gconstpointer data, guint len);
194 return new ArrayG( g_array_prepend_vals(gArray, data, len) );
199 * Inserts len elements into a GArray at the given index.
200 * array:
201 * a GArray.
202 * index_:
203 * the index to place the elements at.
204 * data:
205 * a pointer to the elements to insert.
206 * len:
207 * the number of elements to insert.
208 * Returns:
209 * the GArray.
211 public ArrayG insertVals(uint index, void* data, uint len)
213 // GArray* g_array_insert_vals (GArray *array, guint index_, gconstpointer data, guint len);
214 return new ArrayG( g_array_insert_vals(gArray, index, data, len) );
218 * Removes the element at the given index from a GArray.
219 * The following elements are moved down one place.
220 * array:
221 * a GArray.
222 * index_:
223 * the index of the element to remove.
224 * Returns:
225 * the GArray.
227 public ArrayG removeIndex(uint index)
229 // GArray* g_array_remove_index (GArray *array, guint index_);
230 return new ArrayG( g_array_remove_index(gArray, index) );
234 * Removes the element at the given index from a GArray.
235 * The last element in the array is used to fill in the space, so this function
236 * does not preserve the order of the GArray. But it is faster than
237 * g_array_remove_index().
238 * array:
239 * a GArray.
240 * index_:
241 * the index of the element to remove.
242 * Returns:
243 * the GArray.
245 public ArrayG removeIndexFast(uint index)
247 // GArray* g_array_remove_index_fast (GArray *array, guint index_);
248 return new ArrayG( g_array_remove_index_fast(gArray, index) );
252 * Removes the given number of elements starting at the given index from a
253 * GArray. The following elements are moved to close the gap.
254 * array:
255 * a GArray.
256 * index_:
257 * the index of the first element to remove.
258 * length:
259 * the number of elements to remove.
260 * Returns:
261 * the GArray.
262 * Since 2.4
264 public ArrayG removeRange(uint index, uint length)
266 // GArray* g_array_remove_range (GArray *array, guint index_, guint length);
267 return new ArrayG( g_array_remove_range(gArray, index, length) );
271 * Sorts a GArray using compare_func which should be a qsort()-style comparison
272 * function (returns less than zero for first arg is less than second arg,
273 * zero for equal, greater zero if first arg is greater than second arg).
274 * If two array elements compare equal, their order in the sorted array is
275 * undefined.
276 * array:
277 * a GArray.
278 * compare_func:
279 * comparison function.
281 public void sort(GCompareFunc compareFunc)
283 // void g_array_sort (GArray *array, GCompareFunc compare_func);
284 g_array_sort(gArray, compareFunc);
288 * Like g_array_sort(), but the comparison function receives an extra user data
289 * argument.
290 * array:
291 * a GArray.
292 * compare_func:
293 * comparison function.
294 * user_data:
295 * data to pass to compare_func.
297 public void sortWithData(GCompareDataFunc compareFunc, void* userData)
299 // void g_array_sort_with_data (GArray *array, GCompareDataFunc compare_func, gpointer user_data);
300 g_array_sort_with_data(gArray, compareFunc, userData);
305 * Sets the size of the array, expanding it if necessary.
306 * If the array was created with clear_ set to TRUE, the new elements are set to 0.
307 * array:
308 * a GArray.
309 * length:
310 * the new size of the GArray.
311 * Returns:
312 * the GArray.
314 public ArrayG setSize(uint length)
316 // GArray* g_array_set_size (GArray *array, guint length);
317 return new ArrayG( g_array_set_size(gArray, length) );
321 * Frees the memory allocated for the GArray.
322 * If free_segment is TRUE it frees the memory block holding the elements
323 * as well. Pass FALSE if you want to free the GArray wrapper but preserve
324 * the underlying array for use elsewhere.
325 * Note
326 * If array elements contain dynamically-allocated memory, they should be freed
327 * first.
328 * array:
329 * a GArray.
330 * free_segment:
331 * if TRUE the actual element data is freed as well.
332 * Returns:
333 * the element data if free_segment is FALSE, otherwise NULL
335 public char[] free(int freeSegment)
337 // gchar* g_array_free (GArray *array, gboolean free_segment);
338 return Str.toString(g_array_free(gArray, freeSegment) );