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