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