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 /** 173 * Calls @func for each element in the queue passing @user_data to the 174 * function. 175 * 176 * It is safe for @func to remove the element from @queue, but it must 177 * not modify any part of the queue after that element. 178 * 179 * Params: 180 * func = the function to call for each element's data 181 * userData = user data to pass to @func 182 * 183 * Since: 2.4 184 */ 185 public void foreac(GFunc func, void* userData) 186 { 187 g_queue_foreach(gQueue, func, userData); 188 } 189 190 /** 191 * Frees the memory allocated for the #GQueue. Only call this function 192 * if @queue was created with g_queue_new(). If queue elements contain 193 * dynamically-allocated memory, they should be freed first. 194 * 195 * If queue elements contain dynamically-allocated memory, you should 196 * either use g_queue_free_full() or free them manually first. 197 */ 198 public void free() 199 { 200 g_queue_free(gQueue); 201 ownedRef = false; 202 } 203 204 /** 205 * Convenience method, which frees all the memory used by a #GQueue, 206 * and calls the specified destroy function on every element's data. 207 * 208 * @free_func should not modify the queue (eg, by removing the freed 209 * element from it). 210 * 211 * Params: 212 * freeFunc = the function to be called to free each element's data 213 * 214 * Since: 2.32 215 */ 216 public void freeFull(GDestroyNotify freeFunc) 217 { 218 g_queue_free_full(gQueue, freeFunc); 219 } 220 221 /** 222 * Returns the number of items in @queue. 223 * 224 * Returns: the number of items in @queue 225 * 226 * Since: 2.4 227 */ 228 public uint getLength() 229 { 230 return g_queue_get_length(gQueue); 231 } 232 233 /** 234 * Returns the position of the first element in @queue which contains @data. 235 * 236 * Params: 237 * data = the data to find 238 * 239 * Returns: the position of the first element in @queue which 240 * contains @data, or -1 if no element in @queue contains @data 241 * 242 * Since: 2.4 243 */ 244 public int index(void* data) 245 { 246 return g_queue_index(gQueue, data); 247 } 248 249 /** 250 * A statically-allocated #GQueue must be initialized with this function 251 * before it can be used. Alternatively you can initialize it with 252 * #G_QUEUE_INIT. It is not necessary to initialize queues created with 253 * g_queue_new(). 254 * 255 * Since: 2.14 256 */ 257 public void init() 258 { 259 g_queue_init(gQueue); 260 } 261 262 /** 263 * Inserts @data into @queue after @sibling. 264 * 265 * @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the 266 * data at the head of the queue. 267 * 268 * Params: 269 * sibling = a #GList link that must be part of @queue, or %NULL to 270 * push at the head of the queue. 271 * data = the data to insert 272 * 273 * Since: 2.4 274 */ 275 public void insertAfter(ListG sibling, void* data) 276 { 277 g_queue_insert_after(gQueue, (sibling is null) ? null : sibling.getListGStruct(), data); 278 } 279 280 /** 281 * Inserts @data into @queue before @sibling. 282 * 283 * @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the 284 * data at the tail of the queue. 285 * 286 * Params: 287 * sibling = a #GList link that must be part of @queue, or %NULL to 288 * push at the tail of the queue. 289 * data = the data to insert 290 * 291 * Since: 2.4 292 */ 293 public void insertBefore(ListG sibling, void* data) 294 { 295 g_queue_insert_before(gQueue, (sibling is null) ? null : sibling.getListGStruct(), data); 296 } 297 298 /** 299 * Inserts @data into @queue using @func to determine the new position. 300 * 301 * Params: 302 * data = the data to insert 303 * func = the #GCompareDataFunc used to compare elements in the queue. It is 304 * called with two elements of the @queue and @user_data. It should 305 * return 0 if the elements are equal, a negative value if the first 306 * element comes before the second, and a positive value if the second 307 * element comes before the first. 308 * userData = user data passed to @func 309 * 310 * Since: 2.4 311 */ 312 public void insertSorted(void* data, GCompareDataFunc func, void* userData) 313 { 314 g_queue_insert_sorted(gQueue, data, func, userData); 315 } 316 317 /** 318 * Returns %TRUE if the queue is empty. 319 * 320 * Returns: %TRUE if the queue is empty 321 */ 322 public bool isEmpty() 323 { 324 return g_queue_is_empty(gQueue) != 0; 325 } 326 327 /** 328 * Returns the position of @link_ in @queue. 329 * 330 * Params: 331 * link = a #GList link 332 * 333 * Returns: the position of @link_, or -1 if the link is 334 * not part of @queue 335 * 336 * Since: 2.4 337 */ 338 public int linkIndex(ListG link) 339 { 340 return g_queue_link_index(gQueue, (link is null) ? null : link.getListGStruct()); 341 } 342 343 /** 344 * Returns the first element of the queue. 345 * 346 * Returns: the data of the first element in the queue, or %NULL 347 * if the queue is empty 348 */ 349 public void* peekHead() 350 { 351 return g_queue_peek_head(gQueue); 352 } 353 354 /** 355 * Returns the first link in @queue. 356 * 357 * Returns: the first link in @queue, or %NULL if @queue is empty 358 * 359 * Since: 2.4 360 */ 361 public ListG peekHeadLink() 362 { 363 auto p = g_queue_peek_head_link(gQueue); 364 365 if(p is null) 366 { 367 return null; 368 } 369 370 return new ListG(cast(GList*) p); 371 } 372 373 /** 374 * Returns the @n'th element of @queue. 375 * 376 * Params: 377 * n = the position of the element 378 * 379 * Returns: the data for the @n'th element of @queue, 380 * or %NULL if @n is off the end of @queue 381 * 382 * Since: 2.4 383 */ 384 public void* peekNth(uint n) 385 { 386 return g_queue_peek_nth(gQueue, n); 387 } 388 389 /** 390 * Returns the link at the given position 391 * 392 * Params: 393 * n = the position of the link 394 * 395 * Returns: the link at the @n'th position, or %NULL 396 * if @n is off the end of the list 397 * 398 * Since: 2.4 399 */ 400 public ListG peekNthLink(uint n) 401 { 402 auto p = g_queue_peek_nth_link(gQueue, n); 403 404 if(p is null) 405 { 406 return null; 407 } 408 409 return new ListG(cast(GList*) p); 410 } 411 412 /** 413 * Returns the last element of the queue. 414 * 415 * Returns: the data of the last element in the queue, or %NULL 416 * if the queue is empty 417 */ 418 public void* peekTail() 419 { 420 return g_queue_peek_tail(gQueue); 421 } 422 423 /** 424 * Returns the last link in @queue. 425 * 426 * Returns: the last link in @queue, or %NULL if @queue is empty 427 * 428 * Since: 2.4 429 */ 430 public ListG peekTailLink() 431 { 432 auto p = g_queue_peek_tail_link(gQueue); 433 434 if(p is null) 435 { 436 return null; 437 } 438 439 return new ListG(cast(GList*) p); 440 } 441 442 /** 443 * Removes the first element of the queue and returns its data. 444 * 445 * Returns: the data of the first element in the queue, or %NULL 446 * if the queue is empty 447 */ 448 public void* popHead() 449 { 450 return g_queue_pop_head(gQueue); 451 } 452 453 /** 454 * Removes and returns the first element of the queue. 455 * 456 * Returns: the #GList element at the head of the queue, or %NULL 457 * if the queue is empty 458 */ 459 public ListG popHeadLink() 460 { 461 auto p = g_queue_pop_head_link(gQueue); 462 463 if(p is null) 464 { 465 return null; 466 } 467 468 return new ListG(cast(GList*) p); 469 } 470 471 /** 472 * Removes the @n'th element of @queue and returns its data. 473 * 474 * Params: 475 * n = the position of the element 476 * 477 * Returns: the element's data, or %NULL if @n is off the end of @queue 478 * 479 * Since: 2.4 480 */ 481 public void* popNth(uint n) 482 { 483 return g_queue_pop_nth(gQueue, n); 484 } 485 486 /** 487 * Removes and returns the link at the given position. 488 * 489 * Params: 490 * n = the link's position 491 * 492 * Returns: the @n'th link, or %NULL if @n is off the end of @queue 493 * 494 * Since: 2.4 495 */ 496 public ListG popNthLink(uint n) 497 { 498 auto p = g_queue_pop_nth_link(gQueue, n); 499 500 if(p is null) 501 { 502 return null; 503 } 504 505 return new ListG(cast(GList*) p); 506 } 507 508 /** 509 * Removes the last element of the queue and returns its data. 510 * 511 * Returns: the data of the last element in the queue, or %NULL 512 * if the queue is empty 513 */ 514 public void* popTail() 515 { 516 return g_queue_pop_tail(gQueue); 517 } 518 519 /** 520 * Removes and returns the last element of the queue. 521 * 522 * Returns: the #GList element at the tail of the queue, or %NULL 523 * if the queue is empty 524 */ 525 public ListG popTailLink() 526 { 527 auto p = g_queue_pop_tail_link(gQueue); 528 529 if(p is null) 530 { 531 return null; 532 } 533 534 return new ListG(cast(GList*) p); 535 } 536 537 /** 538 * Adds a new element at the head of the queue. 539 * 540 * Params: 541 * data = the data for the new element. 542 */ 543 public void pushHead(void* data) 544 { 545 g_queue_push_head(gQueue, data); 546 } 547 548 /** 549 * Adds a new element at the head of the queue. 550 * 551 * Params: 552 * link = a single #GList element, not a list with more than one element 553 */ 554 public void pushHeadLink(ListG link) 555 { 556 g_queue_push_head_link(gQueue, (link is null) ? null : link.getListGStruct()); 557 } 558 559 /** 560 * Inserts a new element into @queue at the given position. 561 * 562 * Params: 563 * data = the data for the new element 564 * n = the position to insert the new element. If @n is negative or 565 * larger than the number of elements in the @queue, the element is 566 * added to the end of the queue. 567 * 568 * Since: 2.4 569 */ 570 public void pushNth(void* data, int n) 571 { 572 g_queue_push_nth(gQueue, data, n); 573 } 574 575 /** 576 * Inserts @link into @queue at the given position. 577 * 578 * Params: 579 * n = the position to insert the link. If this is negative or larger than 580 * the number of elements in @queue, the link is added to the end of 581 * @queue. 582 * link = the link to add to @queue 583 * 584 * Since: 2.4 585 */ 586 public void pushNthLink(int n, ListG link) 587 { 588 g_queue_push_nth_link(gQueue, n, (link is null) ? null : link.getListGStruct()); 589 } 590 591 /** 592 * Adds a new element at the tail of the queue. 593 * 594 * Params: 595 * data = the data for the new element 596 */ 597 public void pushTail(void* data) 598 { 599 g_queue_push_tail(gQueue, data); 600 } 601 602 /** 603 * Adds a new element at the tail of the queue. 604 * 605 * Params: 606 * link = a single #GList element, not a list with more than one element 607 */ 608 public void pushTailLink(ListG link) 609 { 610 g_queue_push_tail_link(gQueue, (link is null) ? null : link.getListGStruct()); 611 } 612 613 /** 614 * Removes the first element in @queue that contains @data. 615 * 616 * Params: 617 * data = the data to remove 618 * 619 * Returns: %TRUE if @data was found and removed from @queue 620 * 621 * Since: 2.4 622 */ 623 public bool remove(void* data) 624 { 625 return g_queue_remove(gQueue, data) != 0; 626 } 627 628 /** 629 * Remove all elements whose data equals @data from @queue. 630 * 631 * Params: 632 * data = the data to remove 633 * 634 * Returns: the number of elements removed from @queue 635 * 636 * Since: 2.4 637 */ 638 public uint removeAll(void* data) 639 { 640 return g_queue_remove_all(gQueue, data); 641 } 642 643 /** 644 * Reverses the order of the items in @queue. 645 * 646 * Since: 2.4 647 */ 648 public void reverse() 649 { 650 g_queue_reverse(gQueue); 651 } 652 653 /** 654 * Sorts @queue using @compare_func. 655 * 656 * Params: 657 * compareFunc = the #GCompareDataFunc used to sort @queue. This function 658 * is passed two elements of the queue and should return 0 if they are 659 * equal, a negative value if the first comes before the second, and 660 * a positive value if the second comes before the first. 661 * userData = user data passed to @compare_func 662 * 663 * Since: 2.4 664 */ 665 public void sort(GCompareDataFunc compareFunc, void* userData) 666 { 667 g_queue_sort(gQueue, compareFunc, userData); 668 } 669 670 /** 671 * Unlinks @link_ so that it will no longer be part of @queue. 672 * The link is not freed. 673 * 674 * @link_ must be part of @queue. 675 * 676 * Params: 677 * link = a #GList link that must be part of @queue 678 * 679 * Since: 2.4 680 */ 681 public void unlink(ListG link) 682 { 683 g_queue_unlink(gQueue, (link is null) ? null : link.getListGStruct()); 684 } 685 686 /** 687 * Creates a new #GQueue. 688 * 689 * Returns: a newly allocated #GQueue 690 * 691 * Throws: ConstructionException GTK+ fails to create the object. 692 */ 693 public this() 694 { 695 auto p = g_queue_new(); 696 697 if(p is null) 698 { 699 throw new ConstructionException("null returned by new"); 700 } 701 702 this(cast(GQueue*) p); 703 } 704 }