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