alternative to assert
[gtkD.git] / src / glib / ListG.d
blob5f20511b4a9485a429a43e0d8e12390708c26f18
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-Doubly-Linked-Lists.html
26 * outPack = glib
27 * outFile = ListG
28 * strct = GList
29 * realStrct=
30 * ctorStrct=
31 * clss = ListG
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_list_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * structWrap:
45 * - GList* -> ListG
46 * local aliases:
49 module glib.ListG;
51 private import glib.glibtypes;
53 private import lib.glib;
56 /**
57 * Description
58 * The GList structure and its associated functions provide a standard
59 * doubly-linked list data structure.
60 * Each element in the list contains a piece of data, together with pointers
61 * which link to the previous and next elements in the list.
62 * Using these pointers it is possible to move through the list in both
63 * directions (unlike the
64 * Singly-Linked Lists
65 * which only allows movement through the list in the forward direction).
66 * The data contained in each element can be either integer values, by using one
67 * of the
68 * Type Conversion Macros,
69 * or simply pointers to any type of data.
70 * List elements are allocated from the slice
71 * allocator, which is more efficient than allocating elements
72 * individually.
73 * Note that most of the GList functions expect to be passed a pointer to
74 * the first element in the list. The functions which insert elements return
75 * the new start of the list, which may have changed.
76 * There is no function to create a GList. NULL is considered to be the empty
77 * list so you simply set a GList* to NULL.
78 * To add elements, use g_list_append(), g_list_prepend(), g_list_insert()
79 * and g_list_insert_sorted().
80 * To remove elements, use g_list_remove().
81 * To find elements in the list use g_list_first(), g_list_last(), g_list_next(),
82 * g_list_previous(), g_list_nth(), g_list_nth_data(), g_list_find() and
83 * g_list_find_custom().
84 * To find the index of an element use g_list_position() and g_list_index().
85 * To call a function for each element in the list use g_list_foreach().
86 * To free the entire list, use g_list_free().
88 public class ListG
91 /** the main Gtk struct */
92 protected GList* gList;
95 public GList* getListGStruct()
97 return gList;
101 /** the main Gtk struct as a void* */
102 protected void* getStruct()
104 return cast(void*)gList;
108 * Sets our main struct and passes it to the parent class
110 public this (GList* gList)
112 this.gList = gList;
120 * Adds a new element on to the end of the list.
121 * Note
122 * The return value is the new start of the list, which may have changed, so
123 * make sure you store the new value.
124 * Note
125 * Note that g_list_append() has to traverse the entire list to find the end,
126 * which is inefficient when adding multiple elements. A common idiom to
127 * avoid the inefficiency is to prepend the elements and reverse the list
128 * when all elements have been added.
129 * /+* Notice that these are initialized to the empty list. +/
130 * GList *list = NULL, *number_list = NULL;
131 * /+* This is a list of strings. +/
132 * list = g_list_append (list, "first");
133 * list = g_list_append (list, "second");
134 * /+* This is a list of integers. +/
135 * number_list = g_list_append (number_list, GINT_TO_POINTER (27));
136 * number_list = g_list_append (number_list, GINT_TO_POINTER (14));
137 * list:
138 * a pointer to a GList.
139 * data:
140 * the data for the new element.
141 * Returns:
142 * the new start of the GList.
144 public ListG append(void* data)
146 // GList* g_list_append (GList *list, gpointer data);
147 return new ListG( g_list_append(gList, data) );
151 * Adds a new element on to the start of the list.
152 * Note
153 * The return value is the new start of the list, which may have changed, so
154 * make sure you store the new value.
155 * /+* Notice that it is initialized to the empty list. +/
156 * GList *list = NULL;
157 * list = g_list_prepend (list, "last");
158 * list = g_list_prepend (list, "first");
159 * list:
160 * a pointer to a GList.
161 * data:
162 * the data for the new element.
163 * Returns:
164 * the new start of the GList.
166 public ListG prepend(void* data)
168 // GList* g_list_prepend (GList *list, gpointer data);
169 return new ListG( g_list_prepend(gList, data) );
173 * Inserts a new element into the list at the given position.
174 * list:
175 * a pointer to a GList.
176 * data:
177 * the data for the new element.
178 * position:
179 * the position to insert the element. If this is negative, or is
180 * larger than the number of elements in the list, the new element is added on
181 * to the end of the list.
182 * Returns:
183 * the new start of the GList.
185 public ListG insert(void* data, int position)
187 // GList* g_list_insert (GList *list, gpointer data, gint position);
188 return new ListG( g_list_insert(gList, data, position) );
192 * Inserts a new element into the list before the given position.
193 * list:
194 * a pointer to a GList.
195 * sibling:
196 * the list element before which the new element is inserted
197 * or NULL to insert at the end of the list.
198 * data:
199 * the data for the new element.
200 * Returns:
201 * the new start of the GList.
203 public ListG insertBefore(ListG sibling, void* data)
205 // GList* g_list_insert_before (GList *list, GList *sibling, gpointer data);
206 return new ListG( g_list_insert_before(gList, (sibling is null) ? null : sibling.getListGStruct(), data) );
210 * Inserts a new element into the list, using the given comparison function
211 * to determine its position.
212 * list:
213 * a pointer to a GList.
214 * data:
215 * the data for the new element.
216 * func:
217 * the function to compare elements in the list. It should return a
218 * number > 0 if the first parameter comes after the second parameter in
219 * the sort order.
220 * Returns:
221 * the new start of the GList.
223 public ListG insertSorted(void* data, GCompareFunc func)
225 // GList* g_list_insert_sorted (GList *list, gpointer data, GCompareFunc func);
226 return new ListG( g_list_insert_sorted(gList, data, func) );
230 * Removes an element from a GList.
231 * If two elements contain the same data, only the first is removed.
232 * If none of the elements contain the data, the GList is unchanged.
233 * list:
234 * a GList.
235 * data:
236 * the data of the element to remove.
237 * Returns:
238 * the new start of the GList.
240 public ListG remove(void* data)
242 // GList* g_list_remove (GList *list, gconstpointer data);
243 return new ListG( g_list_remove(gList, data) );
247 * Removes an element from a GList, without freeing the element.
248 * The removed element's prev and next links are set to NULL, so that it becomes a
249 * self-contained list with one element.
250 * list:
251 * a GList.
252 * llink:
253 * an element in the GList.
254 * Returns:
255 * the new start of the GList, without the element.
257 public ListG removeLink(ListG llink)
259 // GList* g_list_remove_link (GList *list, GList *llink);
260 return new ListG( g_list_remove_link(gList, (llink is null) ? null : llink.getListGStruct()) );
264 * Deletes the node link_ from list.
265 * list:
266 * a GList.
267 * link_:
268 * node to delete from list.
269 * Returns:
270 * the new head of list.
272 public ListG deleteLink(ListG link)
274 // GList* g_list_delete_link (GList *list, GList *link_);
275 return new ListG( g_list_delete_link(gList, (link is null) ? null : link.getListGStruct()) );
279 * Removes all list nodes with data equal to data. Returns the new
280 * head of the list. Contrast with g_list_remove() which removes only
281 * the first node matching the given data.
282 * list:
283 * a GList.
284 * data:
285 * data to remove.
286 * Returns:
287 * new head of list.
289 public ListG removeAll(void* data)
291 // GList* g_list_remove_all (GList *list, gconstpointer data);
292 return new ListG( g_list_remove_all(gList, data) );
296 * Frees all of the memory used by a GList.
297 * The freed elements are returned to the slice allocator.
298 * Note
299 * If list elements contain dynamically-allocated memory, they should be freed
300 * first.
301 * list:
302 * a GList.
304 public void free()
306 // void g_list_free (GList *list);
307 g_list_free(gList);
311 * Allocates space for one GList element.
312 * It is called by g_list_append(), g_list_prepend(), g_list_insert() and
313 * g_list_insert_sorted() and so is rarely used on its own.
314 * Returns:
315 * a pointer to the newly-allocated GList element.
317 public static ListG alloc()
319 // GList* g_list_alloc (void);
320 return new ListG( g_list_alloc() );
324 * Frees one GList element.
325 * It is usually used after g_list_remove_link().
326 * list:
327 * a GList element.
329 public void free1()
331 // void g_list_free_1 (GList *list);
332 g_list_free_1(gList);
337 * Gets the number of elements in a GList.
338 * list:
339 * a GList.
340 * Returns:
341 * the number of elements in the GList.
343 public uint length()
345 // guint g_list_length (GList *list);
346 return g_list_length(gList);
350 * Copies a GList.
351 * Note that this is a "shallow" copy. If the list elements consist of pointers
352 * to data, the pointers are copied but the actual data isn't.
353 * list:
354 * a GList.
355 * Returns:
356 * a copy of list.
358 public ListG copy()
360 // GList* g_list_copy (GList *list);
361 return new ListG( g_list_copy(gList) );
365 * Reverses a GList.
366 * It simply switches the next and prev pointers of each element.
367 * list:
368 * a GList.
369 * Returns:
370 * the start of the reversed GList.
372 public ListG reverse()
374 // GList* g_list_reverse (GList *list);
375 return new ListG( g_list_reverse(gList) );
379 * Sorts a GList using the given comparison function.
380 * list:
381 * a GList.
382 * compare_func:
383 * the comparison function used to sort the GList.
384 * This function is passed the data from 2 elements of the GList and should
385 * return 0 if they are equal, a negative value if the first element
386 * comes before the second, or a positive value if the first element
387 * comes after the second.
388 * Returns:
389 * the start of the sorted GList.
391 public ListG sort(GCompareFunc compareFunc)
393 // GList* g_list_sort (GList *list, GCompareFunc compare_func);
394 return new ListG( g_list_sort(gList, compareFunc) );
399 * Inserts a new element into the list, using the given comparison function
400 * to determine its position.
401 * list:
402 * a pointer to a GList.
403 * data:
404 * the data for the new element.
405 * func:
406 * the function to compare elements in the list. It should return a
407 * number > 0 if the first parameter comes after the second parameter in
408 * the sort order.
409 * user_data:
410 * user data to pass to comparison function.
411 * Returns:
412 * the new start of the GList.
413 * Since 2.10
415 public ListG insertSortedWithData(void* data, GCompareDataFunc func, void* userData)
417 // GList* g_list_insert_sorted_with_data (GList *list, gpointer data, GCompareDataFunc func, gpointer user_data);
418 return new ListG( g_list_insert_sorted_with_data(gList, data, func, userData) );
422 * Like g_list_sort(), but the comparison function accepts a user data argument.
423 * list:
424 * a GList.
425 * compare_func:
426 * comparison function.
427 * user_data:
428 * user data to pass to comparison function.
429 * Returns:
430 * the new head of list.
432 public ListG sortWithData(GCompareDataFunc compareFunc, void* userData)
434 // GList* g_list_sort_with_data (GList *list, GCompareDataFunc compare_func, gpointer user_data);
435 return new ListG( g_list_sort_with_data(gList, compareFunc, userData) );
440 * Adds the second GList onto the end of the first GList.
441 * Note that the elements of the second GList are not copied.
442 * They are used directly.
443 * list1:
444 * a GList.
445 * list2:
446 * the GList to add to the end of the first GList.
447 * Returns:
448 * the start of the new GList.
450 public ListG concat(ListG list2)
452 // GList* g_list_concat (GList *list1, GList *list2);
453 return new ListG( g_list_concat(gList, (list2 is null) ? null : list2.getListGStruct()) );
457 * Calls a function for each element of a GList.
458 * list:
459 * a GList.
460 * func:
461 * the function to call with each element's data.
462 * user_data:
463 * user data to pass to the function.
465 public void foreac(GFunc func, void* userData)
467 // void g_list_foreach (GList *list, GFunc func, gpointer user_data);
468 g_list_foreach(gList, func, userData);
473 * Gets the first element in a GList.
474 * list:
475 * a GList.
476 * Returns:
477 * the first element in a GList, or NULL if the GList has no elements.
479 public ListG first()
481 // GList* g_list_first (GList *list);
482 return new ListG( g_list_first(gList) );
486 * Gets the last element in a GList.
487 * list:
488 * a GList.
489 * Returns:
490 * the last element in the GList, or NULL if the GList has no
491 * elements.
493 public ListG last()
495 // GList* g_list_last (GList *list);
496 return new ListG( g_list_last(gList) );
502 * Gets the element at the given position in a GList.
503 * list:
504 * a GList.
505 * n:
506 * the position of the element, counting from 0.
507 * Returns:
508 * the element, or NULL if the position is off the end of the GList.
510 public ListG nth(uint n)
512 // GList* g_list_nth (GList *list, guint n);
513 return new ListG( g_list_nth(gList, n) );
517 * Gets the data of the element at the given position.
518 * list:
519 * a GList.
520 * n:
521 * the position of the element.
522 * Returns:
523 * the element's data, or NULL if the position is off the end of the
524 * GList.
526 public void* nthData(uint n)
528 // gpointer g_list_nth_data (GList *list, guint n);
529 return g_list_nth_data(gList, n);
533 * Gets the element n places before list.
534 * list:
535 * a GList.
536 * n:
537 * the position of the element, counting from 0.
538 * Returns:
539 * the element, or NULL if the position is off the end of the GList.
541 public ListG nthPrev(uint n)
543 // GList* g_list_nth_prev (GList *list, guint n);
544 return new ListG( g_list_nth_prev(gList, n) );
548 * Finds the element in a GList which contains the given data.
549 * list:
550 * a GList.
551 * data:
552 * the element data to find.
553 * Returns:
554 * the found GList element, or NULL if it is not found.
556 public ListG find(void* data)
558 // GList* g_list_find (GList *list, gconstpointer data);
559 return new ListG( g_list_find(gList, data) );
563 * Finds an element in a GList, using a supplied function to find the desired
564 * element.
565 * It iterates over the list, calling the given function which should return 0
566 * when the desired element is found.
567 * The function takes two gconstpointer arguments, the GList element's data as
568 * the first argument and the given user data.
569 * list:
570 * a GList.
571 * data:
572 * user data passed to the function.
573 * func:
574 * the function to call for each element. It should return 0 when the
575 * desired element is found.
576 * Returns:
577 * the found GList element, or NULL if it is not found.
579 public ListG findCustom(void* data, GCompareFunc func)
581 // GList* g_list_find_custom (GList *list, gconstpointer data, GCompareFunc func);
582 return new ListG( g_list_find_custom(gList, data, func) );
586 * Gets the position of the given element in the GList (starting from 0).
587 * list:
588 * a GList.
589 * llink:
590 * an element in the GList.
591 * Returns:
592 * the position of the element in the GList, or -1 if the element is
593 * not found.
595 public int position(ListG llink)
597 // gint g_list_position (GList *list, GList *llink);
598 return g_list_position(gList, (llink is null) ? null : llink.getListGStruct());
602 * Gets the position of the element containing the given data (starting from 0).
603 * list:
604 * a GList.
605 * data:
606 * the data to find.
607 * Returns:
608 * the index of the element containing the data, or -1 if the data
609 * is not found.
611 public int index(void* data)
613 // gint g_list_index (GList *list, gconstpointer data);
614 return g_list_index(gList, data);
618 * Warning
619 * 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
620 * converted to the slice allocator
621 * Sets the allocator to use to allocate GList elements.
622 * Use g_list_pop_allocator() to restore the previous allocator.
623 * Note that this function is not available if GLib has been compiled
624 * with --disable-mem-pools
625 * allocator:
626 * the GAllocator to use when allocating GList elements.
628 public static void pushAllocator(void* allocator)
630 // void g_list_push_allocator (gpointer allocator);
631 g_list_push_allocator(allocator);
635 * Warning
636 * 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
637 * converted to the slice allocator
638 * Restores the previous GAllocator, used when allocating GList elements.
639 * Note that this function is not available if GLib has been compiled
640 * with --disable-mem-pools
642 public static void popAllocator()
644 // void g_list_pop_allocator (void);
645 g_list_pop_allocator();