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.QueueG; 26 27 private import glib.ConstructionException; 28 private import glib.ListG; 29 private import glib.c.functions; 30 public import glib.c.types; 31 public import gtkc.glibtypes; 32 private import gtkd.Loader; 33 34 35 /** 36 * Contains the public fields of a 37 * [Queue][glib-Double-ended-Queues]. 38 */ 39 public class QueueG 40 { 41 /** the main Gtk struct */ 42 protected GQueue* gQueue; 43 protected bool ownedRef; 44 45 /** Get the main Gtk struct */ 46 public GQueue* getQueueGStruct(bool transferOwnership = false) 47 { 48 if (transferOwnership) 49 ownedRef = false; 50 return gQueue; 51 } 52 53 /** the main Gtk struct as a void* */ 54 protected void* getStruct() 55 { 56 return cast(void*)gQueue; 57 } 58 59 /** 60 * Sets our main struct and passes it to the parent class. 61 */ 62 public this (GQueue* gQueue, bool ownedRef = false) 63 { 64 this.gQueue = gQueue; 65 this.ownedRef = ownedRef; 66 } 67 68 ~this () 69 { 70 if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef ) 71 g_queue_free(gQueue); 72 } 73 74 75 /** 76 * Removes all the elements in @queue. If queue elements contain 77 * dynamically-allocated memory, they should be freed first. 78 * 79 * Since: 2.14 80 */ 81 public void clear() 82 { 83 g_queue_clear(gQueue); 84 } 85 86 /** 87 * Copies a @queue. Note that is a shallow copy. If the elements in the 88 * queue consist of pointers to data, the pointers are copied, but the 89 * actual data is not. 90 * 91 * Returns: a copy of @queue 92 * 93 * Since: 2.4 94 */ 95 public QueueG copy() 96 { 97 auto p = g_queue_copy(gQueue); 98 99 if(p is null) 100 { 101 return null; 102 } 103 104 return new QueueG(cast(GQueue*) p); 105 } 106 107 /** 108 * Removes @link_ from @queue and frees it. 109 * 110 * @link_ must be part of @queue. 111 * 112 * Params: 113 * link = a #GList link that must be part of @queue 114 * 115 * Since: 2.4 116 */ 117 public void deleteLink(ListG link) 118 { 119 g_queue_delete_link(gQueue, (link is null) ? null : link.getListGStruct()); 120 } 121 122 /** 123 * Finds the first link in @queue which contains @data. 124 * 125 * Params: 126 * data = data to find 127 * 128 * Returns: the first link in @queue which contains @data 129 * 130 * Since: 2.4 131 */ 132 public ListG find(void* data) 133 { 134 auto p = g_queue_find(gQueue, data); 135 136 if(p is null) 137 { 138 return null; 139 } 140 141 return new ListG(cast(GList*) p); 142 } 143 144 /** 145 * Finds an element in a #GQueue, using a supplied function to find the 146 * desired element. It iterates over the queue, calling the given function 147 * which should return 0 when the desired element is found. The function 148 * takes two gconstpointer arguments, the #GQueue element's data as the 149 * first argument and the given user data as the second argument. 150 * 151 * Params: 152 * data = user data passed to @func 153 * func = a #GCompareFunc to call for each element. It should return 0 154 * when the desired element is found 155 * 156 * Returns: the found link, or %NULL if it wasn't found 157 * 158 * Since: 2.4 159 */ 160 public ListG findCustom(void* data, GCompareFunc func) 161 { 162 auto p = g_queue_find_custom(gQueue, data, func); 163 164 if(p is null) 165 { 166 return null; 167 } 168 169 return new ListG(cast(GList*) p); 170 } 171 172 alias foreac = foreach_; 173 /** 174 * Calls @func for each element in the queue passing @user_data to the 175 * function. 176 * 177 * It is safe for @func to remove the element from @queue, but it must 178 * not modify any part of the queue after that element. 179 * 180 * Params: 181 * func = the function to call for each element's data 182 * userData = user data to pass to @func 183 * 184 * Since: 2.4 185 */ 186 public void foreach_(GFunc func, void* userData) 187 { 188 g_queue_foreach(gQueue, func, userData); 189 } 190 191 /** 192 * Frees the memory allocated for the #GQueue. Only call this function 193 * if @queue was created with g_queue_new(). If queue elements contain 194 * dynamically-allocated memory, they should be freed first. 195 * 196 * If queue elements contain dynamically-allocated memory, you should 197 * either use g_queue_free_full() or free them manually first. 198 */ 199 public void free() 200 { 201 g_queue_free(gQueue); 202 ownedRef = false; 203 } 204 205 /** 206 * Convenience method, which frees all the memory used by a #GQueue, 207 * and calls the specified destroy function on every element's data. 208 * 209 * @free_func should not modify the queue (eg, by removing the freed 210 * element from it). 211 * 212 * Params: 213 * freeFunc = the function to be called to free each element's data 214 * 215 * Since: 2.32 216 */ 217 public void freeFull(GDestroyNotify freeFunc) 218 { 219 g_queue_free_full(gQueue, freeFunc); 220 } 221 222 /** 223 * Returns the number of items in @queue. 224 * 225 * Returns: the number of items in @queue 226 * 227 * Since: 2.4 228 */ 229 public uint getLength() 230 { 231 return g_queue_get_length(gQueue); 232 } 233 234 /** 235 * Returns the position of the first element in @queue which contains @data. 236 * 237 * Params: 238 * data = the data to find 239 * 240 * Returns: the position of the first element in @queue which 241 * contains @data, or -1 if no element in @queue contains @data 242 * 243 * Since: 2.4 244 */ 245 public int index(void* data) 246 { 247 return g_queue_index(gQueue, data); 248 } 249 250 /** 251 * A statically-allocated #GQueue must be initialized with this function 252 * before it can be used. Alternatively you can initialize it with 253 * #G_QUEUE_INIT. It is not necessary to initialize queues created with 254 * g_queue_new(). 255 * 256 * Since: 2.14 257 */ 258 public void init() 259 { 260 g_queue_init(gQueue); 261 } 262 263 /** 264 * Inserts @data into @queue after @sibling. 265 * 266 * @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the 267 * data at the head of the queue. 268 * 269 * Params: 270 * sibling = a #GList link that must be part of @queue, or %NULL to 271 * push at the head of the queue. 272 * data = the data to insert 273 * 274 * Since: 2.4 275 */ 276 public void insertAfter(ListG sibling, void* data) 277 { 278 g_queue_insert_after(gQueue, (sibling is null) ? null : sibling.getListGStruct(), data); 279 } 280 281 /** 282 * Inserts @data into @queue before @sibling. 283 * 284 * @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the 285 * data at the tail of the queue. 286 * 287 * Params: 288 * sibling = a #GList link that must be part of @queue, or %NULL to 289 * push at the tail of the queue. 290 * data = the data to insert 291 * 292 * Since: 2.4 293 */ 294 public void insertBefore(ListG sibling, void* data) 295 { 296 g_queue_insert_before(gQueue, (sibling is null) ? null : sibling.getListGStruct(), data); 297 } 298 299 /** 300 * Inserts @data into @queue using @func to determine the new position. 301 * 302 * Params: 303 * data = the data to insert 304 * func = the #GCompareDataFunc used to compare elements in the queue. It is 305 * called with two elements of the @queue and @user_data. It should 306 * return 0 if the elements are equal, a negative value if the first 307 * element comes before the second, and a positive value if the second 308 * element comes before the first. 309 * userData = user data passed to @func 310 * 311 * Since: 2.4 312 */ 313 public void insertSorted(void* data, GCompareDataFunc func, void* userData) 314 { 315 g_queue_insert_sorted(gQueue, data, func, userData); 316 } 317 318 /** 319 * Returns %TRUE if the queue is empty. 320 * 321 * Returns: %TRUE if the queue is empty 322 */ 323 public bool isEmpty() 324 { 325 return g_queue_is_empty(gQueue) != 0; 326 } 327 328 /** 329 * Returns the position of @link_ in @queue. 330 * 331 * Params: 332 * link = a #GList link 333 * 334 * Returns: the position of @link_, or -1 if the link is 335 * not part of @queue 336 * 337 * Since: 2.4 338 */ 339 public int linkIndex(ListG link) 340 { 341 return g_queue_link_index(gQueue, (link is null) ? null : link.getListGStruct()); 342 } 343 344 /** 345 * Returns the first element of the queue. 346 * 347 * Returns: the data of the first element in the queue, or %NULL 348 * if the queue is empty 349 */ 350 public void* peekHead() 351 { 352 return g_queue_peek_head(gQueue); 353 } 354 355 /** 356 * Returns the first link in @queue. 357 * 358 * Returns: the first link in @queue, or %NULL if @queue is empty 359 * 360 * Since: 2.4 361 */ 362 public ListG peekHeadLink() 363 { 364 auto p = g_queue_peek_head_link(gQueue); 365 366 if(p is null) 367 { 368 return null; 369 } 370 371 return new ListG(cast(GList*) p); 372 } 373 374 /** 375 * Returns the @n'th element of @queue. 376 * 377 * Params: 378 * n = the position of the element 379 * 380 * Returns: the data for the @n'th element of @queue, 381 * or %NULL if @n is off the end of @queue 382 * 383 * Since: 2.4 384 */ 385 public void* peekNth(uint n) 386 { 387 return g_queue_peek_nth(gQueue, n); 388 } 389 390 /** 391 * Returns the link at the given position 392 * 393 * Params: 394 * n = the position of the link 395 * 396 * Returns: the link at the @n'th position, or %NULL 397 * if @n is off the end of the list 398 * 399 * Since: 2.4 400 */ 401 public ListG peekNthLink(uint n) 402 { 403 auto p = g_queue_peek_nth_link(gQueue, n); 404 405 if(p is null) 406 { 407 return null; 408 } 409 410 return new ListG(cast(GList*) p); 411 } 412 413 /** 414 * Returns the last element of the queue. 415 * 416 * Returns: the data of the last element in the queue, or %NULL 417 * if the queue is empty 418 */ 419 public void* peekTail() 420 { 421 return g_queue_peek_tail(gQueue); 422 } 423 424 /** 425 * Returns the last link in @queue. 426 * 427 * Returns: the last link in @queue, or %NULL if @queue is empty 428 * 429 * Since: 2.4 430 */ 431 public ListG peekTailLink() 432 { 433 auto p = g_queue_peek_tail_link(gQueue); 434 435 if(p is null) 436 { 437 return null; 438 } 439 440 return new ListG(cast(GList*) p); 441 } 442 443 /** 444 * Removes the first element of the queue and returns its data. 445 * 446 * Returns: the data of the first element in the queue, or %NULL 447 * if the queue is empty 448 */ 449 public void* popHead() 450 { 451 return g_queue_pop_head(gQueue); 452 } 453 454 /** 455 * Removes and returns the first element of the queue. 456 * 457 * Returns: the #GList element at the head of the queue, or %NULL 458 * if the queue is empty 459 */ 460 public ListG popHeadLink() 461 { 462 auto p = g_queue_pop_head_link(gQueue); 463 464 if(p is null) 465 { 466 return null; 467 } 468 469 return new ListG(cast(GList*) p); 470 } 471 472 /** 473 * Removes the @n'th element of @queue and returns its data. 474 * 475 * Params: 476 * n = the position of the element 477 * 478 * Returns: the element's data, or %NULL if @n is off the end of @queue 479 * 480 * Since: 2.4 481 */ 482 public void* popNth(uint n) 483 { 484 return g_queue_pop_nth(gQueue, n); 485 } 486 487 /** 488 * Removes and returns the link at the given position. 489 * 490 * Params: 491 * n = the link's position 492 * 493 * Returns: the @n'th link, or %NULL if @n is off the end of @queue 494 * 495 * Since: 2.4 496 */ 497 public ListG popNthLink(uint n) 498 { 499 auto p = g_queue_pop_nth_link(gQueue, n); 500 501 if(p is null) 502 { 503 return null; 504 } 505 506 return new ListG(cast(GList*) p); 507 } 508 509 /** 510 * Removes the last element of the queue and returns its data. 511 * 512 * Returns: the data of the last element in the queue, or %NULL 513 * if the queue is empty 514 */ 515 public void* popTail() 516 { 517 return g_queue_pop_tail(gQueue); 518 } 519 520 /** 521 * Removes and returns the last element of the queue. 522 * 523 * Returns: the #GList element at the tail of the queue, or %NULL 524 * if the queue is empty 525 */ 526 public ListG popTailLink() 527 { 528 auto p = g_queue_pop_tail_link(gQueue); 529 530 if(p is null) 531 { 532 return null; 533 } 534 535 return new ListG(cast(GList*) p); 536 } 537 538 /** 539 * Adds a new element at the head of the queue. 540 * 541 * Params: 542 * data = the data for the new element. 543 */ 544 public void pushHead(void* data) 545 { 546 g_queue_push_head(gQueue, data); 547 } 548 549 /** 550 * Adds a new element at the head of the queue. 551 * 552 * Params: 553 * link = a single #GList element, not a list with more than one element 554 */ 555 public void pushHeadLink(ListG link) 556 { 557 g_queue_push_head_link(gQueue, (link is null) ? null : link.getListGStruct()); 558 } 559 560 /** 561 * Inserts a new element into @queue at the given position. 562 * 563 * Params: 564 * data = the data for the new element 565 * n = the position to insert the new element. If @n is negative or 566 * larger than the number of elements in the @queue, the element is 567 * added to the end of the queue. 568 * 569 * Since: 2.4 570 */ 571 public void pushNth(void* data, int n) 572 { 573 g_queue_push_nth(gQueue, data, n); 574 } 575 576 /** 577 * Inserts @link into @queue at the given position. 578 * 579 * Params: 580 * n = the position to insert the link. If this is negative or larger than 581 * the number of elements in @queue, the link is added to the end of 582 * @queue. 583 * link = the link to add to @queue 584 * 585 * Since: 2.4 586 */ 587 public void pushNthLink(int n, ListG link) 588 { 589 g_queue_push_nth_link(gQueue, n, (link is null) ? null : link.getListGStruct()); 590 } 591 592 /** 593 * Adds a new element at the tail of the queue. 594 * 595 * Params: 596 * data = the data for the new element 597 */ 598 public void pushTail(void* data) 599 { 600 g_queue_push_tail(gQueue, data); 601 } 602 603 /** 604 * Adds a new element at the tail of the queue. 605 * 606 * Params: 607 * link = a single #GList element, not a list with more than one element 608 */ 609 public void pushTailLink(ListG link) 610 { 611 g_queue_push_tail_link(gQueue, (link is null) ? null : link.getListGStruct()); 612 } 613 614 /** 615 * Removes the first element in @queue that contains @data. 616 * 617 * Params: 618 * data = the data to remove 619 * 620 * Returns: %TRUE if @data was found and removed from @queue 621 * 622 * Since: 2.4 623 */ 624 public bool remove(void* data) 625 { 626 return g_queue_remove(gQueue, data) != 0; 627 } 628 629 /** 630 * Remove all elements whose data equals @data from @queue. 631 * 632 * Params: 633 * data = the data to remove 634 * 635 * Returns: the number of elements removed from @queue 636 * 637 * Since: 2.4 638 */ 639 public uint removeAll(void* data) 640 { 641 return g_queue_remove_all(gQueue, data); 642 } 643 644 /** 645 * Reverses the order of the items in @queue. 646 * 647 * Since: 2.4 648 */ 649 public void reverse() 650 { 651 g_queue_reverse(gQueue); 652 } 653 654 /** 655 * Sorts @queue using @compare_func. 656 * 657 * Params: 658 * compareFunc = the #GCompareDataFunc used to sort @queue. This function 659 * is passed two elements of the queue and should return 0 if they are 660 * equal, a negative value if the first comes before the second, and 661 * a positive value if the second comes before the first. 662 * userData = user data passed to @compare_func 663 * 664 * Since: 2.4 665 */ 666 public void sort(GCompareDataFunc compareFunc, void* userData) 667 { 668 g_queue_sort(gQueue, compareFunc, userData); 669 } 670 671 /** 672 * Unlinks @link_ so that it will no longer be part of @queue. 673 * The link is not freed. 674 * 675 * @link_ must be part of @queue. 676 * 677 * Params: 678 * link = a #GList link that must be part of @queue 679 * 680 * Since: 2.4 681 */ 682 public void unlink(ListG link) 683 { 684 g_queue_unlink(gQueue, (link is null) ? null : link.getListGStruct()); 685 } 686 687 /** 688 * Creates a new #GQueue. 689 * 690 * Returns: a newly allocated #GQueue 691 * 692 * Throws: ConstructionException GTK+ fails to create the object. 693 */ 694 public this() 695 { 696 auto p = g_queue_new(); 697 698 if(p is null) 699 { 700 throw new ConstructionException("null returned by new"); 701 } 702 703 this(cast(GQueue*) p); 704 } 705 }