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-Singly-Linked-Lists.html 27 * outPack = glib 28 * outFile = ListSG 29 * strct = GSList 30 * realStrct= 31 * ctorStrct= 32 * clss = ListSG 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_slist_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * structWrap: 47 * - GSList* -> ListSG 48 * module aliases: 49 * local aliases: 50 * overrides: 51 */ 52 53 module glib.ListSG; 54 55 public import gtkc.glibtypes; 56 57 private import gtkc.glib; 58 private import glib.ConstructionException; 59 60 61 62 63 /** 64 * The GSList structure and its associated functions provide a 65 * standard singly-linked list data structure. 66 * 67 * Each element in the list contains a piece of data, together with a 68 * pointer which links to the next element in the list. Using this 69 * pointer it is possible to move through the list in one direction 70 * only (unlike the Doubly-Linked Lists which 71 * allow movement in both directions). 72 * 73 * The data contained in each element can be either integer values, by 74 * using one of the Type 75 * Conversion Macros, or simply pointers to any type of data. 76 * 77 * List elements are allocated from the slice allocator, which is more 78 * efficient than allocating elements individually. 79 * 80 * Note that most of the GSList functions expect to be passed a 81 * pointer to the first element in the list. The functions which insert 82 * elements return the new start of the list, which may have changed. 83 * 84 * There is no function to create a GSList. NULL is considered to be 85 * the empty list so you simply set a GSList* to NULL. 86 * 87 * To add elements, use g_slist_append(), g_slist_prepend(), 88 * g_slist_insert() and g_slist_insert_sorted(). 89 * 90 * To remove elements, use g_slist_remove(). 91 * 92 * To find elements in the list use g_slist_last(), g_slist_next(), 93 * g_slist_nth(), g_slist_nth_data(), g_slist_find() and 94 * g_slist_find_custom(). 95 * 96 * To find the index of an element use g_slist_position() and 97 * g_slist_index(). 98 * 99 * To call a function for each element in the list use 100 * g_slist_foreach(). 101 * 102 * To free the entire list, use g_slist_free(). 103 */ 104 public class ListSG 105 { 106 107 /** the main Gtk struct */ 108 protected GSList* gSList; 109 110 111 /** Get the main Gtk struct */ 112 public GSList* getListSGStruct() 113 { 114 return gSList; 115 } 116 117 118 /** the main Gtk struct as a void* */ 119 protected void* getStruct() 120 { 121 return cast(void*)gSList; 122 } 123 124 /** 125 * Sets our main struct and passes it to the parent class 126 */ 127 public this (GSList* gSList) 128 { 129 this.gSList = gSList; 130 } 131 132 /** */ 133 @property void* data() 134 { 135 return gSList.data; 136 } 137 138 /** 139 * get the next element 140 * Returns: the next element, or NULL if there are no more elements. 141 */ 142 @property ListSG next() 143 { 144 if ( gSList.next is null ) 145 { 146 return null; 147 } 148 149 return new ListSG(gSList.next); 150 } 151 152 /** 153 * Turn the list into a D array of the desiered type. 154 * Type T wraps should match the type of the data. 155 */ 156 public T[] toArray(T, TC = typeof(T.tupleof[0]))() 157 { 158 T[] arr = new T[length()]; 159 ListSG list = this; 160 size_t count; 161 162 while(list !is null && count < arr.length) 163 { 164 arr[count] = new T(cast(TC)list.data); 165 list = next(); 166 count++; 167 } 168 169 return arr; 170 } 171 172 /** 173 */ 174 175 /** 176 * Allocates space for one GSList element. It is called by the 177 * g_slist_append(), g_slist_prepend(), g_slist_insert() and 178 * g_slist_insert_sorted() functions and so is rarely used on its own. 179 * Returns: a pointer to the newly-allocated GSList element. 180 */ 181 public static ListSG alloc() 182 { 183 // GSList * g_slist_alloc (void); 184 auto p = g_slist_alloc(); 185 186 if(p is null) 187 { 188 return null; 189 } 190 191 return new ListSG(cast(GSList*) p); 192 } 193 194 /** 195 * Adds a new element on to the end of the list. 196 * Note 197 * The return value is the new start of the list, which may 198 * have changed, so make sure you store the new value. 199 * Note 200 * Note that g_slist_append() has to traverse the entire list 201 * to find the end, which is inefficient when adding multiple 202 * elements. A common idiom to avoid the inefficiency is to prepend 203 * the elements and reverse the list when all elements have been added. 204 * $(DDOC_COMMENT example) 205 * Params: 206 * data = the data for the new element 207 * Returns: the new start of the GSList 208 */ 209 public ListSG append(void* data) 210 { 211 // GSList * g_slist_append (GSList *list, gpointer data); 212 auto p = g_slist_append(gSList, data); 213 214 if(p is null) 215 { 216 return null; 217 } 218 219 return new ListSG(cast(GSList*) p); 220 } 221 222 /** 223 * Adds a new element on to the start of the list. 224 * Note 225 * The return value is the new start of the list, which 226 * may have changed, so make sure you store the new value. 227 * $(DDOC_COMMENT example) 228 * Params: 229 * data = the data for the new element 230 * Returns: the new start of the GSList 231 */ 232 public ListSG prepend(void* data) 233 { 234 // GSList * g_slist_prepend (GSList *list, gpointer data); 235 auto p = g_slist_prepend(gSList, data); 236 237 if(p is null) 238 { 239 return null; 240 } 241 242 return new ListSG(cast(GSList*) p); 243 } 244 245 /** 246 * Inserts a new element into the list at the given position. 247 * Params: 248 * data = the data for the new element 249 * position = the position to insert the element. 250 * If this is negative, or is larger than the number 251 * of elements in the list, the new element is added on 252 * to the end of the list. 253 * Returns: the new start of the GSList 254 */ 255 public ListSG insert(void* data, int position) 256 { 257 // GSList * g_slist_insert (GSList *list, gpointer data, gint position); 258 auto p = g_slist_insert(gSList, data, position); 259 260 if(p is null) 261 { 262 return null; 263 } 264 265 return new ListSG(cast(GSList*) p); 266 } 267 268 /** 269 * Inserts a node before sibling containing data. 270 * Params: 271 * sibling = node to insert data before 272 * data = data to put in the newly-inserted node 273 * Returns: the new head of the list. 274 */ 275 public ListSG insertBefore(ListSG sibling, void* data) 276 { 277 // GSList * g_slist_insert_before (GSList *slist, GSList *sibling, gpointer data); 278 auto p = g_slist_insert_before(gSList, (sibling is null) ? null : sibling.getListSGStruct(), data); 279 280 if(p is null) 281 { 282 return null; 283 } 284 285 return new ListSG(cast(GSList*) p); 286 } 287 288 /** 289 * Inserts a new element into the list, using the given 290 * comparison function to determine its position. 291 * Params: 292 * data = the data for the new element 293 * func = the function to compare elements in the list. 294 * It should return a number > 0 if the first parameter 295 * comes after the second parameter in the sort order. 296 * Returns: the new start of the GSList 297 */ 298 public ListSG insertSorted(void* data, GCompareFunc func) 299 { 300 // GSList * g_slist_insert_sorted (GSList *list, gpointer data, GCompareFunc func); 301 auto p = g_slist_insert_sorted(gSList, data, func); 302 303 if(p is null) 304 { 305 return null; 306 } 307 308 return new ListSG(cast(GSList*) p); 309 } 310 311 /** 312 * Removes an element from a GSList. 313 * If two elements contain the same data, only the first is removed. 314 * If none of the elements contain the data, the GSList is unchanged. 315 * Params: 316 * data = the data of the element to remove 317 * Returns: the new start of the GSList 318 */ 319 public ListSG remove(void* data) 320 { 321 // GSList * g_slist_remove (GSList *list, gconstpointer data); 322 auto p = g_slist_remove(gSList, data); 323 324 if(p is null) 325 { 326 return null; 327 } 328 329 return new ListSG(cast(GSList*) p); 330 } 331 332 /** 333 * Removes an element from a GSList, without 334 * freeing the element. The removed element's next 335 * link is set to NULL, so that it becomes a 336 * self-contained list with one element. 337 * Note 338 * Removing arbitrary nodes from a singly-linked list 339 * requires time that is proportional to the length of the list 340 * (ie. O(n)). If you find yourself using g_slist_remove_link() 341 * frequently, you should consider a different data structure, such 342 * as the doubly-linked GList. 343 * Params: 344 * link = an element in the GSList 345 * Returns: the new start of the GSList, without the element 346 */ 347 public ListSG removeLink(ListSG link) 348 { 349 // GSList * g_slist_remove_link (GSList *list, GSList *link_); 350 auto p = g_slist_remove_link(gSList, (link is null) ? null : link.getListSGStruct()); 351 352 if(p is null) 353 { 354 return null; 355 } 356 357 return new ListSG(cast(GSList*) p); 358 } 359 360 /** 361 * Removes the node link_ from the list and frees it. 362 * Compare this to g_slist_remove_link() which removes the node 363 * without freeing it. 364 * Note 365 * Removing arbitrary nodes from a singly-linked list 366 * requires time that is proportional to the length of the list 367 * (ie. O(n)). If you find yourself using g_slist_delete_link() 368 * frequently, you should consider a different data structure, such 369 * as the doubly-linked GList. 370 * Params: 371 * link = node to delete 372 * Returns: the new head of list 373 */ 374 public ListSG deleteLink(ListSG link) 375 { 376 // GSList * g_slist_delete_link (GSList *list, GSList *link_); 377 auto p = g_slist_delete_link(gSList, (link is null) ? null : link.getListSGStruct()); 378 379 if(p is null) 380 { 381 return null; 382 } 383 384 return new ListSG(cast(GSList*) p); 385 } 386 387 /** 388 * Removes all list nodes with data equal to data. 389 * Returns the new head of the list. Contrast with 390 * g_slist_remove() which removes only the first node 391 * matching the given data. 392 * Params: 393 * data = data to remove 394 * Returns: new head of list 395 */ 396 public ListSG removeAll(void* data) 397 { 398 // GSList * g_slist_remove_all (GSList *list, gconstpointer data); 399 auto p = g_slist_remove_all(gSList, data); 400 401 if(p is null) 402 { 403 return null; 404 } 405 406 return new ListSG(cast(GSList*) p); 407 } 408 409 /** 410 * Frees all of the memory used by a GSList. 411 * The freed elements are returned to the slice allocator. 412 * Note 413 * If list elements contain dynamically-allocated memory, 414 * you should either use g_slist_free_full() or free them manually 415 * first. 416 */ 417 public void free() 418 { 419 // void g_slist_free (GSList *list); 420 g_slist_free(gSList); 421 } 422 423 /** 424 * Convenience method, which frees all the memory used by a GSList, and 425 * calls the specified destroy function on every element's data. 426 * Since 2.28 427 * Params: 428 * freeFunc = the function to be called to free each element's data 429 */ 430 public void freeFull(GDestroyNotify freeFunc) 431 { 432 // void g_slist_free_full (GSList *list, GDestroyNotify free_func); 433 g_slist_free_full(gSList, freeFunc); 434 } 435 436 /** 437 * Frees one GSList element. 438 * It is usually used after g_slist_remove_link(). 439 */ 440 public void free1() 441 { 442 // void g_slist_free_1 (GSList *list); 443 g_slist_free_1(gSList); 444 } 445 446 /** 447 * Gets the number of elements in a GSList. 448 * Note 449 * This function iterates over the whole list to 450 * count its elements. 451 * Returns: the number of elements in the GSList 452 */ 453 public uint length() 454 { 455 // guint g_slist_length (GSList *list); 456 return g_slist_length(gSList); 457 } 458 459 /** 460 * Copies a GSList. 461 * Note 462 * Note that this is a "shallow" copy. If the list elements 463 * consist of pointers to data, the pointers are copied but 464 * the actual data isn't. See g_slist_copy_deep() if you need 465 * to copy the data as well. 466 * Returns: a copy of list 467 */ 468 public ListSG copy() 469 { 470 // GSList * g_slist_copy (GSList *list); 471 auto p = g_slist_copy(gSList); 472 473 if(p is null) 474 { 475 return null; 476 } 477 478 return new ListSG(cast(GSList*) p); 479 } 480 481 /** 482 * Makes a full (deep) copy of a GSList. 483 * In contrast with g_slist_copy(), this function uses func to make a copy of 484 * each list element, in addition to copying the list container itself. 485 * func, as a GCopyFunc, takes two arguments, the data to be copied and a user 486 * pointer. It's safe to pass NULL as user_data, if the copy function takes only 487 * one argument. 488 * Since 2.34 489 * Params: 490 * func = a copy function used to copy every element in the list 491 * userData = user data passed to the copy function func, or NULL 492 * Returns: a full copy of list, use g_slist_free_full to free it 493 */ 494 public ListSG copyDeep(GCopyFunc func, void* userData) 495 { 496 // GSList * g_slist_copy_deep (GSList *list, GCopyFunc func, gpointer user_data); 497 auto p = g_slist_copy_deep(gSList, func, userData); 498 499 if(p is null) 500 { 501 return null; 502 } 503 504 return new ListSG(cast(GSList*) p); 505 } 506 507 /** 508 * Reverses a GSList. 509 * Returns: the start of the reversed GSList 510 */ 511 public ListSG reverse() 512 { 513 // GSList * g_slist_reverse (GSList *list); 514 auto p = g_slist_reverse(gSList); 515 516 if(p is null) 517 { 518 return null; 519 } 520 521 return new ListSG(cast(GSList*) p); 522 } 523 524 /** 525 * Inserts a new element into the list, using the given 526 * comparison function to determine its position. 527 * Since 2.10 528 * Params: 529 * data = the data for the new element 530 * func = the function to compare elements in the list. 531 * It should return a number > 0 if the first parameter 532 * comes after the second parameter in the sort order. 533 * userData = data to pass to comparison function 534 * Returns: the new start of the GSList 535 */ 536 public ListSG insertSortedWithData(void* data, GCompareDataFunc func, void* userData) 537 { 538 // GSList * g_slist_insert_sorted_with_data (GSList *list, gpointer data, GCompareDataFunc func, gpointer user_data); 539 auto p = g_slist_insert_sorted_with_data(gSList, data, func, userData); 540 541 if(p is null) 542 { 543 return null; 544 } 545 546 return new ListSG(cast(GSList*) p); 547 } 548 549 /** 550 * Sorts a GSList using the given comparison function. 551 * Params: 552 * compareFunc = the comparison function used to sort the GSList. 553 * This function is passed the data from 2 elements of the GSList 554 * and should return 0 if they are equal, a negative value if the 555 * first element comes before the second, or a positive value if 556 * the first element comes after the second. 557 * Returns: the start of the sorted GSList 558 */ 559 public ListSG sort(GCompareFunc compareFunc) 560 { 561 // GSList * g_slist_sort (GSList *list, GCompareFunc compare_func); 562 auto p = g_slist_sort(gSList, compareFunc); 563 564 if(p is null) 565 { 566 return null; 567 } 568 569 return new ListSG(cast(GSList*) p); 570 } 571 572 /** 573 * Like g_slist_sort(), but the sort function accepts a user data argument. 574 * Params: 575 * compareFunc = comparison function 576 * userData = data to pass to comparison function 577 * Returns: new head of the list 578 */ 579 public ListSG sortWithData(GCompareDataFunc compareFunc, void* userData) 580 { 581 // GSList * g_slist_sort_with_data (GSList *list, GCompareDataFunc compare_func, gpointer user_data); 582 auto p = g_slist_sort_with_data(gSList, compareFunc, userData); 583 584 if(p is null) 585 { 586 return null; 587 } 588 589 return new ListSG(cast(GSList*) p); 590 } 591 592 /** 593 * Adds the second GSList onto the end of the first GSList. 594 * Note that the elements of the second GSList are not copied. 595 * They are used directly. 596 * Params: 597 * list2 = the GSList to add to the end of the first GSList 598 * Returns: the start of the new GSList 599 */ 600 public ListSG concat(ListSG list2) 601 { 602 // GSList * g_slist_concat (GSList *list1, GSList *list2); 603 auto p = g_slist_concat(gSList, (list2 is null) ? null : list2.getListSGStruct()); 604 605 if(p is null) 606 { 607 return null; 608 } 609 610 return new ListSG(cast(GSList*) p); 611 } 612 613 /** 614 * Calls a function for each element of a GSList. 615 * Params: 616 * func = the function to call with each element's data 617 * userData = user data to pass to the function 618 */ 619 public void foreac(GFunc func, void* userData) 620 { 621 // void g_slist_foreach (GSList *list, GFunc func, gpointer user_data); 622 g_slist_foreach(gSList, func, userData); 623 } 624 625 /** 626 * Gets the last element in a GSList. 627 * Note 628 * This function iterates over the whole list. 629 * Returns: the last element in the GSList, or NULL if the GSList has no elements 630 */ 631 public ListSG last() 632 { 633 // GSList * g_slist_last (GSList *list); 634 auto p = g_slist_last(gSList); 635 636 if(p is null) 637 { 638 return null; 639 } 640 641 return new ListSG(cast(GSList*) p); 642 } 643 644 /** 645 * Gets the element at the given position in a GSList. 646 * Params: 647 * n = the position of the element, counting from 0 648 * Returns: the element, or NULL if the position is off the end of the GSList 649 */ 650 public ListSG nth(uint n) 651 { 652 // GSList * g_slist_nth (GSList *list, guint n); 653 auto p = g_slist_nth(gSList, n); 654 655 if(p is null) 656 { 657 return null; 658 } 659 660 return new ListSG(cast(GSList*) p); 661 } 662 663 /** 664 * Gets the data of the element at the given position. 665 * Params: 666 * n = the position of the element 667 * Returns: the element's data, or NULL if the position is off the end of the GSList 668 */ 669 public void* nthData(uint n) 670 { 671 // gpointer g_slist_nth_data (GSList *list, guint n); 672 return g_slist_nth_data(gSList, n); 673 } 674 675 /** 676 * Finds the element in a GSList which 677 * contains the given data. 678 * Params: 679 * data = the element data to find 680 * Returns: the found GSList element, or NULL if it is not found 681 */ 682 public ListSG find(void* data) 683 { 684 // GSList * g_slist_find (GSList *list, gconstpointer data); 685 auto p = g_slist_find(gSList, data); 686 687 if(p is null) 688 { 689 return null; 690 } 691 692 return new ListSG(cast(GSList*) p); 693 } 694 695 /** 696 * Finds an element in a GSList, using a supplied function to 697 * find the desired element. It iterates over the list, calling 698 * the given function which should return 0 when the desired 699 * element is found. The function takes two gconstpointer arguments, 700 * the GSList element's data as the first argument and the 701 * given user data. 702 * Params: 703 * data = user data passed to the function 704 * func = the function to call for each element. 705 * It should return 0 when the desired element is found 706 * Returns: the found GSList element, or NULL if it is not found 707 */ 708 public ListSG findCustom(void* data, GCompareFunc func) 709 { 710 // GSList * g_slist_find_custom (GSList *list, gconstpointer data, GCompareFunc func); 711 auto p = g_slist_find_custom(gSList, data, func); 712 713 if(p is null) 714 { 715 return null; 716 } 717 718 return new ListSG(cast(GSList*) p); 719 } 720 721 /** 722 * Gets the position of the given element 723 * in the GSList (starting from 0). 724 * Params: 725 * llink = an element in the GSList 726 * Returns: the position of the element in the GSList, or -1 if the element is not found 727 */ 728 public int position(ListSG llink) 729 { 730 // gint g_slist_position (GSList *list, GSList *llink); 731 return g_slist_position(gSList, (llink is null) ? null : llink.getListSGStruct()); 732 } 733 734 /** 735 * Gets the position of the element containing 736 * the given data (starting from 0). 737 * Params: 738 * data = the data to find 739 * Returns: the index of the element containing the data, or -1 if the data is not found 740 */ 741 public int index(void* data) 742 { 743 // gint g_slist_index (GSList *list, gconstpointer data); 744 return g_slist_index(gSList, data); 745 } 746 }