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