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