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 module glib.Sequence; 26 27 private import glib.ConstructionException; 28 private import glib.SequenceIter; 29 private import glib.c.functions; 30 public import glib.c.types; 31 public import gtkc.glibtypes; 32 private import gtkd.Loader; 33 34 35 /** 36 * The #GSequence struct is an opaque data type representing a 37 * [sequence][glib-Sequences] data type. 38 */ 39 public class Sequence 40 { 41 /** the main Gtk struct */ 42 protected GSequence* gSequence; 43 protected bool ownedRef; 44 45 /** Get the main Gtk struct */ 46 public GSequence* getSequenceStruct(bool transferOwnership = false) 47 { 48 if (transferOwnership) 49 ownedRef = false; 50 return gSequence; 51 } 52 53 /** the main Gtk struct as a void* */ 54 protected void* getStruct() 55 { 56 return cast(void*)gSequence; 57 } 58 59 /** 60 * Sets our main struct and passes it to the parent class. 61 */ 62 public this (GSequence* gSequence, bool ownedRef = false) 63 { 64 this.gSequence = gSequence; 65 this.ownedRef = ownedRef; 66 } 67 68 ~this () 69 { 70 if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef ) 71 g_sequence_free(gSequence); 72 } 73 74 75 /** 76 * Adds a new item to the end of @seq. 77 * 78 * Params: 79 * data = the data for the new item 80 * 81 * Returns: an iterator pointing to the new item 82 * 83 * Since: 2.14 84 */ 85 public SequenceIter append(void* data) 86 { 87 auto p = g_sequence_append(gSequence, data); 88 89 if(p is null) 90 { 91 return null; 92 } 93 94 return new SequenceIter(cast(GSequenceIter*) p); 95 } 96 97 alias foreac = foreach_; 98 /** 99 * Calls @func for each item in the sequence passing @user_data 100 * to the function. @func must not modify the sequence itself. 101 * 102 * Params: 103 * func = the function to call for each item in @seq 104 * userData = user data passed to @func 105 * 106 * Since: 2.14 107 */ 108 public void foreach_(GFunc func, void* userData) 109 { 110 g_sequence_foreach(gSequence, func, userData); 111 } 112 113 /** 114 * Frees the memory allocated for @seq. If @seq has a data destroy 115 * function associated with it, that function is called on all items 116 * in @seq. 117 * 118 * Since: 2.14 119 */ 120 public void free() 121 { 122 g_sequence_free(gSequence); 123 ownedRef = false; 124 } 125 126 /** 127 * Returns the begin iterator for @seq. 128 * 129 * Returns: the begin iterator for @seq. 130 * 131 * Since: 2.14 132 */ 133 public SequenceIter getBeginIter() 134 { 135 auto p = g_sequence_get_begin_iter(gSequence); 136 137 if(p is null) 138 { 139 return null; 140 } 141 142 return new SequenceIter(cast(GSequenceIter*) p); 143 } 144 145 /** 146 * Returns the end iterator for @seg 147 * 148 * Returns: the end iterator for @seq 149 * 150 * Since: 2.14 151 */ 152 public SequenceIter getEndIter() 153 { 154 auto p = g_sequence_get_end_iter(gSequence); 155 156 if(p is null) 157 { 158 return null; 159 } 160 161 return new SequenceIter(cast(GSequenceIter*) p); 162 } 163 164 /** 165 * Returns the iterator at position @pos. If @pos is negative or larger 166 * than the number of items in @seq, the end iterator is returned. 167 * 168 * Params: 169 * pos = a position in @seq, or -1 for the end 170 * 171 * Returns: The #GSequenceIter at position @pos 172 * 173 * Since: 2.14 174 */ 175 public SequenceIter getIterAtPos(int pos) 176 { 177 auto p = g_sequence_get_iter_at_pos(gSequence, pos); 178 179 if(p is null) 180 { 181 return null; 182 } 183 184 return new SequenceIter(cast(GSequenceIter*) p); 185 } 186 187 /** 188 * Returns the length of @seq. Note that this method is O(h) where `h' is the 189 * height of the tree. It is thus more efficient to use g_sequence_is_empty() 190 * when comparing the length to zero. 191 * 192 * Returns: the length of @seq 193 * 194 * Since: 2.14 195 */ 196 public int getLength() 197 { 198 return g_sequence_get_length(gSequence); 199 } 200 201 /** 202 * Inserts @data into @sequence using @func to determine the new 203 * position. The sequence must already be sorted according to @cmp_func; 204 * otherwise the new position of @data is undefined. 205 * 206 * @cmp_func is called with two items of the @seq and @user_data. 207 * It should return 0 if the items are equal, a negative value 208 * if the first item comes before the second, and a positive value 209 * if the second item comes before the first. 210 * 211 * Note that when adding a large amount of data to a #GSequence, 212 * it is more efficient to do unsorted insertions and then call 213 * g_sequence_sort() or g_sequence_sort_iter(). 214 * 215 * Params: 216 * data = the data to insert 217 * cmpFunc = the function used to compare items in the sequence 218 * cmpData = user data passed to @cmp_func. 219 * 220 * Returns: a #GSequenceIter pointing to the new item. 221 * 222 * Since: 2.14 223 */ 224 public SequenceIter insertSorted(void* data, GCompareDataFunc cmpFunc, void* cmpData) 225 { 226 auto p = g_sequence_insert_sorted(gSequence, data, cmpFunc, cmpData); 227 228 if(p is null) 229 { 230 return null; 231 } 232 233 return new SequenceIter(cast(GSequenceIter*) p); 234 } 235 236 /** 237 * Like g_sequence_insert_sorted(), but uses 238 * a #GSequenceIterCompareFunc instead of a #GCompareDataFunc as 239 * the compare function. 240 * 241 * @iter_cmp is called with two iterators pointing into @seq. 242 * It should return 0 if the iterators are equal, a negative 243 * value if the first iterator comes before the second, and a 244 * positive value if the second iterator comes before the first. 245 * 246 * It is called with two iterators pointing into @seq. It should 247 * return 0 if the iterators are equal, a negative value if the 248 * first iterator comes before the second, and a positive value 249 * if the second iterator comes before the first. 250 * 251 * Note that when adding a large amount of data to a #GSequence, 252 * it is more efficient to do unsorted insertions and then call 253 * g_sequence_sort() or g_sequence_sort_iter(). 254 * 255 * Params: 256 * data = data for the new item 257 * iterCmp = the function used to compare iterators in the sequence 258 * cmpData = user data passed to @cmp_func 259 * 260 * Returns: a #GSequenceIter pointing to the new item 261 * 262 * Since: 2.14 263 */ 264 public SequenceIter insertSortedIter(void* data, GSequenceIterCompareFunc iterCmp, void* cmpData) 265 { 266 auto p = g_sequence_insert_sorted_iter(gSequence, data, iterCmp, cmpData); 267 268 if(p is null) 269 { 270 return null; 271 } 272 273 return new SequenceIter(cast(GSequenceIter*) p); 274 } 275 276 /** 277 * Returns %TRUE if the sequence contains zero items. 278 * 279 * This function is functionally identical to checking the result of 280 * g_sequence_get_length() being equal to zero. However this function is 281 * implemented in O(1) running time. 282 * 283 * Returns: %TRUE if the sequence is empty, otherwise %FALSE. 284 * 285 * Since: 2.48 286 */ 287 public bool isEmpty() 288 { 289 return g_sequence_is_empty(gSequence) != 0; 290 } 291 292 /** 293 * Returns an iterator pointing to the position of the first item found 294 * equal to @data according to @cmp_func and @cmp_data. If more than one 295 * item is equal, it is not guaranteed that it is the first which is 296 * returned. In that case, you can use g_sequence_iter_next() and 297 * g_sequence_iter_prev() to get others. 298 * 299 * @cmp_func is called with two items of the @seq and @user_data. 300 * It should return 0 if the items are equal, a negative value if 301 * the first item comes before the second, and a positive value if 302 * the second item comes before the first. 303 * 304 * This function will fail if the data contained in the sequence is 305 * unsorted. 306 * 307 * Params: 308 * data = data to lookup 309 * cmpFunc = the function used to compare items in the sequence 310 * cmpData = user data passed to @cmp_func 311 * 312 * Returns: an #GSequenceIter pointing to the position of the 313 * first item found equal to @data according to @cmp_func and 314 * @cmp_data, or %NULL if no such item exists 315 * 316 * Since: 2.28 317 */ 318 public SequenceIter lookup(void* data, GCompareDataFunc cmpFunc, void* cmpData) 319 { 320 auto p = g_sequence_lookup(gSequence, data, cmpFunc, cmpData); 321 322 if(p is null) 323 { 324 return null; 325 } 326 327 return new SequenceIter(cast(GSequenceIter*) p); 328 } 329 330 /** 331 * Like g_sequence_lookup(), but uses a #GSequenceIterCompareFunc 332 * instead of a #GCompareDataFunc as the compare function. 333 * 334 * @iter_cmp is called with two iterators pointing into @seq. 335 * It should return 0 if the iterators are equal, a negative value 336 * if the first iterator comes before the second, and a positive 337 * value if the second iterator comes before the first. 338 * 339 * This function will fail if the data contained in the sequence is 340 * unsorted. 341 * 342 * Params: 343 * data = data to lookup 344 * iterCmp = the function used to compare iterators in the sequence 345 * cmpData = user data passed to @iter_cmp 346 * 347 * Returns: an #GSequenceIter pointing to the position of 348 * the first item found equal to @data according to @cmp_func 349 * and @cmp_data, or %NULL if no such item exists 350 * 351 * Since: 2.28 352 */ 353 public SequenceIter lookupIter(void* data, GSequenceIterCompareFunc iterCmp, void* cmpData) 354 { 355 auto p = g_sequence_lookup_iter(gSequence, data, iterCmp, cmpData); 356 357 if(p is null) 358 { 359 return null; 360 } 361 362 return new SequenceIter(cast(GSequenceIter*) p); 363 } 364 365 /** 366 * Adds a new item to the front of @seq 367 * 368 * Params: 369 * data = the data for the new item 370 * 371 * Returns: an iterator pointing to the new item 372 * 373 * Since: 2.14 374 */ 375 public SequenceIter prepend(void* data) 376 { 377 auto p = g_sequence_prepend(gSequence, data); 378 379 if(p is null) 380 { 381 return null; 382 } 383 384 return new SequenceIter(cast(GSequenceIter*) p); 385 } 386 387 /** 388 * Returns an iterator pointing to the position where @data would 389 * be inserted according to @cmp_func and @cmp_data. 390 * 391 * @cmp_func is called with two items of the @seq and @user_data. 392 * It should return 0 if the items are equal, a negative value if 393 * the first item comes before the second, and a positive value if 394 * the second item comes before the first. 395 * 396 * If you are simply searching for an existing element of the sequence, 397 * consider using g_sequence_lookup(). 398 * 399 * This function will fail if the data contained in the sequence is 400 * unsorted. 401 * 402 * Params: 403 * data = data for the new item 404 * cmpFunc = the function used to compare items in the sequence 405 * cmpData = user data passed to @cmp_func 406 * 407 * Returns: an #GSequenceIter pointing to the position where @data 408 * would have been inserted according to @cmp_func and @cmp_data 409 * 410 * Since: 2.14 411 */ 412 public SequenceIter search(void* data, GCompareDataFunc cmpFunc, void* cmpData) 413 { 414 auto p = g_sequence_search(gSequence, data, cmpFunc, cmpData); 415 416 if(p is null) 417 { 418 return null; 419 } 420 421 return new SequenceIter(cast(GSequenceIter*) p); 422 } 423 424 /** 425 * Like g_sequence_search(), but uses a #GSequenceIterCompareFunc 426 * instead of a #GCompareDataFunc as the compare function. 427 * 428 * @iter_cmp is called with two iterators pointing into @seq. 429 * It should return 0 if the iterators are equal, a negative value 430 * if the first iterator comes before the second, and a positive 431 * value if the second iterator comes before the first. 432 * 433 * If you are simply searching for an existing element of the sequence, 434 * consider using g_sequence_lookup_iter(). 435 * 436 * This function will fail if the data contained in the sequence is 437 * unsorted. 438 * 439 * Params: 440 * data = data for the new item 441 * iterCmp = the function used to compare iterators in the sequence 442 * cmpData = user data passed to @iter_cmp 443 * 444 * Returns: a #GSequenceIter pointing to the position in @seq 445 * where @data would have been inserted according to @iter_cmp 446 * and @cmp_data 447 * 448 * Since: 2.14 449 */ 450 public SequenceIter searchIter(void* data, GSequenceIterCompareFunc iterCmp, void* cmpData) 451 { 452 auto p = g_sequence_search_iter(gSequence, data, iterCmp, cmpData); 453 454 if(p is null) 455 { 456 return null; 457 } 458 459 return new SequenceIter(cast(GSequenceIter*) p); 460 } 461 462 /** 463 * Sorts @seq using @cmp_func. 464 * 465 * @cmp_func is passed two items of @seq and should 466 * return 0 if they are equal, a negative value if the 467 * first comes before the second, and a positive value 468 * if the second comes before the first. 469 * 470 * Params: 471 * cmpFunc = the function used to sort the sequence 472 * cmpData = user data passed to @cmp_func 473 * 474 * Since: 2.14 475 */ 476 public void sort(GCompareDataFunc cmpFunc, void* cmpData) 477 { 478 g_sequence_sort(gSequence, cmpFunc, cmpData); 479 } 480 481 /** 482 * Like g_sequence_sort(), but uses a #GSequenceIterCompareFunc instead 483 * of a GCompareDataFunc as the compare function 484 * 485 * @cmp_func is called with two iterators pointing into @seq. It should 486 * return 0 if the iterators are equal, a negative value if the first 487 * iterator comes before the second, and a positive value if the second 488 * iterator comes before the first. 489 * 490 * Params: 491 * cmpFunc = the function used to compare iterators in the sequence 492 * cmpData = user data passed to @cmp_func 493 * 494 * Since: 2.14 495 */ 496 public void sortIter(GSequenceIterCompareFunc cmpFunc, void* cmpData) 497 { 498 g_sequence_sort_iter(gSequence, cmpFunc, cmpData); 499 } 500 501 /** 502 * Calls @func for each item in the range (@begin, @end) passing 503 * @user_data to the function. @func must not modify the sequence 504 * itself. 505 * 506 * Params: 507 * begin = a #GSequenceIter 508 * end = a #GSequenceIter 509 * func = a #GFunc 510 * userData = user data passed to @func 511 * 512 * Since: 2.14 513 */ 514 public static void foreachRange(SequenceIter begin, SequenceIter end, GFunc func, void* userData) 515 { 516 g_sequence_foreach_range((begin is null) ? null : begin.getSequenceIterStruct(), (end is null) ? null : end.getSequenceIterStruct(), func, userData); 517 } 518 519 /** 520 * Returns the data that @iter points to. 521 * 522 * Params: 523 * iter = a #GSequenceIter 524 * 525 * Returns: the data that @iter points to 526 * 527 * Since: 2.14 528 */ 529 public static void* get(SequenceIter iter) 530 { 531 return g_sequence_get((iter is null) ? null : iter.getSequenceIterStruct()); 532 } 533 534 /** 535 * Inserts a new item just before the item pointed to by @iter. 536 * 537 * Params: 538 * iter = a #GSequenceIter 539 * data = the data for the new item 540 * 541 * Returns: an iterator pointing to the new item 542 * 543 * Since: 2.14 544 */ 545 public static SequenceIter insertBefore(SequenceIter iter, void* data) 546 { 547 auto p = g_sequence_insert_before((iter is null) ? null : iter.getSequenceIterStruct(), data); 548 549 if(p is null) 550 { 551 return null; 552 } 553 554 return new SequenceIter(cast(GSequenceIter*) p); 555 } 556 557 /** 558 * Moves the item pointed to by @src to the position indicated by @dest. 559 * After calling this function @dest will point to the position immediately 560 * after @src. It is allowed for @src and @dest to point into different 561 * sequences. 562 * 563 * Params: 564 * src = a #GSequenceIter pointing to the item to move 565 * dest = a #GSequenceIter pointing to the position to which 566 * the item is moved 567 * 568 * Since: 2.14 569 */ 570 public static void move(SequenceIter src, SequenceIter dest) 571 { 572 g_sequence_move((src is null) ? null : src.getSequenceIterStruct(), (dest is null) ? null : dest.getSequenceIterStruct()); 573 } 574 575 /** 576 * Inserts the (@begin, @end) range at the destination pointed to by ptr. 577 * The @begin and @end iters must point into the same sequence. It is 578 * allowed for @dest to point to a different sequence than the one pointed 579 * into by @begin and @end. 580 * 581 * If @dest is NULL, the range indicated by @begin and @end is 582 * removed from the sequence. If @dest iter points to a place within 583 * the (@begin, @end) range, the range does not move. 584 * 585 * Params: 586 * dest = a #GSequenceIter 587 * begin = a #GSequenceIter 588 * end = a #GSequenceIter 589 * 590 * Since: 2.14 591 */ 592 public static void moveRange(SequenceIter dest, SequenceIter begin, SequenceIter end) 593 { 594 g_sequence_move_range((dest is null) ? null : dest.getSequenceIterStruct(), (begin is null) ? null : begin.getSequenceIterStruct(), (end is null) ? null : end.getSequenceIterStruct()); 595 } 596 597 /** 598 * Creates a new GSequence. The @data_destroy function, if non-%NULL will 599 * be called on all items when the sequence is destroyed and on items that 600 * are removed from the sequence. 601 * 602 * Params: 603 * dataDestroy = a #GDestroyNotify function, or %NULL 604 * 605 * Returns: a new #GSequence 606 * 607 * Since: 2.14 608 * 609 * Throws: ConstructionException GTK+ fails to create the object. 610 */ 611 public this(GDestroyNotify dataDestroy) 612 { 613 auto p = g_sequence_new(dataDestroy); 614 615 if(p is null) 616 { 617 throw new ConstructionException("null returned by new"); 618 } 619 620 this(cast(GSequence*) p); 621 } 622 623 /** 624 * Finds an iterator somewhere in the range (@begin, @end). This 625 * iterator will be close to the middle of the range, but is not 626 * guaranteed to be exactly in the middle. 627 * 628 * The @begin and @end iterators must both point to the same sequence 629 * and @begin must come before or be equal to @end in the sequence. 630 * 631 * Params: 632 * begin = a #GSequenceIter 633 * end = a #GSequenceIter 634 * 635 * Returns: a #GSequenceIter pointing somewhere in the 636 * (@begin, @end) range 637 * 638 * Since: 2.14 639 */ 640 public static SequenceIter rangeGetMidpoint(SequenceIter begin, SequenceIter end) 641 { 642 auto p = g_sequence_range_get_midpoint((begin is null) ? null : begin.getSequenceIterStruct(), (end is null) ? null : end.getSequenceIterStruct()); 643 644 if(p is null) 645 { 646 return null; 647 } 648 649 return new SequenceIter(cast(GSequenceIter*) p); 650 } 651 652 /** 653 * Removes the item pointed to by @iter. It is an error to pass the 654 * end iterator to this function. 655 * 656 * If the sequence has a data destroy function associated with it, this 657 * function is called on the data for the removed item. 658 * 659 * Params: 660 * iter = a #GSequenceIter 661 * 662 * Since: 2.14 663 */ 664 public static void remove(SequenceIter iter) 665 { 666 g_sequence_remove((iter is null) ? null : iter.getSequenceIterStruct()); 667 } 668 669 /** 670 * Removes all items in the (@begin, @end) range. 671 * 672 * If the sequence has a data destroy function associated with it, this 673 * function is called on the data for the removed items. 674 * 675 * Params: 676 * begin = a #GSequenceIter 677 * end = a #GSequenceIter 678 * 679 * Since: 2.14 680 */ 681 public static void removeRange(SequenceIter begin, SequenceIter end) 682 { 683 g_sequence_remove_range((begin is null) ? null : begin.getSequenceIterStruct(), (end is null) ? null : end.getSequenceIterStruct()); 684 } 685 686 /** 687 * Changes the data for the item pointed to by @iter to be @data. If 688 * the sequence has a data destroy function associated with it, that 689 * function is called on the existing data that @iter pointed to. 690 * 691 * Params: 692 * iter = a #GSequenceIter 693 * data = new data for the item 694 * 695 * Since: 2.14 696 */ 697 public static void set(SequenceIter iter, void* data) 698 { 699 g_sequence_set((iter is null) ? null : iter.getSequenceIterStruct(), data); 700 } 701 702 /** 703 * Moves the data pointed to a new position as indicated by @cmp_func. This 704 * function should be called for items in a sequence already sorted according 705 * to @cmp_func whenever some aspect of an item changes so that @cmp_func 706 * may return different values for that item. 707 * 708 * @cmp_func is called with two items of the @seq and @user_data. 709 * It should return 0 if the items are equal, a negative value if 710 * the first item comes before the second, and a positive value if 711 * the second item comes before the first. 712 * 713 * Params: 714 * iter = A #GSequenceIter 715 * cmpFunc = the function used to compare items in the sequence 716 * cmpData = user data passed to @cmp_func. 717 * 718 * Since: 2.14 719 */ 720 public static void sortChanged(SequenceIter iter, GCompareDataFunc cmpFunc, void* cmpData) 721 { 722 g_sequence_sort_changed((iter is null) ? null : iter.getSequenceIterStruct(), cmpFunc, cmpData); 723 } 724 725 /** 726 * Like g_sequence_sort_changed(), but uses 727 * a #GSequenceIterCompareFunc instead of a #GCompareDataFunc as 728 * the compare function. 729 * 730 * @iter_cmp is called with two iterators pointing into @seq. It should 731 * return 0 if the iterators are equal, a negative value if the first 732 * iterator comes before the second, and a positive value if the second 733 * iterator comes before the first. 734 * 735 * Params: 736 * iter = a #GSequenceIter 737 * iterCmp = the function used to compare iterators in the sequence 738 * cmpData = user data passed to @cmp_func 739 * 740 * Since: 2.14 741 */ 742 public static void sortChangedIter(SequenceIter iter, GSequenceIterCompareFunc iterCmp, void* cmpData) 743 { 744 g_sequence_sort_changed_iter((iter is null) ? null : iter.getSequenceIterStruct(), iterCmp, cmpData); 745 } 746 747 /** 748 * Swaps the items pointed to by @a and @b. It is allowed for @a and @b 749 * to point into difference sequences. 750 * 751 * Params: 752 * a = a #GSequenceIter 753 * b = a #GSequenceIter 754 * 755 * Since: 2.14 756 */ 757 public static void swap(SequenceIter a, SequenceIter b) 758 { 759 g_sequence_swap((a is null) ? null : a.getSequenceIterStruct(), (b is null) ? null : b.getSequenceIterStruct()); 760 } 761 }