1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = glib-Arrays.html 27 * outPack = glib 28 * outFile = ArrayG 29 * strct = GArray 30 * realStrct= 31 * ctorStrct= 32 * clss = ArrayG 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_array_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * structWrap: 48 * - GArray* -> ArrayG 49 * module aliases: 50 * local aliases: 51 * overrides: 52 */ 53 54 module glib.ArrayG; 55 56 public import gtkc.glibtypes; 57 58 private import gtkc.glib; 59 private import glib.ConstructionException; 60 61 62 private import glib.Str; 63 64 65 66 67 /** 68 * Arrays are similar to standard C arrays, except that they grow 69 * automatically as elements are added. 70 * 71 * Array elements can be of any size (though all elements of one array 72 * are the same size), and the array can be automatically cleared to 73 * '0's and zero-terminated. 74 * 75 * To create a new array use g_array_new(). 76 * 77 * To add elements to an array, use g_array_append_val(), 78 * g_array_append_vals(), g_array_prepend_val(), and 79 * g_array_prepend_vals(). 80 * 81 * To access an element of an array, use g_array_index(). 82 * 83 * To set the size of an array, use g_array_set_size(). 84 * 85 * To free an array, use g_array_free(). 86 * 87 * $(DDOC_COMMENT example) 88 */ 89 public class ArrayG 90 { 91 92 /** the main Gtk struct */ 93 protected GArray* gArray; 94 95 96 public GArray* getArrayGStruct() 97 { 98 return gArray; 99 } 100 101 102 /** the main Gtk struct as a void* */ 103 protected void* getStruct() 104 { 105 return cast(void*)gArray; 106 } 107 108 /** 109 * Sets our main struct and passes it to the parent class 110 */ 111 public this (GArray* gArray) 112 { 113 this.gArray = gArray; 114 } 115 116 /** 117 */ 118 119 /** 120 * Creates a new GArray with a reference count of 1. 121 * Params: 122 * zeroTerminated = TRUE if the array should have an extra element at 123 * the end which is set to 0. 124 * clear = TRUE if GArray elements should be automatically cleared 125 * to 0 when they are allocated. 126 * elementSize = the size of each element in bytes. 127 * Throws: ConstructionException GTK+ fails to create the object. 128 */ 129 public this (int zeroTerminated, int clear, uint elementSize) 130 { 131 // GArray * g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size); 132 auto p = g_array_new(zeroTerminated, clear, elementSize); 133 if(p is null) 134 { 135 throw new ConstructionException("null returned by g_array_new(zeroTerminated, clear, elementSize)"); 136 } 137 this(cast(GArray*) p); 138 } 139 140 /** 141 * Creates a new GArray with reserved_size elements preallocated and 142 * a reference count of 1. This avoids frequent reallocation, if you 143 * are going to add many elements to the array. Note however that the 144 * size of the array is still 0. 145 * Params: 146 * zeroTerminated = TRUE if the array should have an extra element at 147 * the end with all bits cleared. 148 * clear = TRUE if all bits in the array should be cleared to 0 on 149 * allocation. 150 * elementSize = size of each element in the array. 151 * reservedSize = number of elements preallocated. 152 * Returns: the new GArray. 153 */ 154 public static ArrayG sizedNew(int zeroTerminated, int clear, uint elementSize, uint reservedSize) 155 { 156 // GArray * g_array_sized_new (gboolean zero_terminated, gboolean clear_, guint element_size, guint reserved_size); 157 auto p = g_array_sized_new(zeroTerminated, clear, elementSize, reservedSize); 158 159 if(p is null) 160 { 161 return null; 162 } 163 164 return new ArrayG(cast(GArray*) p); 165 } 166 167 /** 168 * Atomically increments the reference count of array by one. This 169 * function is MT-safe and may be called from any thread. 170 * Since 2.22 171 * Returns: The passed in GArray. 172 */ 173 public ArrayG doref() 174 { 175 // GArray * g_array_ref (GArray *array); 176 auto p = g_array_ref(gArray); 177 178 if(p is null) 179 { 180 return null; 181 } 182 183 return new ArrayG(cast(GArray*) p); 184 } 185 186 /** 187 * Atomically decrements the reference count of array by one. If the 188 * reference count drops to 0, all memory allocated by the array is 189 * released. This function is MT-safe and may be called from any 190 * thread. 191 * Since 2.22 192 */ 193 public void unref() 194 { 195 // void g_array_unref (GArray *array); 196 g_array_unref(gArray); 197 } 198 199 /** 200 * Gets the size of the elements in array. 201 * Since 2.22 202 * Returns: Size of each element, in bytes. 203 */ 204 public uint getElementSize() 205 { 206 // guint g_array_get_element_size (GArray *array); 207 return g_array_get_element_size(gArray); 208 } 209 210 /** 211 * Adds len elements onto the end of the array. 212 * Params: 213 * data = a pointer to the elements to append to the end of the array. 214 * len = the number of elements to append. 215 * Returns: the GArray. 216 */ 217 public ArrayG appendVals(void* data, uint len) 218 { 219 // GArray * g_array_append_vals (GArray *array, gconstpointer data, guint len); 220 auto p = g_array_append_vals(gArray, data, len); 221 222 if(p is null) 223 { 224 return null; 225 } 226 227 return new ArrayG(cast(GArray*) p); 228 } 229 230 /** 231 * Adds len elements onto the start of the array. 232 * This operation is slower than g_array_append_vals() since the 233 * existing elements in the array have to be moved to make space for 234 * the new elements. 235 * Params: 236 * data = a pointer to the elements to prepend to the start of the 237 * array. 238 * len = the number of elements to prepend. 239 * Returns: the GArray. 240 */ 241 public ArrayG prependVals(void* data, uint len) 242 { 243 // GArray * g_array_prepend_vals (GArray *array, gconstpointer data, guint len); 244 auto p = g_array_prepend_vals(gArray, data, len); 245 246 if(p is null) 247 { 248 return null; 249 } 250 251 return new ArrayG(cast(GArray*) p); 252 } 253 254 /** 255 * Inserts len elements into a GArray at the given index. 256 * Params: 257 * index = the index to place the elements at. 258 * data = a pointer to the elements to insert. 259 * len = the number of elements to insert. 260 * Returns: the GArray. 261 */ 262 public ArrayG insertVals(uint index, void* data, uint len) 263 { 264 // GArray * g_array_insert_vals (GArray *array, guint index_, gconstpointer data, guint len); 265 auto p = g_array_insert_vals(gArray, index, data, len); 266 267 if(p is null) 268 { 269 return null; 270 } 271 272 return new ArrayG(cast(GArray*) p); 273 } 274 275 /** 276 * Removes the element at the given index from a GArray. The following 277 * elements are moved down one place. 278 * Params: 279 * index = the index of the element to remove. 280 * Returns: the GArray. 281 */ 282 public ArrayG removeIndex(uint index) 283 { 284 // GArray * g_array_remove_index (GArray *array, guint index_); 285 auto p = g_array_remove_index(gArray, index); 286 287 if(p is null) 288 { 289 return null; 290 } 291 292 return new ArrayG(cast(GArray*) p); 293 } 294 295 /** 296 * Removes the element at the given index from a GArray. The last 297 * element in the array is used to fill in the space, so this function 298 * does not preserve the order of the GArray. But it is faster than 299 * g_array_remove_index(). 300 * Params: 301 * index = the index of the element to remove. 302 * Returns: the GArray. 303 */ 304 public ArrayG removeIndexFast(uint index) 305 { 306 // GArray * g_array_remove_index_fast (GArray *array, guint index_); 307 auto p = g_array_remove_index_fast(gArray, index); 308 309 if(p is null) 310 { 311 return null; 312 } 313 314 return new ArrayG(cast(GArray*) p); 315 } 316 317 /** 318 * Removes the given number of elements starting at the given index 319 * from a GArray. The following elements are moved to close the gap. 320 * Since 2.4 321 * Params: 322 * index = the index of the first element to remove. 323 * length = the number of elements to remove. 324 * Returns: the GArray. 325 */ 326 public ArrayG removeRange(uint index, uint length) 327 { 328 // GArray * g_array_remove_range (GArray *array, guint index_, guint length); 329 auto p = g_array_remove_range(gArray, index, length); 330 331 if(p is null) 332 { 333 return null; 334 } 335 336 return new ArrayG(cast(GArray*) p); 337 } 338 339 /** 340 * Sorts a GArray using compare_func which should be a qsort()-style 341 * comparison function (returns less than zero for first arg is less 342 * than second arg, zero for equal, greater zero if first arg is 343 * greater than second arg). 344 * This is guaranteed to be a stable sort since version 2.32. 345 * Params: 346 * compareFunc = comparison function. 347 */ 348 public void sort(GCompareFunc compareFunc) 349 { 350 // void g_array_sort (GArray *array, GCompareFunc compare_func); 351 g_array_sort(gArray, compareFunc); 352 } 353 354 /** 355 * Like g_array_sort(), but the comparison function receives an extra 356 * user data argument. 357 * This is guaranteed to be a stable sort since version 2.32. 358 * There used to be a comment here about making the sort stable by 359 * using the addresses of the elements in the comparison function. 360 * This did not actually work, so any such code should be removed. 361 * Params: 362 * compareFunc = comparison function. 363 * userData = data to pass to compare_func. 364 */ 365 public void sortWithData(GCompareDataFunc compareFunc, void* userData) 366 { 367 // void g_array_sort_with_data (GArray *array, GCompareDataFunc compare_func, gpointer user_data); 368 g_array_sort_with_data(gArray, compareFunc, userData); 369 } 370 371 /** 372 * Sets the size of the array, expanding it if necessary. If the array 373 * was created with clear_ set to TRUE, the new elements are set to 0. 374 * Params: 375 * length = the new size of the GArray. 376 * Returns: the GArray. 377 */ 378 public ArrayG setSize(uint length) 379 { 380 // GArray * g_array_set_size (GArray *array, guint length); 381 auto p = g_array_set_size(gArray, length); 382 383 if(p is null) 384 { 385 return null; 386 } 387 388 return new ArrayG(cast(GArray*) p); 389 } 390 391 /** 392 * Sets a function to clear an element of array. 393 * The clear_func will be called when an element in the array 394 * data segment is removed and when the array is freed and data 395 * segment is deallocated as well. 396 * Note that in contrast with other uses of GDestroyNotify 397 * functions, clear_func is expected to clear the contents of 398 * the array element it is given, but not free the element itself. 399 * Since 2.32 400 * Params: 401 * clearFunc = a function to clear an element of array 402 */ 403 public void setClearFunc(GDestroyNotify clearFunc) 404 { 405 // void g_array_set_clear_func (GArray *array, GDestroyNotify clear_func); 406 g_array_set_clear_func(gArray, clearFunc); 407 } 408 409 /** 410 * Frees the memory allocated for the GArray. If free_segment is 411 * TRUE it frees the memory block holding the elements as well and 412 * also each element if array has a element_free_func set. Pass 413 * FALSE if you want to free the GArray wrapper but preserve the 414 * underlying array for use elsewhere. If the reference count of array 415 * is greater than one, the GArray wrapper is preserved but the size 416 * of array will be set to zero. 417 * Note 418 * If array elements contain dynamically-allocated memory, 419 * they should be freed separately. 420 * Params: 421 * freeSegment = if TRUE the actual element data is freed as well. 422 * Returns: the element data if free_segment is FALSE, otherwise NULL. The element data should be freed using g_free(). 423 */ 424 public string free(int freeSegment) 425 { 426 // gchar * g_array_free (GArray *array, gboolean free_segment); 427 return Str.toString(g_array_free(gArray, freeSegment)); 428 } 429 }