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