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