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