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