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