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