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-Pointer-Arrays.html 27 * outPack = glib 28 * outFile = PtrArray 29 * strct = GPtrArray 30 * realStrct= 31 * ctorStrct= 32 * clss = PtrArray 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_ptr_array_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * structWrap: 47 * - GPtrArray* -> PtrArray 48 * module aliases: 49 * local aliases: 50 * overrides: 51 */ 52 53 module glib.PtrArray; 54 55 public import gtkc.glibtypes; 56 57 private import gtkc.glib; 58 private import glib.ConstructionException; 59 60 61 62 63 64 65 /** 66 * Description 67 * Pointer Arrays are similar to Arrays but are used only for storing 68 * pointers. 69 * Note 70 * If you remove elements from the array, elements at the 71 * end of the array are moved into the space previously occupied by the 72 * removed element. This means that you should not rely on the index of 73 * particular elements remaining the same. You should also be careful 74 * when deleting elements while iterating over the array. 75 * To create a pointer array, use g_ptr_array_new(). 76 * To add elements to a pointer array, use g_ptr_array_add(). 77 * To remove elements from a pointer array, use g_ptr_array_remove(), 78 * g_ptr_array_remove_index() or g_ptr_array_remove_index_fast(). 79 * To access an element of a pointer array, use g_ptr_array_index(). 80 * To set the size of a pointer array, use g_ptr_array_set_size(). 81 * To free a pointer array, use g_ptr_array_free(). 82 * $(DDOC_COMMENT example) 83 */ 84 public class PtrArray 85 { 86 87 /** the main Gtk struct */ 88 protected GPtrArray* gPtrArray; 89 90 91 public GPtrArray* getPtrArrayStruct() 92 { 93 return gPtrArray; 94 } 95 96 97 /** the main Gtk struct as a void* */ 98 protected void* getStruct() 99 { 100 return cast(void*)gPtrArray; 101 } 102 103 /** 104 * Sets our main struct and passes it to the parent class 105 */ 106 public this (GPtrArray* gPtrArray) 107 { 108 this.gPtrArray = gPtrArray; 109 } 110 111 /** 112 */ 113 114 /** 115 * Creates a new GPtrArray with a reference count of 1. 116 * Throws: ConstructionException GTK+ fails to create the object. 117 */ 118 public this () 119 { 120 // GPtrArray * g_ptr_array_new (void); 121 auto p = g_ptr_array_new(); 122 if(p is null) 123 { 124 throw new ConstructionException("null returned by g_ptr_array_new()"); 125 } 126 this(cast(GPtrArray*) p); 127 } 128 129 /** 130 * Creates a new GPtrArray with reserved_size pointers preallocated 131 * and a reference count of 1. This avoids frequent reallocation, if 132 * you are going to add many pointers to the array. Note however that 133 * the size of the array is still 0. 134 * Params: 135 * reservedSize = number of pointers preallocated. 136 * Returns: the new GPtrArray. 137 */ 138 public static PtrArray sizedNew(uint reservedSize) 139 { 140 // GPtrArray * g_ptr_array_sized_new (guint reserved_size); 141 auto p = g_ptr_array_sized_new(reservedSize); 142 143 if(p is null) 144 { 145 return null; 146 } 147 148 return new PtrArray(cast(GPtrArray*) p); 149 } 150 151 /** 152 * Creates a new GPtrArray with a reference count of 1 and use element_free_func 153 * for freeing each element when the array is destroyed either via 154 * g_ptr_array_unref(), when g_ptr_array_free() is called with free_segment 155 * set to TRUE or when removing elements. 156 * Since 2.22 157 * Params: 158 * elementFreeFunc = A function to free elements with destroy array or NULL. 159 * Throws: ConstructionException GTK+ fails to create the object. 160 */ 161 public this (GDestroyNotify elementFreeFunc) 162 { 163 // GPtrArray * g_ptr_array_new_with_free_func (GDestroyNotify element_free_func); 164 auto p = g_ptr_array_new_with_free_func(elementFreeFunc); 165 if(p is null) 166 { 167 throw new ConstructionException("null returned by g_ptr_array_new_with_free_func(elementFreeFunc)"); 168 } 169 this(cast(GPtrArray*) p); 170 } 171 172 /** 173 * Sets a function for freeing each element when array is destroyed 174 * either via g_ptr_array_unref(), when g_ptr_array_free() is called 175 * with free_segment set to TRUE or when removing elements. 176 * Since 2.22 177 * Params: 178 * elementFreeFunc = A function to free elements with destroy array or NULL. 179 */ 180 public void setFreeFunc(GDestroyNotify elementFreeFunc) 181 { 182 // void g_ptr_array_set_free_func (GPtrArray *array, GDestroyNotify element_free_func); 183 g_ptr_array_set_free_func(gPtrArray, elementFreeFunc); 184 } 185 186 /** 187 * Atomically increments the reference count of array by one. This 188 * function is MT-safe and may be called from any thread. 189 * Since 2.22 190 * Returns: The passed in GPtrArray. 191 */ 192 public PtrArray doref() 193 { 194 // GPtrArray * g_ptr_array_ref (GPtrArray *array); 195 auto p = g_ptr_array_ref(gPtrArray); 196 197 if(p is null) 198 { 199 return null; 200 } 201 202 return new PtrArray(cast(GPtrArray*) p); 203 } 204 205 /** 206 * Atomically decrements the reference count of array by one. If the 207 * reference count drops to 0, the effect is the same as calling 208 * g_ptr_array_free() with free_segment set to TRUE. This function 209 * is MT-safe and may be called from any thread. 210 * Since 2.22 211 */ 212 public void unref() 213 { 214 // void g_ptr_array_unref (GPtrArray *array); 215 g_ptr_array_unref(gPtrArray); 216 } 217 218 /** 219 * Adds a pointer to the end of the pointer array. The array will grow 220 * in size automatically if necessary. 221 * Params: 222 * data = the pointer to add. 223 */ 224 public void add(void* data) 225 { 226 // void g_ptr_array_add (GPtrArray *array, gpointer data); 227 g_ptr_array_add(gPtrArray, data); 228 } 229 230 /** 231 * Removes the first occurrence of the given pointer from the pointer 232 * array. The following elements are moved down one place. If array 233 * has a non-NULL GDestroyNotify function it is called for the 234 * removed element. 235 * It returns TRUE if the pointer was removed, or FALSE if the 236 * pointer was not found. 237 * Params: 238 * data = the pointer to remove. 239 * Returns: TRUE if the pointer is removed. FALSE if the pointer is not found in the array. 240 */ 241 public int remove(void* data) 242 { 243 // gboolean g_ptr_array_remove (GPtrArray *array, gpointer data); 244 return g_ptr_array_remove(gPtrArray, data); 245 } 246 247 /** 248 * Removes the pointer at the given index from the pointer array. The 249 * following elements are moved down one place. If array has a 250 * non-NULL GDestroyNotify function it is called for the removed 251 * element. 252 * Params: 253 * index = the index of the pointer to remove. 254 * Returns: the pointer which was removed. 255 */ 256 public void* removeIndex(uint index) 257 { 258 // gpointer g_ptr_array_remove_index (GPtrArray *array, guint index_); 259 return g_ptr_array_remove_index(gPtrArray, index); 260 } 261 262 /** 263 * Removes the first occurrence of the given pointer from the pointer 264 * array. The last element in the array is used to fill in the space, 265 * so this function does not preserve the order of the array. But it is 266 * faster than g_ptr_array_remove(). If array has a non-NULL 267 * GDestroyNotify function it is called for the removed element. 268 * It returns TRUE if the pointer was removed, or FALSE if the 269 * pointer was not found. 270 * Params: 271 * data = the pointer to remove. 272 * Returns: TRUE if the pointer was found in the array. 273 */ 274 public int removeFast(void* data) 275 { 276 // gboolean g_ptr_array_remove_fast (GPtrArray *array, gpointer data); 277 return g_ptr_array_remove_fast(gPtrArray, data); 278 } 279 280 /** 281 * Removes the pointer at the given index from the pointer array. The 282 * last element in the array is used to fill in the space, so this 283 * function does not preserve the order of the array. But it is faster 284 * than g_ptr_array_remove_index(). If array has a non-NULL 285 * GDestroyNotify function it is called for the removed element. 286 * Params: 287 * index = the index of the pointer to remove. 288 * Returns: the pointer which was removed. 289 */ 290 public void* removeIndexFast(uint index) 291 { 292 // gpointer g_ptr_array_remove_index_fast (GPtrArray *array, guint index_); 293 return g_ptr_array_remove_index_fast(gPtrArray, index); 294 } 295 296 /** 297 * Removes the given number of pointers starting at the given index 298 * from a GPtrArray. The following elements are moved to close the 299 * gap. If array has a non-NULL GDestroyNotify function it is called 300 * for the removed elements. 301 * Since 2.4 302 * Params: 303 * index = the index of the first pointer to remove. 304 * length = the number of pointers to remove. 305 */ 306 public void removeRange(uint index, uint length) 307 { 308 // void g_ptr_array_remove_range (GPtrArray *array, guint index_, guint length); 309 g_ptr_array_remove_range(gPtrArray, index, length); 310 } 311 312 /** 313 * Sorts the array, using compare_func which should be a qsort()-style 314 * comparison function (returns less than zero for first arg is less 315 * than second arg, zero for equal, greater than zero if irst arg is 316 * greater than second arg). 317 * If two array elements compare equal, their order in the sorted array 318 * is undefined. 319 * Note 320 * The comparison function for g_ptr_array_sort() doesn't 321 * take the pointers from the array as arguments, it takes pointers to 322 * the pointers in the array. 323 * Params: 324 * compareFunc = comparison function. 325 */ 326 public void sort(GCompareFunc compareFunc) 327 { 328 // void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func); 329 g_ptr_array_sort(gPtrArray, compareFunc); 330 } 331 332 /** 333 * Like g_ptr_array_sort(), but the comparison function has an extra 334 * user data argument. 335 * Note 336 * The comparison function for g_ptr_array_sort_with_data() 337 * doesn't take the pointers from the array as arguments, it takes 338 * pointers to the pointers in the array. 339 * Params: 340 * compareFunc = comparison function. 341 * userData = data to pass to compare_func. 342 */ 343 public void sortWithData(GCompareDataFunc compareFunc, void* userData) 344 { 345 // void g_ptr_array_sort_with_data (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data); 346 g_ptr_array_sort_with_data(gPtrArray, compareFunc, userData); 347 } 348 349 /** 350 * Sets the size of the array. When making the array larger, 351 * newly-added elements will be set to NULL. When making it smaller, 352 * if array has a non-NULL GDestroyNotify function then it will be 353 * called for the removed elements. 354 * Params: 355 * length = the new length of the pointer array. 356 */ 357 public void setSize(int length) 358 { 359 // void g_ptr_array_set_size (GPtrArray *array, gint length); 360 g_ptr_array_set_size(gPtrArray, length); 361 } 362 363 /** 364 * Frees the memory allocated for the GPtrArray. If free_seg is TRUE 365 * it frees the memory block holding the elements as well. Pass FALSE 366 * if you want to free the GPtrArray wrapper but preserve the 367 * underlying array for use elsewhere. If the reference count of array 368 * is greater than one, the GPtrArray wrapper is preserved but the 369 * size of array will be set to zero. 370 * Note 371 * If array contents point to dynamically-allocated 372 * memory, they should be freed separately if free_seg is TRUE and no 373 * GDestroyNotify function has been set for array. 374 * Params: 375 * freeSeg = if TRUE the actual pointer array is freed as well. 376 * Returns: the pointer array if free_seg is FALSE, otherwise NULL. The pointer array should be freed using g_free(). 377 */ 378 public void** free(int freeSeg) 379 { 380 // gpointer * g_ptr_array_free (GPtrArray *array, gboolean free_seg); 381 return g_ptr_array_free(gPtrArray, freeSeg); 382 } 383 384 /** 385 * Calls a function for each element of a GPtrArray. 386 * Since 2.4 387 * Params: 388 * func = the function to call for each array element 389 * userData = user data to pass to the function 390 */ 391 public void foreac(GFunc func, void* userData) 392 { 393 // void g_ptr_array_foreach (GPtrArray *array, GFunc func, gpointer user_data); 394 g_ptr_array_foreach(gPtrArray, func, userData); 395 } 396 }