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