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