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