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