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