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-Doubly-Linked-Lists.html
27  * outPack = glib
28  * outFile = ListG
29  * strct   = GList
30  * realStrct=
31  * ctorStrct=
32  * clss    = ListG
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_list_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * 	- GList* -> ListG
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module glib.ListG;
54 
55 public  import gtkc.glibtypes;
56 
57 private import gtkc.glib;
58 private import glib.ConstructionException;
59 
60 
61 
62 
63 
64 
65 /**
66  * Description
67  * The GList structure and its associated functions provide a standard
68  * doubly-linked list data structure.
69  * Each element in the list contains a piece of data, together with
70  * pointers which link to the previous and next elements in the list.
71  * Using these pointers it is possible to move through the list in both
72  * directions (unlike the Singly-Linked Lists which
73  * only allows movement through the list in the forward direction).
74  * The data contained in each element can be either integer values, by
75  * using one of the Type
76  * Conversion Macros, or simply pointers to any type of data.
77  * List elements are allocated from the slice allocator, which is more
78  * efficient than allocating elements individually.
79  * Note that most of the GList functions expect to be passed a pointer
80  * to the first element in the list. The functions which insert
81  * elements return the new start of the list, which may have changed.
82  * There is no function to create a GList. NULL is considered to be
83  * the empty list so you simply set a GList* to NULL.
84  * To add elements, use g_list_append(), g_list_prepend(),
85  * g_list_insert() and g_list_insert_sorted().
86  * To remove elements, use g_list_remove().
87  * To find elements in the list use g_list_first(), g_list_last(),
88  * g_list_next(), g_list_previous(), g_list_nth(), g_list_nth_data(),
89  * g_list_find() and g_list_find_custom().
90  * To find the index of an element use g_list_position() and
91  * g_list_index().
92  * To call a function for each element in the list use g_list_foreach().
93  * To free the entire list, use g_list_free().
94  */
95 public class ListG
96 {
97 	
98 	/** the main Gtk struct */
99 	protected GList* gList;
100 	
101 	
102 	public GList* getListGStruct()
103 	{
104 		return gList;
105 	}
106 	
107 	
108 	/** the main Gtk struct as a void* */
109 	protected void* getStruct()
110 	{
111 		return cast(void*)gList;
112 	}
113 	
114 	/**
115 	 * Sets our main struct and passes it to the parent class
116 	 */
117 	public this (GList* gList)
118 	{
119 		this.gList = gList;
120 	}
121 	
122 	/** */
123 	void* data()
124 	{
125 		return gList.data;
126 	}
127 	
128 	/**
129 	 * get the next element
130 	 * Returns: the next element, or NULL if there are no more elements.
131 	 */
132 	ListG next()
133 	{
134 		if ( gList.next is null )
135 		{
136 			return null;
137 		}
138 		
139 		return new ListG(gList.next);
140 	}
141 	
142 	/**
143 	 * get the previous element
144 	 * Returns: the previous element, or NULL if there are no more elements.
145 	 */
146 	ListG previous()
147 	{
148 		if ( gList.prev is null )
149 		{
150 			return null;
151 		}
152 		
153 		return new ListG(gList.prev);
154 	}
155 	
156 	/**
157 	 */
158 	
159 	/**
160 	 * Adds a new element on to the end of the list.
161 	 * Note
162 	 * The return value is the new start of the list, which
163 	 * may have changed, so make sure you store the new value.
164 	 * Note
165 	 * Note that g_list_append() has to traverse the entire list
166 	 * to find the end, which is inefficient when adding multiple
167 	 * elements. A common idiom to avoid the inefficiency is to prepend
168 	 * the elements and reverse the list when all elements have been added.
169 	 * $(DDOC_COMMENT example)
170 	 * Params:
171 	 * data = the data for the new element
172 	 * Returns: the new start of the GList
173 	 */
174 	public ListG append(void* data)
175 	{
176 		// GList * g_list_append (GList *list,  gpointer data);
177 		auto p = g_list_append(gList, data);
178 		
179 		if(p is null)
180 		{
181 			return null;
182 		}
183 		
184 		return new ListG(cast(GList*) p);
185 	}
186 	
187 	/**
188 	 * Adds a new element on to the start of the list.
189 	 * Note
190 	 * The return value is the new start of the list, which
191 	 * may have changed, so make sure you store the new value.
192 	 * $(DDOC_COMMENT example)
193 	 * Params:
194 	 * data = the data for the new element
195 	 * Returns: the new start of the GList
196 	 */
197 	public ListG prepend(void* data)
198 	{
199 		// GList * g_list_prepend (GList *list,  gpointer data);
200 		auto p = g_list_prepend(gList, data);
201 		
202 		if(p is null)
203 		{
204 			return null;
205 		}
206 		
207 		return new ListG(cast(GList*) p);
208 	}
209 	
210 	/**
211 	 * Inserts a new element into the list at the given position.
212 	 * Params:
213 	 * data = the data for the new element
214 	 * position = the position to insert the element. If this is
215 	 * negative, or is larger than the number of elements in the
216 	 * list, the new element is added on to the end of the list.
217 	 * Returns: the new start of the GList
218 	 */
219 	public ListG insert(void* data, int position)
220 	{
221 		// GList * g_list_insert (GList *list,  gpointer data,  gint position);
222 		auto p = g_list_insert(gList, data, position);
223 		
224 		if(p is null)
225 		{
226 			return null;
227 		}
228 		
229 		return new ListG(cast(GList*) p);
230 	}
231 	
232 	/**
233 	 * Inserts a new element into the list before the given position.
234 	 * Params:
235 	 * sibling = the list element before which the new element
236 	 * is inserted or NULL to insert at the end of the list
237 	 * data = the data for the new element
238 	 * Returns: the new start of the GList
239 	 */
240 	public ListG insertBefore(ListG sibling, void* data)
241 	{
242 		// GList * g_list_insert_before (GList *list,  GList *sibling,  gpointer data);
243 		auto p = g_list_insert_before(gList, (sibling is null) ? null : sibling.getListGStruct(), data);
244 		
245 		if(p is null)
246 		{
247 			return null;
248 		}
249 		
250 		return new ListG(cast(GList*) p);
251 	}
252 	
253 	/**
254 	 * Inserts a new element into the list, using the given comparison
255 	 * function to determine its position.
256 	 * Params:
257 	 * data = the data for the new element
258 	 * func = the function to compare elements in the list. It should
259 	 * return a number > 0 if the first parameter comes after the
260 	 * second parameter in the sort order.
261 	 * Returns: the new start of the GList
262 	 */
263 	public ListG insertSorted(void* data, GCompareFunc func)
264 	{
265 		// GList * g_list_insert_sorted (GList *list,  gpointer data,  GCompareFunc func);
266 		auto p = g_list_insert_sorted(gList, 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 	 * Removes an element from a GList.
278 	 * If two elements contain the same data, only the first is removed.
279 	 * If none of the elements contain the data, the GList is unchanged.
280 	 * Params:
281 	 * data = the data of the element to remove
282 	 * Returns: the new start of the GList
283 	 */
284 	public ListG remove(void* data)
285 	{
286 		// GList * g_list_remove (GList *list,  gconstpointer data);
287 		auto p = g_list_remove(gList, data);
288 		
289 		if(p is null)
290 		{
291 			return null;
292 		}
293 		
294 		return new ListG(cast(GList*) p);
295 	}
296 	
297 	/**
298 	 * Removes an element from a GList, without freeing the element.
299 	 * The removed element's prev and next links are set to NULL, so
300 	 * that it becomes a self-contained list with one element.
301 	 * Params:
302 	 * llink = an element in the GList
303 	 * Returns: the new start of the GList, without the element
304 	 */
305 	public ListG removeLink(ListG llink)
306 	{
307 		// GList * g_list_remove_link (GList *list,  GList *llink);
308 		auto p = g_list_remove_link(gList, (llink is null) ? null : llink.getListGStruct());
309 		
310 		if(p is null)
311 		{
312 			return null;
313 		}
314 		
315 		return new ListG(cast(GList*) p);
316 	}
317 	
318 	/**
319 	 * Removes the node link_ from the list and frees it.
320 	 * Compare this to g_list_remove_link() which removes the node
321 	 * without freeing it.
322 	 * Params:
323 	 * link = node to delete from list
324 	 * Returns: the new head of list
325 	 */
326 	public ListG deleteLink(ListG link)
327 	{
328 		// GList * g_list_delete_link (GList *list,  GList *link_);
329 		auto p = g_list_delete_link(gList, (link is null) ? null : link.getListGStruct());
330 		
331 		if(p is null)
332 		{
333 			return null;
334 		}
335 		
336 		return new ListG(cast(GList*) p);
337 	}
338 	
339 	/**
340 	 * Removes all list nodes with data equal to data.
341 	 * Returns the new head of the list. Contrast with
342 	 * g_list_remove() which removes only the first node
343 	 * matching the given data.
344 	 * Params:
345 	 * data = data to remove
346 	 * Returns: new head of list
347 	 */
348 	public ListG removeAll(void* data)
349 	{
350 		// GList * g_list_remove_all (GList *list,  gconstpointer data);
351 		auto p = g_list_remove_all(gList, data);
352 		
353 		if(p is null)
354 		{
355 			return null;
356 		}
357 		
358 		return new ListG(cast(GList*) p);
359 	}
360 	
361 	/**
362 	 * Frees all of the memory used by a GList.
363 	 * The freed elements are returned to the slice allocator.
364 	 * Note
365 	 * If list elements contain dynamically-allocated memory,
366 	 * you should either use g_list_free_full() or free them manually
367 	 * first.
368 	 */
369 	public void free()
370 	{
371 		// void g_list_free (GList *list);
372 		g_list_free(gList);
373 	}
374 	
375 	/**
376 	 * Convenience method, which frees all the memory used by a GList, and
377 	 * calls the specified destroy function on every element's data.
378 	 * Since 2.28
379 	 * Params:
380 	 * freeFunc = the function to be called to free each element's data
381 	 */
382 	public void freeFull(GDestroyNotify freeFunc)
383 	{
384 		// void g_list_free_full (GList *list,  GDestroyNotify free_func);
385 		g_list_free_full(gList, freeFunc);
386 	}
387 	
388 	/**
389 	 * Allocates space for one GList element. It is called by
390 	 * g_list_append(), g_list_prepend(), g_list_insert() and
391 	 * g_list_insert_sorted() and so is rarely used on its own.
392 	 * Returns: a pointer to the newly-allocated GList element.
393 	 */
394 	public static ListG alloc()
395 	{
396 		// GList * g_list_alloc (void);
397 		auto p = g_list_alloc();
398 		
399 		if(p is null)
400 		{
401 			return null;
402 		}
403 		
404 		return new ListG(cast(GList*) p);
405 	}
406 	
407 	/**
408 	 * Frees one GList element.
409 	 * It is usually used after g_list_remove_link().
410 	 */
411 	public void free1()
412 	{
413 		// void g_list_free_1 (GList *list);
414 		g_list_free_1(gList);
415 	}
416 	
417 	/**
418 	 * Gets the number of elements in a GList.
419 	 * Note
420 	 * This function iterates over the whole list to
421 	 * count its elements.
422 	 * Returns: the number of elements in the GList
423 	 */
424 	public uint length()
425 	{
426 		// guint g_list_length (GList *list);
427 		return g_list_length(gList);
428 	}
429 	
430 	/**
431 	 * Copies a GList.
432 	 * Note
433 	 * Note that this is a "shallow" copy. If the list elements
434 	 * consist of pointers to data, the pointers are copied but
435 	 * the actual data is not.
436 	 * Returns: a copy of list
437 	 */
438 	public ListG copy()
439 	{
440 		// GList * g_list_copy (GList *list);
441 		auto p = g_list_copy(gList);
442 		
443 		if(p is null)
444 		{
445 			return null;
446 		}
447 		
448 		return new ListG(cast(GList*) p);
449 	}
450 	
451 	/**
452 	 * Reverses a GList.
453 	 * It simply switches the next and prev pointers of each element.
454 	 * Returns: the start of the reversed GList
455 	 */
456 	public ListG reverse()
457 	{
458 		// GList * g_list_reverse (GList *list);
459 		auto p = g_list_reverse(gList);
460 		
461 		if(p is null)
462 		{
463 			return null;
464 		}
465 		
466 		return new ListG(cast(GList*) p);
467 	}
468 	
469 	/**
470 	 * Sorts a GList using the given comparison function.
471 	 * Params:
472 	 * compareFunc = the comparison function used to sort the GList.
473 	 * This function is passed the data from 2 elements of the GList
474 	 * and should return 0 if they are equal, a negative value if the
475 	 * first element comes before the second, or a positive value if
476 	 * the first element comes after the second.
477 	 * Returns: the start of the sorted GList
478 	 */
479 	public ListG sort(GCompareFunc compareFunc)
480 	{
481 		// GList * g_list_sort (GList *list,  GCompareFunc compare_func);
482 		auto p = g_list_sort(gList, compareFunc);
483 		
484 		if(p is null)
485 		{
486 			return null;
487 		}
488 		
489 		return new ListG(cast(GList*) p);
490 	}
491 	
492 	/**
493 	 * Inserts a new element into the list, using the given comparison
494 	 * function to determine its position.
495 	 * Since 2.10
496 	 * Params:
497 	 * data = the data for the new element
498 	 * func = the function to compare elements in the list.
499 	 * It should return a number > 0 if the first parameter
500 	 * comes after the second parameter in the sort order.
501 	 * userData = user data to pass to comparison function.
502 	 * Returns: the new start of the GList
503 	 */
504 	public ListG insertSortedWithData(void* data, GCompareDataFunc func, void* userData)
505 	{
506 		// GList * g_list_insert_sorted_with_data (GList *list,  gpointer data,  GCompareDataFunc func,  gpointer user_data);
507 		auto p = g_list_insert_sorted_with_data(gList, data, func, userData);
508 		
509 		if(p is null)
510 		{
511 			return null;
512 		}
513 		
514 		return new ListG(cast(GList*) p);
515 	}
516 	
517 	/**
518 	 * Like g_list_sort(), but the comparison function accepts
519 	 * a user data argument.
520 	 * Params:
521 	 * compareFunc = comparison function
522 	 * userData = user data to pass to comparison function
523 	 * Returns: the new head of list
524 	 */
525 	public ListG sortWithData(GCompareDataFunc compareFunc, void* userData)
526 	{
527 		// GList * g_list_sort_with_data (GList *list,  GCompareDataFunc compare_func,  gpointer user_data);
528 		auto p = g_list_sort_with_data(gList, compareFunc, userData);
529 		
530 		if(p is null)
531 		{
532 			return null;
533 		}
534 		
535 		return new ListG(cast(GList*) p);
536 	}
537 	
538 	/**
539 	 * Adds the second GList onto the end of the first GList.
540 	 * Note that the elements of the second GList are not copied.
541 	 * They are used directly.
542 	 * Params:
543 	 * list2 = the GList to add to the end of the first GList
544 	 * Returns: the start of the new GList
545 	 */
546 	public ListG concat(ListG list2)
547 	{
548 		// GList * g_list_concat (GList *list1,  GList *list2);
549 		auto p = g_list_concat(gList, (list2 is null) ? null : list2.getListGStruct());
550 		
551 		if(p is null)
552 		{
553 			return null;
554 		}
555 		
556 		return new ListG(cast(GList*) p);
557 	}
558 	
559 	/**
560 	 * Calls a function for each element of a GList.
561 	 * Params:
562 	 * func = the function to call with each element's data
563 	 * userData = user data to pass to the function
564 	 */
565 	public void foreac(GFunc func, void* userData)
566 	{
567 		// void g_list_foreach (GList *list,  GFunc func,  gpointer user_data);
568 		g_list_foreach(gList, func, userData);
569 	}
570 	
571 	/**
572 	 * Gets the first element in a GList.
573 	 * Returns: the first element in the GList, or NULL if the GList has no elements
574 	 */
575 	public ListG first()
576 	{
577 		// GList * g_list_first (GList *list);
578 		auto p = g_list_first(gList);
579 		
580 		if(p is null)
581 		{
582 			return null;
583 		}
584 		
585 		return new ListG(cast(GList*) p);
586 	}
587 	
588 	/**
589 	 * Gets the last element in a GList.
590 	 * Returns: the last element in the GList, or NULL if the GList has no elements
591 	 */
592 	public ListG last()
593 	{
594 		// GList * g_list_last (GList *list);
595 		auto p = g_list_last(gList);
596 		
597 		if(p is null)
598 		{
599 			return null;
600 		}
601 		
602 		return new ListG(cast(GList*) p);
603 	}
604 	
605 	/**
606 	 * Gets the element at the given position in a GList.
607 	 * Params:
608 	 * n = the position of the element, counting from 0
609 	 * Returns: the element, or NULL if the position is off the end of the GList
610 	 */
611 	public ListG nth(uint n)
612 	{
613 		// GList * g_list_nth (GList *list,  guint n);
614 		auto p = g_list_nth(gList, n);
615 		
616 		if(p is null)
617 		{
618 			return null;
619 		}
620 		
621 		return new ListG(cast(GList*) p);
622 	}
623 	
624 	/**
625 	 * Gets the data of the element at the given position.
626 	 * Params:
627 	 * n = the position of the element
628 	 * Returns: the element's data, or NULL if the position is off the end of the GList
629 	 */
630 	public void* nthData(uint n)
631 	{
632 		// gpointer g_list_nth_data (GList *list,  guint n);
633 		return g_list_nth_data(gList, n);
634 	}
635 	
636 	/**
637 	 * Gets the element n places before list.
638 	 * Params:
639 	 * n = the position of the element, counting from 0
640 	 * Returns: the element, or NULL if the position is off the end of the GList
641 	 */
642 	public ListG nthPrev(uint n)
643 	{
644 		// GList * g_list_nth_prev (GList *list,  guint n);
645 		auto p = g_list_nth_prev(gList, n);
646 		
647 		if(p is null)
648 		{
649 			return null;
650 		}
651 		
652 		return new ListG(cast(GList*) p);
653 	}
654 	
655 	/**
656 	 * Finds the element in a GList which
657 	 * contains the given data.
658 	 * Params:
659 	 * data = the element data to find
660 	 * Returns: the found GList element, or NULL if it is not found
661 	 */
662 	public ListG find(void* data)
663 	{
664 		// GList * g_list_find (GList *list,  gconstpointer data);
665 		auto p = g_list_find(gList, data);
666 		
667 		if(p is null)
668 		{
669 			return null;
670 		}
671 		
672 		return new ListG(cast(GList*) p);
673 	}
674 	
675 	/**
676 	 * Finds an element in a GList, using a supplied function to
677 	 * find the desired element. It iterates over the list, calling
678 	 * the given function which should return 0 when the desired
679 	 * element is found. The function takes two gconstpointer arguments,
680 	 * the GList element's data as the first argument and the
681 	 * given user data.
682 	 * Params:
683 	 * data = user data passed to the function
684 	 * func = the function to call for each element.
685 	 * It should return 0 when the desired element is found
686 	 * Returns: the found GList element, or NULL if it is not found
687 	 */
688 	public ListG findCustom(void* data, GCompareFunc func)
689 	{
690 		// GList * g_list_find_custom (GList *list,  gconstpointer data,  GCompareFunc func);
691 		auto p = g_list_find_custom(gList, data, func);
692 		
693 		if(p is null)
694 		{
695 			return null;
696 		}
697 		
698 		return new ListG(cast(GList*) p);
699 	}
700 	
701 	/**
702 	 * Gets the position of the given element
703 	 * in the GList (starting from 0).
704 	 * Params:
705 	 * llink = an element in the GList
706 	 * Returns: the position of the element in the GList, or -1 if the element is not found
707 	 */
708 	public int position(ListG llink)
709 	{
710 		// gint g_list_position (GList *list,  GList *llink);
711 		return g_list_position(gList, (llink is null) ? null : llink.getListGStruct());
712 	}
713 	
714 	/**
715 	 * Gets the position of the element containing
716 	 * the given data (starting from 0).
717 	 * Params:
718 	 * data = the data to find
719 	 * Returns: the index of the element containing the data, or -1 if the data is not found
720 	 */
721 	public int index(void* data)
722 	{
723 		// gint g_list_index (GList *list,  gconstpointer data);
724 		return g_list_index(gList, data);
725 	}
726 	
727 	/**
728 	 * Warning
729 	 * g_list_push_allocator has been deprecated since version 2.10 and should not be used in newly-written code. It does nothing, since GList has been converted
730 	 *  to the slice
731 	 *  allocator
732 	 * Sets the allocator to use to allocate GList elements. Use
733 	 * g_list_pop_allocator() to restore the previous allocator.
734 	 * Note that this function is not available if GLib has been compiled
735 	 * with --disable-mem-pools
736 	 * Params:
737 	 * allocator = the GAllocator to use when allocating GList elements.
738 	 */
739 	public static void pushAllocator(void* allocator)
740 	{
741 		// void g_list_push_allocator (gpointer allocator);
742 		g_list_push_allocator(allocator);
743 	}
744 	
745 	/**
746 	 * Warning
747 	 * g_list_pop_allocator has been deprecated since version 2.10 and should not be used in newly-written code. It does nothing, since GList has been converted
748 	 *  to the slice
749 	 *  allocator
750 	 * Restores the previous GAllocator, used when allocating GList
751 	 * elements.
752 	 * Note that this function is not available if GLib has been compiled
753 	 * with --disable-mem-pools
754 	 */
755 	public static void popAllocator()
756 	{
757 		// void g_list_pop_allocator (void);
758 		g_list_pop_allocator();
759 	}
760 }