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