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 @data into @queue before @sibling.
297 	 *
298 	 * @sibling must be part of @queue. Since GLib 2.44 a %NULL sibling pushes the
299 	 * data at the tail of the queue.
300 	 *
301 	 * Params:
302 	 *     sibling = a #GList link that must be part of @queue, or %NULL to
303 	 *         push at the tail of the queue.
304 	 *     data = the data to insert
305 	 *
306 	 * Since: 2.4
307 	 */
308 	public void insertBefore(ListG sibling, void* data)
309 	{
310 		g_queue_insert_before(gQueue, (sibling is null) ? null : sibling.getListGStruct(), data);
311 	}
312 
313 	/**
314 	 * Inserts @data into @queue using @func to determine the new position.
315 	 *
316 	 * Params:
317 	 *     data = the data to insert
318 	 *     func = the #GCompareDataFunc used to compare elements in the queue. It is
319 	 *         called with two elements of the @queue and @user_data. It should
320 	 *         return 0 if the elements are equal, a negative value if the first
321 	 *         element comes before the second, and a positive value if the second
322 	 *         element comes before the first.
323 	 *     userData = user data passed to @func
324 	 *
325 	 * Since: 2.4
326 	 */
327 	public void insertSorted(void* data, GCompareDataFunc func, void* userData)
328 	{
329 		g_queue_insert_sorted(gQueue, data, func, userData);
330 	}
331 
332 	/**
333 	 * Returns %TRUE if the queue is empty.
334 	 *
335 	 * Returns: %TRUE if the queue is empty
336 	 */
337 	public bool isEmpty()
338 	{
339 		return g_queue_is_empty(gQueue) != 0;
340 	}
341 
342 	/**
343 	 * Returns the position of @link_ in @queue.
344 	 *
345 	 * Params:
346 	 *     link = a #GList link
347 	 *
348 	 * Returns: the position of @link_, or -1 if the link is
349 	 *     not part of @queue
350 	 *
351 	 * Since: 2.4
352 	 */
353 	public int linkIndex(ListG link)
354 	{
355 		return g_queue_link_index(gQueue, (link is null) ? null : link.getListGStruct());
356 	}
357 
358 	/**
359 	 * Returns the first element of the queue.
360 	 *
361 	 * Returns: the data of the first element in the queue, or %NULL
362 	 *     if the queue is empty
363 	 */
364 	public void* peekHead()
365 	{
366 		return g_queue_peek_head(gQueue);
367 	}
368 
369 	/**
370 	 * Returns the first link in @queue.
371 	 *
372 	 * Returns: the first link in @queue, or %NULL if @queue is empty
373 	 *
374 	 * Since: 2.4
375 	 */
376 	public ListG peekHeadLink()
377 	{
378 		auto p = g_queue_peek_head_link(gQueue);
379 
380 		if(p is null)
381 		{
382 			return null;
383 		}
384 
385 		return new ListG(cast(GList*) p);
386 	}
387 
388 	/**
389 	 * Returns the @n'th element of @queue.
390 	 *
391 	 * Params:
392 	 *     n = the position of the element
393 	 *
394 	 * Returns: the data for the @n'th element of @queue,
395 	 *     or %NULL if @n is off the end of @queue
396 	 *
397 	 * Since: 2.4
398 	 */
399 	public void* peekNth(uint n)
400 	{
401 		return g_queue_peek_nth(gQueue, n);
402 	}
403 
404 	/**
405 	 * Returns the link at the given position
406 	 *
407 	 * Params:
408 	 *     n = the position of the link
409 	 *
410 	 * Returns: the link at the @n'th position, or %NULL
411 	 *     if @n is off the end of the list
412 	 *
413 	 * Since: 2.4
414 	 */
415 	public ListG peekNthLink(uint n)
416 	{
417 		auto p = g_queue_peek_nth_link(gQueue, n);
418 
419 		if(p is null)
420 		{
421 			return null;
422 		}
423 
424 		return new ListG(cast(GList*) p);
425 	}
426 
427 	/**
428 	 * Returns the last element of the queue.
429 	 *
430 	 * Returns: the data of the last element in the queue, or %NULL
431 	 *     if the queue is empty
432 	 */
433 	public void* peekTail()
434 	{
435 		return g_queue_peek_tail(gQueue);
436 	}
437 
438 	/**
439 	 * Returns the last link in @queue.
440 	 *
441 	 * Returns: the last link in @queue, or %NULL if @queue is empty
442 	 *
443 	 * Since: 2.4
444 	 */
445 	public ListG peekTailLink()
446 	{
447 		auto p = g_queue_peek_tail_link(gQueue);
448 
449 		if(p is null)
450 		{
451 			return null;
452 		}
453 
454 		return new ListG(cast(GList*) p);
455 	}
456 
457 	/**
458 	 * Removes the first element of the queue and returns its data.
459 	 *
460 	 * Returns: the data of the first element in the queue, or %NULL
461 	 *     if the queue is empty
462 	 */
463 	public void* popHead()
464 	{
465 		return g_queue_pop_head(gQueue);
466 	}
467 
468 	/**
469 	 * Removes and returns the first element of the queue.
470 	 *
471 	 * Returns: the #GList element at the head of the queue, or %NULL
472 	 *     if the queue is empty
473 	 */
474 	public ListG popHeadLink()
475 	{
476 		auto p = g_queue_pop_head_link(gQueue);
477 
478 		if(p is null)
479 		{
480 			return null;
481 		}
482 
483 		return new ListG(cast(GList*) p);
484 	}
485 
486 	/**
487 	 * Removes the @n'th element of @queue and returns its data.
488 	 *
489 	 * Params:
490 	 *     n = the position of the element
491 	 *
492 	 * Returns: the element's data, or %NULL if @n is off the end of @queue
493 	 *
494 	 * Since: 2.4
495 	 */
496 	public void* popNth(uint n)
497 	{
498 		return g_queue_pop_nth(gQueue, n);
499 	}
500 
501 	/**
502 	 * Removes and returns the link at the given position.
503 	 *
504 	 * Params:
505 	 *     n = the link's position
506 	 *
507 	 * Returns: the @n'th link, or %NULL if @n is off the end of @queue
508 	 *
509 	 * Since: 2.4
510 	 */
511 	public ListG popNthLink(uint n)
512 	{
513 		auto p = g_queue_pop_nth_link(gQueue, n);
514 
515 		if(p is null)
516 		{
517 			return null;
518 		}
519 
520 		return new ListG(cast(GList*) p);
521 	}
522 
523 	/**
524 	 * Removes the last element of the queue and returns its data.
525 	 *
526 	 * Returns: the data of the last element in the queue, or %NULL
527 	 *     if the queue is empty
528 	 */
529 	public void* popTail()
530 	{
531 		return g_queue_pop_tail(gQueue);
532 	}
533 
534 	/**
535 	 * Removes and returns the last element of the queue.
536 	 *
537 	 * Returns: the #GList element at the tail of the queue, or %NULL
538 	 *     if the queue is empty
539 	 */
540 	public ListG popTailLink()
541 	{
542 		auto p = g_queue_pop_tail_link(gQueue);
543 
544 		if(p is null)
545 		{
546 			return null;
547 		}
548 
549 		return new ListG(cast(GList*) p);
550 	}
551 
552 	/**
553 	 * Adds a new element at the head of the queue.
554 	 *
555 	 * Params:
556 	 *     data = the data for the new element.
557 	 */
558 	public void pushHead(void* data)
559 	{
560 		g_queue_push_head(gQueue, data);
561 	}
562 
563 	/**
564 	 * Adds a new element at the head of the queue.
565 	 *
566 	 * Params:
567 	 *     link = a single #GList element, not a list with more than one element
568 	 */
569 	public void pushHeadLink(ListG link)
570 	{
571 		g_queue_push_head_link(gQueue, (link is null) ? null : link.getListGStruct());
572 	}
573 
574 	/**
575 	 * Inserts a new element into @queue at the given position.
576 	 *
577 	 * Params:
578 	 *     data = the data for the new element
579 	 *     n = the position to insert the new element. If @n is negative or
580 	 *         larger than the number of elements in the @queue, the element is
581 	 *         added to the end of the queue.
582 	 *
583 	 * Since: 2.4
584 	 */
585 	public void pushNth(void* data, int n)
586 	{
587 		g_queue_push_nth(gQueue, data, n);
588 	}
589 
590 	/**
591 	 * Inserts @link into @queue at the given position.
592 	 *
593 	 * Params:
594 	 *     n = the position to insert the link. If this is negative or larger than
595 	 *         the number of elements in @queue, the link is added to the end of
596 	 *         @queue.
597 	 *     link = the link to add to @queue
598 	 *
599 	 * Since: 2.4
600 	 */
601 	public void pushNthLink(int n, ListG link)
602 	{
603 		g_queue_push_nth_link(gQueue, n, (link is null) ? null : link.getListGStruct());
604 	}
605 
606 	/**
607 	 * Adds a new element at the tail of the queue.
608 	 *
609 	 * Params:
610 	 *     data = the data for the new element
611 	 */
612 	public void pushTail(void* data)
613 	{
614 		g_queue_push_tail(gQueue, data);
615 	}
616 
617 	/**
618 	 * Adds a new element at the tail of the queue.
619 	 *
620 	 * Params:
621 	 *     link = a single #GList element, not a list with more than one element
622 	 */
623 	public void pushTailLink(ListG link)
624 	{
625 		g_queue_push_tail_link(gQueue, (link is null) ? null : link.getListGStruct());
626 	}
627 
628 	/**
629 	 * Removes the first element in @queue that contains @data.
630 	 *
631 	 * Params:
632 	 *     data = the data to remove
633 	 *
634 	 * Returns: %TRUE if @data was found and removed from @queue
635 	 *
636 	 * Since: 2.4
637 	 */
638 	public bool remove(void* data)
639 	{
640 		return g_queue_remove(gQueue, data) != 0;
641 	}
642 
643 	/**
644 	 * Remove all elements whose data equals @data from @queue.
645 	 *
646 	 * Params:
647 	 *     data = the data to remove
648 	 *
649 	 * Returns: the number of elements removed from @queue
650 	 *
651 	 * Since: 2.4
652 	 */
653 	public uint removeAll(void* data)
654 	{
655 		return g_queue_remove_all(gQueue, data);
656 	}
657 
658 	/**
659 	 * Reverses the order of the items in @queue.
660 	 *
661 	 * Since: 2.4
662 	 */
663 	public void reverse()
664 	{
665 		g_queue_reverse(gQueue);
666 	}
667 
668 	/**
669 	 * Sorts @queue using @compare_func.
670 	 *
671 	 * Params:
672 	 *     compareFunc = the #GCompareDataFunc used to sort @queue. This function
673 	 *         is passed two elements of the queue and should return 0 if they are
674 	 *         equal, a negative value if the first comes before the second, and
675 	 *         a positive value if the second comes before the first.
676 	 *     userData = user data passed to @compare_func
677 	 *
678 	 * Since: 2.4
679 	 */
680 	public void sort(GCompareDataFunc compareFunc, void* userData)
681 	{
682 		g_queue_sort(gQueue, compareFunc, userData);
683 	}
684 
685 	/**
686 	 * Unlinks @link_ so that it will no longer be part of @queue.
687 	 * The link is not freed.
688 	 *
689 	 * @link_ must be part of @queue.
690 	 *
691 	 * Params:
692 	 *     link = a #GList link that must be part of @queue
693 	 *
694 	 * Since: 2.4
695 	 */
696 	public void unlink(ListG link)
697 	{
698 		g_queue_unlink(gQueue, (link is null) ? null : link.getListGStruct());
699 	}
700 
701 	/**
702 	 * Creates a new #GQueue.
703 	 *
704 	 * Returns: a newly allocated #GQueue
705 	 *
706 	 * Throws: ConstructionException GTK+ fails to create the object.
707 	 */
708 	public this()
709 	{
710 		auto p = g_queue_new();
711 
712 		if(p is null)
713 		{
714 			throw new ConstructionException("null returned by new");
715 		}
716 
717 		this(cast(GQueue*) p);
718 	}
719 }