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