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