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