alternative to assert
[gtkD.git] / src / glib / ListSG.d
blob68ae04a45ab71f5b4b4d3e4135328eef85691c0a
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Singly-Linked-Lists.html
26 * outPack = glib
27 * outFile = ListSG
28 * strct = GSList
29 * realStrct=
30 * ctorStrct=
31 * clss = ListSG
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_slist_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.ListG
45 * structWrap:
46 * - GSList* -> ListSG
47 * local aliases:
50 module glib.ListSG;
52 private import glib.glibtypes;
54 private import lib.glib;
56 private import glib.ListG;
58 /**
59 * Description
60 * The GSList structure and its associated functions provide a standard
61 * singly-linked list data structure.
62 * Each element in the list contains a piece of data, together with a pointer
63 * which links to the next element in the list.
64 * Using this pointer it is possible to move through the list in one
65 * direction only (unlike the
66 * Doubly-Linked Lists
67 * which allow movement in both directions).
68 * The data contained in each element can be either integer values, by using one
69 * of the
70 * Type Conversion Macros,
71 * or simply pointers to any type of data.
72 * List elements are allocated from the slice
73 * allocator, which is more efficient than allocating elements
74 * individually.
75 * Note that most of the GSList functions expect to be passed a pointer to
76 * the first element in the list. The functions which insert elements return
77 * the new start of the list, which may have changed.
78 * There is no function to create a GSList. NULL is considered to be the empty
79 * list so you simply set a GSList* to NULL.
80 * To add elements, use g_slist_append(), g_slist_prepend(), g_slist_insert()
81 * and g_slist_insert_sorted().
82 * To remove elements, use g_slist_remove().
83 * To find elements in the list use g_slist_last(), g_slist_next(),
84 * g_slist_nth(), g_slist_nth_data(), g_slist_find() and
85 * g_slist_find_custom().
86 * To find the index of an element use g_slist_position() and g_slist_index().
87 * To call a function for each element in the list use g_slist_foreach().
88 * To free the entire list, use g_slist_free().
90 public class ListSG
93 /** the main Gtk struct */
94 protected GSList* gSList;
97 public GSList* getListSGStruct()
99 return gSList;
103 /** the main Gtk struct as a void* */
104 protected void* getStruct()
106 return cast(void*)gSList;
110 * Sets our main struct and passes it to the parent class
112 public this (GSList* gSList)
114 this.gSList = gSList;
122 * Allocates space for one GSList element.
123 * It is called by the g_slist_append(), g_slist_prepend(), g_slist_insert() and
124 * g_slist_insert_sorted() functions and so is rarely used on its own.
125 * Returns:
126 * a pointer to the newly-allocated GSList element.
128 public static ListSG alloc()
130 // GSList* g_slist_alloc (void);
131 return new ListSG( g_slist_alloc() );
135 * Adds a new element on to the end of the list.
136 * Note
137 * The return value is the new start of the list, which may have changed, so
138 * make sure you store the new value.
139 * Note
140 * Note that g_slist_append() has to traverse the entire list to find the end,
141 * which is inefficient when adding multiple elements. A common idiom to
142 * avoid the inefficiency is to prepend the elements and reverse the list
143 * when all elements have been added.
144 * /+* Notice that these are initialized to the empty list. +/
145 * GSList *list = NULL, *number_list = NULL;
146 * /+* This is a list of strings. +/
147 * list = g_slist_append (list, "first");
148 * list = g_slist_append (list, "second");
149 * /+* This is a list of integers. +/
150 * number_list = g_slist_append (number_list, GINT_TO_POINTER (27));
151 * number_list = g_slist_append (number_list, GINT_TO_POINTER (14));
152 * list:
153 * a GSList.
154 * data:
155 * the data for the new element.
156 * Returns:
157 * the new start of the GSList.
159 public ListSG append(void* data)
161 // GSList* g_slist_append (GSList *list, gpointer data);
162 return new ListSG( g_slist_append(gSList, data) );
166 * Adds a new element on to the start of the list.
167 * Note
168 * The return value is the new start of the list, which may have changed, so
169 * make sure you store the new value.
170 * /+* Notice that it is initialized to the empty list. +/
171 * GSList *list = NULL;
172 * list = g_slist_prepend (list, "last");
173 * list = g_slist_prepend (list, "first");
174 * list:
175 * a GSList.
176 * data:
177 * the data for the new element.
178 * Returns:
179 * the new start of the GSList.
181 public ListSG prepend(void* data)
183 // GSList* g_slist_prepend (GSList *list, gpointer data);
184 return new ListSG( g_slist_prepend(gSList, data) );
188 * Inserts a new element into the list at the given position.
189 * list:
190 * a GSList.
191 * data:
192 * the data for the new element.
193 * position:
194 * the position to insert the element. If this is negative, or is
195 * larger than the number of elements in the list, the new element is added on
196 * to the end of the list.
197 * Returns:
198 * the new start of the GSList.
200 public ListSG insert(void* data, int position)
202 // GSList* g_slist_insert (GSList *list, gpointer data, gint position);
203 return new ListSG( g_slist_insert(gSList, data, position) );
207 * Inserts a node before sibling containing data. Returns the new head of the list.
208 * slist:
209 * a GSList.
210 * sibling:
211 * node to insert data before.
212 * data:
213 * data to put in the newly-inserted node.
214 * Returns:
215 * new head of the list.
217 public ListSG insertBefore(ListSG sibling, void* data)
219 // GSList* g_slist_insert_before (GSList *slist, GSList *sibling, gpointer data);
220 return new ListSG( g_slist_insert_before(gSList, (sibling is null) ? null : sibling.getListSGStruct(), data) );
224 * Inserts a new element into the list, using the given comparison function
225 * to determine its position.
226 * list:
227 * a GSList.
228 * data:
229 * the data for the new element.
230 * func:
231 * the function to compare elements in the list. It should return a
232 * number > 0 if the first parameter comes after the second parameter in
233 * the sort order.
234 * Returns:
235 * the new start of the GSList.
237 public ListSG insertSorted(void* data, GCompareFunc func)
239 // GSList* g_slist_insert_sorted (GSList *list, gpointer data, GCompareFunc func);
240 return new ListSG( g_slist_insert_sorted(gSList, data, func) );
244 * Removes an element from a GSList.
245 * If two elements contain the same data, only the first is removed.
246 * If none of the elements contain the data, the GSList is unchanged.
247 * list:
248 * a GSList.
249 * data:
250 * the data of the element to remove.
251 * Returns:
252 * the new start of the GSList.
254 public ListSG remove(void* data)
256 // GSList* g_slist_remove (GSList *list, gconstpointer data);
257 return new ListSG( g_slist_remove(gSList, data) );
261 * Removes an element from a GSList, without freeing the element.
262 * The removed element's next link is set to NULL, so that it becomes a
263 * self-contained list with one element.
264 * list:
265 * a GSList.
266 * link_:
267 * an element in the GSList.
268 * Returns:
269 * the new start of the GSList, without the element.
271 public ListSG removeLink(ListSG link)
273 // GSList* g_slist_remove_link (GSList *list, GSList *link_);
274 return new ListSG( g_slist_remove_link(gSList, (link is null) ? null : link.getListSGStruct()) );
278 * Deletes a node of list. Returns the new list head.
279 * list:
280 * a GSList.
281 * link_:
282 * node to delete.
283 * Returns:
284 * new head of list.
286 public ListSG deleteLink(ListSG link)
288 // GSList* g_slist_delete_link (GSList *list, GSList *link_);
289 return new ListSG( g_slist_delete_link(gSList, (link is null) ? null : link.getListSGStruct()) );
293 * Removes all list nodes with data equal to data. Returns the new
294 * head of the list. Contrast with g_slist_remove() which removes only
295 * the first node matching the given data.
296 * list:
297 * a GSList.
298 * data:
299 * data to remove.
300 * Returns:
301 * new head of list.
303 public ListSG removeAll(void* data)
305 // GSList* g_slist_remove_all (GSList *list, gconstpointer data);
306 return new ListSG( g_slist_remove_all(gSList, data) );
310 * Frees all of the memory used by a GSList.
311 * The freed elements are returned to the slice allocator.
312 * list:
313 * a GSList.
315 public void free()
317 // void g_slist_free (GSList *list);
318 g_slist_free(gSList);
322 * Frees one GSList element.
323 * It is usually used after g_slist_remove_link().
324 * list:
325 * a GSList element.
327 public void free1()
329 // void g_slist_free_1 (GSList *list);
330 g_slist_free_1(gSList);
335 * Gets the number of elements in a GSList.
336 * list:
337 * a GSList.
338 * Returns:
339 * the number of elements in the GSList.
341 public uint length()
343 // guint g_slist_length (GSList *list);
344 return g_slist_length(gSList);
348 * Copies a GSList.
349 * Note that this is a "shallow" copy. If the list elements consist of pointers
350 * to data, the pointers are copied but the actual data isn't.
351 * list:
352 * a GSList.
353 * Returns:
354 * a copy of list.
356 public ListSG copy()
358 // GSList* g_slist_copy (GSList *list);
359 return new ListSG( g_slist_copy(gSList) );
363 * Reverses a GSList.
364 * list:
365 * a GSList.
366 * Returns:
367 * the start of the reversed GSList.
369 public ListSG reverse()
371 // GSList* g_slist_reverse (GSList *list);
372 return new ListSG( g_slist_reverse(gSList) );
376 * Inserts a new element into the list, using the given comparison function
377 * to determine its position.
378 * list:
379 * a GSList.
380 * data:
381 * the data for the new element.
382 * func:
383 * the function to compare elements in the list. It should return a
384 * number > 0 if the first parameter comes after the second parameter in
385 * the sort order.
386 * user_data:
387 * data to pass to comparison function.
388 * Returns:
389 * the new start of the GSList.
390 * Since 2.10
392 public ListSG insertSortedWithData(void* data, GCompareDataFunc func, void* userData)
394 // GSList* g_slist_insert_sorted_with_data (GSList *list, gpointer data, GCompareDataFunc func, gpointer user_data);
395 return new ListSG( g_slist_insert_sorted_with_data(gSList, data, func, userData) );
399 * Sorts a GSList using the given comparison function.
400 * list:
401 * a GSList.
402 * compare_func:
403 * the comparison function used to sort the GSList.
404 * This function is passed the data from 2 elements of the GSList and should
405 * return 0 if they are equal, a negative value if the first element
406 * comes before the second, or a positive value if the first element
407 * comes after the second.
408 * Returns:
409 * the start of the sorted GSList.
411 public ListSG sort(GCompareFunc compareFunc)
413 // GSList* g_slist_sort (GSList *list, GCompareFunc compare_func);
414 return new ListSG( g_slist_sort(gSList, compareFunc) );
418 * Like g_slist_sort(), but the sort function accepts a user data argument.
419 * list:
420 * a GSList
421 * compare_func:
422 * comparison function.
423 * user_data:
424 * data to pass to comparison function.
425 * Returns:
426 * new head of the list.
428 public ListSG sortWithData(GCompareDataFunc compareFunc, void* userData)
430 // GSList* g_slist_sort_with_data (GSList *list, GCompareDataFunc compare_func, gpointer user_data);
431 return new ListSG( g_slist_sort_with_data(gSList, compareFunc, userData) );
435 * Adds the second GSList onto the end of the first GSList.
436 * Note that the elements of the second GSList are not copied.
437 * They are used directly.
438 * list1:
439 * a GSList.
440 * list2:
441 * the GSList to add to the end of the first GSList.
442 * Returns:
443 * the start of the new GSList.
445 public ListSG concat(ListSG list2)
447 // GSList* g_slist_concat (GSList *list1, GSList *list2);
448 return new ListSG( g_slist_concat(gSList, (list2 is null) ? null : list2.getListSGStruct()) );
452 * Calls a function for each element of a GSList.
453 * list:
454 * a GSList.
455 * func:
456 * the function to call with each element's data.
457 * user_data:
458 * user data to pass to the function.
460 public void foreac(GFunc func, void* userData)
462 // void g_slist_foreach (GSList *list, GFunc func, gpointer user_data);
463 g_slist_foreach(gSList, func, userData);
467 * Gets the last element in a GSList.
468 * list:
469 * a GSList.
470 * Returns:
471 * the last element in the GSList, or NULL if the GSList has no
472 * elements.
474 public ListSG last()
476 // GSList* g_slist_last (GSList *list);
477 return new ListSG( g_slist_last(gSList) );
482 * Gets the element at the given position in a GSList.
483 * list:
484 * a GSList.
485 * n:
486 * the position of the element, counting from 0.
487 * Returns:
488 * the element, or NULL if the position is off the end of the GSList.
490 public ListSG nth(uint n)
492 // GSList* g_slist_nth (GSList *list, guint n);
493 return new ListSG( g_slist_nth(gSList, n) );
497 * Gets the data of the element at the given position.
498 * list:
499 * a GSList.
500 * n:
501 * the position of the element.
502 * Returns:
503 * the element's data, or NULL if the position is off the end of the
504 * GSList.
506 public void* nthData(uint n)
508 // gpointer g_slist_nth_data (GSList *list, guint n);
509 return g_slist_nth_data(gSList, n);
513 * Finds the element in a GSList which contains the given data.
514 * list:
515 * a GSList.
516 * data:
517 * the element data to find.
518 * Returns:
519 * the found GSList element, or NULL if it is not found.
521 public ListSG find(void* data)
523 // GSList* g_slist_find (GSList *list, gconstpointer data);
524 return new ListSG( g_slist_find(gSList, data) );
528 * Finds an element in a GSList, using a supplied function to find the desired
529 * element.
530 * It iterates over the list, calling the given function which should return 0
531 * when the desired element is found.
532 * The function takes two gconstpointer arguments, the GSList element's data as
533 * the first argument and the given user data.
534 * list:
535 * a GSList.
536 * data:
537 * user data passed to the function.
538 * func:
539 * the function to call for each element. It should return 0 when the
540 * desired element is found.
541 * Returns:
542 * the found GSList element, or NULL if it is not found.
544 public ListSG findCustom(void* data, GCompareFunc func)
546 // GSList* g_slist_find_custom (GSList *list, gconstpointer data, GCompareFunc func);
547 return new ListSG( g_slist_find_custom(gSList, data, func) );
551 * Gets the position of the given element in the GSList (starting from 0).
552 * list:
553 * a GSList.
554 * llink:
555 * an element in the GSList.
556 * Returns:
557 * the position of the element in the GSList, or -1 if the element
558 * is not found.
560 public int position(ListSG llink)
562 // gint g_slist_position (GSList *list, GSList *llink);
563 return g_slist_position(gSList, (llink is null) ? null : llink.getListSGStruct());
567 * Gets the position of the element containing the given data (starting from 0).
568 * list:
569 * a GSList.
570 * data:
571 * the data to find.
572 * Returns:
573 * the index of the element containing the data, or -1 if the data
574 * is not found.
576 public int index(void* data)
578 // gint g_slist_index (GSList *list, gconstpointer data);
579 return g_slist_index(gSList, data);
583 * Warning
584 * 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
585 * converted to the slice allocator
586 * Sets the allocator to use to allocate GSList elements.
587 * Use g_slist_pop_allocator() to restore the previous allocator.
588 * Note that this function is not available if GLib has been compiled
589 * with --disable-mem-pools
590 * dummy:
591 * the GAllocator to use when allocating GSList elements.
593 public static void pushAllocator(void* dummy)
595 // void g_slist_push_allocator (gpointer dummy);
596 g_slist_push_allocator(dummy);
600 * Warning
601 * 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
602 * converted to the slice allocator
603 * Restores the previous GAllocator, used when allocating GSList elements.
604 * Note that this function is not available if GLib has been compiled
605 * with --disable-mem-pools
607 public static void popAllocator()
609 // void g_slist_pop_allocator (void);
610 g_slist_pop_allocator();