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 @seq using @cmp_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 @cmp_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 * Note that when adding a large amount of data to a #GSequence, 247 * it is more efficient to do unsorted insertions and then call 248 * g_sequence_sort() or g_sequence_sort_iter(). 249 * 250 * Params: 251 * data = data for the new item 252 * iterCmp = the function used to compare iterators in the sequence 253 * cmpData = user data passed to @iter_cmp 254 * 255 * Returns: a #GSequenceIter pointing to the new item 256 * 257 * Since: 2.14 258 */ 259 public SequenceIter insertSortedIter(void* data, GSequenceIterCompareFunc iterCmp, void* cmpData) 260 { 261 auto __p = g_sequence_insert_sorted_iter(gSequence, data, iterCmp, cmpData); 262 263 if(__p is null) 264 { 265 return null; 266 } 267 268 return new SequenceIter(cast(GSequenceIter*) __p); 269 } 270 271 /** 272 * Returns %TRUE if the sequence contains zero items. 273 * 274 * This function is functionally identical to checking the result of 275 * g_sequence_get_length() being equal to zero. However this function is 276 * implemented in O(1) running time. 277 * 278 * Returns: %TRUE if the sequence is empty, otherwise %FALSE. 279 * 280 * Since: 2.48 281 */ 282 public bool isEmpty() 283 { 284 return g_sequence_is_empty(gSequence) != 0; 285 } 286 287 /** 288 * Returns an iterator pointing to the position of the first item found 289 * equal to @data according to @cmp_func and @cmp_data. If more than one 290 * item is equal, it is not guaranteed that it is the first which is 291 * returned. In that case, you can use g_sequence_iter_next() and 292 * g_sequence_iter_prev() to get others. 293 * 294 * @cmp_func is called with two items of the @seq, and @cmp_data. 295 * It should return 0 if the items are equal, a negative value if 296 * the first item comes before the second, and a positive value if 297 * the second item comes before the first. 298 * 299 * This function will fail if the data contained in the sequence is 300 * unsorted. 301 * 302 * Params: 303 * data = data to look up 304 * cmpFunc = the function used to compare items in the sequence 305 * cmpData = user data passed to @cmp_func 306 * 307 * Returns: an #GSequenceIter pointing to the position of the 308 * first item found equal to @data according to @cmp_func and 309 * @cmp_data, or %NULL if no such item exists 310 * 311 * Since: 2.28 312 */ 313 public SequenceIter lookup(void* data, GCompareDataFunc cmpFunc, void* cmpData) 314 { 315 auto __p = g_sequence_lookup(gSequence, data, cmpFunc, cmpData); 316 317 if(__p is null) 318 { 319 return null; 320 } 321 322 return new SequenceIter(cast(GSequenceIter*) __p); 323 } 324 325 /** 326 * Like g_sequence_lookup(), but uses a #GSequenceIterCompareFunc 327 * instead of a #GCompareDataFunc as the compare function. 328 * 329 * @iter_cmp is called with two iterators pointing into @seq. 330 * It should return 0 if the iterators are equal, a negative value 331 * if the first iterator comes before the second, and a positive 332 * value if the second iterator comes before the first. 333 * 334 * This function will fail if the data contained in the sequence is 335 * unsorted. 336 * 337 * Params: 338 * data = data to look up 339 * iterCmp = the function used to compare iterators in the sequence 340 * cmpData = user data passed to @iter_cmp 341 * 342 * Returns: an #GSequenceIter pointing to the position of 343 * the first item found equal to @data according to @iter_cmp 344 * and @cmp_data, or %NULL if no such item exists 345 * 346 * Since: 2.28 347 */ 348 public SequenceIter lookupIter(void* data, GSequenceIterCompareFunc iterCmp, void* cmpData) 349 { 350 auto __p = g_sequence_lookup_iter(gSequence, data, iterCmp, cmpData); 351 352 if(__p is null) 353 { 354 return null; 355 } 356 357 return new SequenceIter(cast(GSequenceIter*) __p); 358 } 359 360 /** 361 * Adds a new item to the front of @seq 362 * 363 * Params: 364 * data = the data for the new item 365 * 366 * Returns: an iterator pointing to the new item 367 * 368 * Since: 2.14 369 */ 370 public SequenceIter prepend(void* data) 371 { 372 auto __p = g_sequence_prepend(gSequence, data); 373 374 if(__p is null) 375 { 376 return null; 377 } 378 379 return new SequenceIter(cast(GSequenceIter*) __p); 380 } 381 382 /** 383 * Returns an iterator pointing to the position where @data would 384 * be inserted according to @cmp_func and @cmp_data. 385 * 386 * @cmp_func is called with two items of the @seq, and @cmp_data. 387 * It should return 0 if the items are equal, a negative value if 388 * the first item comes before the second, and a positive value if 389 * the second item comes before the first. 390 * 391 * If you are simply searching for an existing element of the sequence, 392 * consider using g_sequence_lookup(). 393 * 394 * This function will fail if the data contained in the sequence is 395 * unsorted. 396 * 397 * Params: 398 * data = data for the new item 399 * cmpFunc = the function used to compare items in the sequence 400 * cmpData = user data passed to @cmp_func 401 * 402 * Returns: an #GSequenceIter pointing to the position where @data 403 * would have been inserted according to @cmp_func and @cmp_data 404 * 405 * Since: 2.14 406 */ 407 public SequenceIter search(void* data, GCompareDataFunc cmpFunc, void* cmpData) 408 { 409 auto __p = g_sequence_search(gSequence, data, cmpFunc, cmpData); 410 411 if(__p is null) 412 { 413 return null; 414 } 415 416 return new SequenceIter(cast(GSequenceIter*) __p); 417 } 418 419 /** 420 * Like g_sequence_search(), but uses a #GSequenceIterCompareFunc 421 * instead of a #GCompareDataFunc as the compare function. 422 * 423 * @iter_cmp is called with two iterators pointing into @seq. 424 * It should return 0 if the iterators are equal, a negative value 425 * if the first iterator comes before the second, and a positive 426 * value if the second iterator comes before the first. 427 * 428 * If you are simply searching for an existing element of the sequence, 429 * consider using g_sequence_lookup_iter(). 430 * 431 * This function will fail if the data contained in the sequence is 432 * unsorted. 433 * 434 * Params: 435 * data = data for the new item 436 * iterCmp = the function used to compare iterators in the sequence 437 * cmpData = user data passed to @iter_cmp 438 * 439 * Returns: a #GSequenceIter pointing to the position in @seq 440 * where @data would have been inserted according to @iter_cmp 441 * and @cmp_data 442 * 443 * Since: 2.14 444 */ 445 public SequenceIter searchIter(void* data, GSequenceIterCompareFunc iterCmp, void* cmpData) 446 { 447 auto __p = g_sequence_search_iter(gSequence, data, iterCmp, cmpData); 448 449 if(__p is null) 450 { 451 return null; 452 } 453 454 return new SequenceIter(cast(GSequenceIter*) __p); 455 } 456 457 /** 458 * Sorts @seq using @cmp_func. 459 * 460 * @cmp_func is passed two items of @seq and should 461 * return 0 if they are equal, a negative value if the 462 * first comes before the second, and a positive value 463 * if the second comes before the first. 464 * 465 * Params: 466 * cmpFunc = the function used to sort the sequence 467 * cmpData = user data passed to @cmp_func 468 * 469 * Since: 2.14 470 */ 471 public void sort(GCompareDataFunc cmpFunc, void* cmpData) 472 { 473 g_sequence_sort(gSequence, cmpFunc, cmpData); 474 } 475 476 /** 477 * Like g_sequence_sort(), but uses a #GSequenceIterCompareFunc instead 478 * of a #GCompareDataFunc as the compare function 479 * 480 * @cmp_func is called with two iterators pointing into @seq. It should 481 * return 0 if the iterators are equal, a negative value if the first 482 * iterator comes before the second, and a positive value if the second 483 * iterator comes before the first. 484 * 485 * Params: 486 * cmpFunc = the function used to compare iterators in the sequence 487 * cmpData = user data passed to @cmp_func 488 * 489 * Since: 2.14 490 */ 491 public void sortIter(GSequenceIterCompareFunc cmpFunc, void* cmpData) 492 { 493 g_sequence_sort_iter(gSequence, cmpFunc, cmpData); 494 } 495 496 /** 497 * Calls @func for each item in the range (@begin, @end) passing 498 * @user_data to the function. @func must not modify the sequence 499 * itself. 500 * 501 * Params: 502 * begin = a #GSequenceIter 503 * end = a #GSequenceIter 504 * func = a #GFunc 505 * userData = user data passed to @func 506 * 507 * Since: 2.14 508 */ 509 public static void foreachRange(SequenceIter begin, SequenceIter end, GFunc func, void* userData) 510 { 511 g_sequence_foreach_range((begin is null) ? null : begin.getSequenceIterStruct(), (end is null) ? null : end.getSequenceIterStruct(), func, userData); 512 } 513 514 /** 515 * Returns the data that @iter points to. 516 * 517 * Params: 518 * iter = a #GSequenceIter 519 * 520 * Returns: the data that @iter points to 521 * 522 * Since: 2.14 523 */ 524 public static void* get(SequenceIter iter) 525 { 526 return g_sequence_get((iter is null) ? null : iter.getSequenceIterStruct()); 527 } 528 529 /** 530 * Inserts a new item just before the item pointed to by @iter. 531 * 532 * Params: 533 * iter = a #GSequenceIter 534 * data = the data for the new item 535 * 536 * Returns: an iterator pointing to the new item 537 * 538 * Since: 2.14 539 */ 540 public static SequenceIter insertBefore(SequenceIter iter, void* data) 541 { 542 auto __p = g_sequence_insert_before((iter is null) ? null : iter.getSequenceIterStruct(), data); 543 544 if(__p is null) 545 { 546 return null; 547 } 548 549 return new SequenceIter(cast(GSequenceIter*) __p); 550 } 551 552 /** 553 * Moves the item pointed to by @src to the position indicated by @dest. 554 * After calling this function @dest will point to the position immediately 555 * after @src. It is allowed for @src and @dest to point into different 556 * sequences. 557 * 558 * Params: 559 * src = a #GSequenceIter pointing to the item to move 560 * dest = a #GSequenceIter pointing to the position to which 561 * the item is moved 562 * 563 * Since: 2.14 564 */ 565 public static void move(SequenceIter src, SequenceIter dest) 566 { 567 g_sequence_move((src is null) ? null : src.getSequenceIterStruct(), (dest is null) ? null : dest.getSequenceIterStruct()); 568 } 569 570 /** 571 * Inserts the (@begin, @end) range at the destination pointed to by @dest. 572 * The @begin and @end iters must point into the same sequence. It is 573 * allowed for @dest to point to a different sequence than the one pointed 574 * into by @begin and @end. 575 * 576 * If @dest is %NULL, the range indicated by @begin and @end is 577 * removed from the sequence. If @dest points to a place within 578 * the (@begin, @end) range, the range does not move. 579 * 580 * Params: 581 * dest = a #GSequenceIter 582 * begin = a #GSequenceIter 583 * end = a #GSequenceIter 584 * 585 * Since: 2.14 586 */ 587 public static void moveRange(SequenceIter dest, SequenceIter begin, SequenceIter end) 588 { 589 g_sequence_move_range((dest is null) ? null : dest.getSequenceIterStruct(), (begin is null) ? null : begin.getSequenceIterStruct(), (end is null) ? null : end.getSequenceIterStruct()); 590 } 591 592 /** 593 * Creates a new GSequence. The @data_destroy function, if non-%NULL will 594 * be called on all items when the sequence is destroyed and on items that 595 * are removed from the sequence. 596 * 597 * Params: 598 * dataDestroy = a #GDestroyNotify function, or %NULL 599 * 600 * Returns: a new #GSequence 601 * 602 * Since: 2.14 603 * 604 * Throws: ConstructionException GTK+ fails to create the object. 605 */ 606 public this(GDestroyNotify dataDestroy) 607 { 608 auto __p = g_sequence_new(dataDestroy); 609 610 if(__p is null) 611 { 612 throw new ConstructionException("null returned by new"); 613 } 614 615 this(cast(GSequence*) __p); 616 } 617 618 /** 619 * Finds an iterator somewhere in the range (@begin, @end). This 620 * iterator will be close to the middle of the range, but is not 621 * guaranteed to be exactly in the middle. 622 * 623 * The @begin and @end iterators must both point to the same sequence 624 * and @begin must come before or be equal to @end in the sequence. 625 * 626 * Params: 627 * begin = a #GSequenceIter 628 * end = a #GSequenceIter 629 * 630 * Returns: a #GSequenceIter pointing somewhere in the 631 * (@begin, @end) range 632 * 633 * Since: 2.14 634 */ 635 public static SequenceIter rangeGetMidpoint(SequenceIter begin, SequenceIter end) 636 { 637 auto __p = g_sequence_range_get_midpoint((begin is null) ? null : begin.getSequenceIterStruct(), (end is null) ? null : end.getSequenceIterStruct()); 638 639 if(__p is null) 640 { 641 return null; 642 } 643 644 return new SequenceIter(cast(GSequenceIter*) __p); 645 } 646 647 /** 648 * Removes the item pointed to by @iter. It is an error to pass the 649 * end iterator to this function. 650 * 651 * If the sequence has a data destroy function associated with it, this 652 * function is called on the data for the removed item. 653 * 654 * Params: 655 * iter = a #GSequenceIter 656 * 657 * Since: 2.14 658 */ 659 public static void remove(SequenceIter iter) 660 { 661 g_sequence_remove((iter is null) ? null : iter.getSequenceIterStruct()); 662 } 663 664 /** 665 * Removes all items in the (@begin, @end) range. 666 * 667 * If the sequence has a data destroy function associated with it, this 668 * function is called on the data for the removed items. 669 * 670 * Params: 671 * begin = a #GSequenceIter 672 * end = a #GSequenceIter 673 * 674 * Since: 2.14 675 */ 676 public static void removeRange(SequenceIter begin, SequenceIter end) 677 { 678 g_sequence_remove_range((begin is null) ? null : begin.getSequenceIterStruct(), (end is null) ? null : end.getSequenceIterStruct()); 679 } 680 681 /** 682 * Changes the data for the item pointed to by @iter to be @data. If 683 * the sequence has a data destroy function associated with it, that 684 * function is called on the existing data that @iter pointed to. 685 * 686 * Params: 687 * iter = a #GSequenceIter 688 * data = new data for the item 689 * 690 * Since: 2.14 691 */ 692 public static void set(SequenceIter iter, void* data) 693 { 694 g_sequence_set((iter is null) ? null : iter.getSequenceIterStruct(), data); 695 } 696 697 /** 698 * Moves the data pointed to by @iter to a new position as indicated by 699 * @cmp_func. This 700 * function should be called for items in a sequence already sorted according 701 * to @cmp_func whenever some aspect of an item changes so that @cmp_func 702 * may return different values for that item. 703 * 704 * @cmp_func is called with two items of the @seq, and @cmp_data. 705 * It should return 0 if the items are equal, a negative value if 706 * the first item comes before the second, and a positive value if 707 * the second item comes before the first. 708 * 709 * Params: 710 * iter = A #GSequenceIter 711 * cmpFunc = the function used to compare items in the sequence 712 * cmpData = user data passed to @cmp_func. 713 * 714 * Since: 2.14 715 */ 716 public static void sortChanged(SequenceIter iter, GCompareDataFunc cmpFunc, void* cmpData) 717 { 718 g_sequence_sort_changed((iter is null) ? null : iter.getSequenceIterStruct(), cmpFunc, cmpData); 719 } 720 721 /** 722 * Like g_sequence_sort_changed(), but uses 723 * a #GSequenceIterCompareFunc instead of a #GCompareDataFunc as 724 * the compare function. 725 * 726 * @iter_cmp is called with two iterators pointing into the #GSequence that 727 * @iter points into. It should 728 * return 0 if the iterators are equal, a negative value if the first 729 * iterator comes before the second, and a positive value if the second 730 * iterator comes before the first. 731 * 732 * Params: 733 * iter = a #GSequenceIter 734 * iterCmp = the function used to compare iterators in the sequence 735 * cmpData = user data passed to @cmp_func 736 * 737 * Since: 2.14 738 */ 739 public static void sortChangedIter(SequenceIter iter, GSequenceIterCompareFunc iterCmp, void* cmpData) 740 { 741 g_sequence_sort_changed_iter((iter is null) ? null : iter.getSequenceIterStruct(), iterCmp, cmpData); 742 } 743 744 /** 745 * Swaps the items pointed to by @a and @b. It is allowed for @a and @b 746 * to point into difference sequences. 747 * 748 * Params: 749 * a = a #GSequenceIter 750 * b = a #GSequenceIter 751 * 752 * Since: 2.14 753 */ 754 public static void swap(SequenceIter a, SequenceIter b) 755 { 756 g_sequence_swap((a is null) ? null : a.getSequenceIterStruct(), (b is null) ? null : b.getSequenceIterStruct()); 757 } 758 }