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