alternative to assert
[gtkD.git] / gtkD / src / glib / ListG.d
blob1c552444af077429813e2c07f031e23e107e9549
1 /*
2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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: Yes
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 * module aliases:
47 * local aliases:
50 module glib.ListG;
52 version(noAssert)
54 version(Tango)
56 import tango.io.Stdout; // use the tango loging?
60 private import gtkc.glibtypes;
62 private import gtkc.glib;
69 /**
70 * Description
71 * The GList structure and its associated functions provide a standard
72 * doubly-linked list data structure.
73 * Each element in the list contains a piece of data, together with pointers
74 * which link to the previous and next elements in the list.
75 * Using these pointers it is possible to move through the list in both
76 * directions (unlike the
77 * Singly-Linked Lists
78 * which only allows movement through the list in the forward direction).
79 * The data contained in each element can be either integer values, by using one
80 * of the
81 * Type Conversion Macros,
82 * or simply pointers to any type of data.
83 * List elements are allocated from the slice
84 * allocator, which is more efficient than allocating elements
85 * individually.
86 * Note that most of the GList functions expect to be passed a pointer to
87 * the first element in the list. The functions which insert elements return
88 * the new start of the list, which may have changed.
89 * There is no function to create a GList. NULL is considered to be the empty
90 * list so you simply set a GList* to NULL.
91 * To add elements, use g_list_append(), g_list_prepend(), g_list_insert()
92 * and g_list_insert_sorted().
93 * To remove elements, use g_list_remove().
94 * To find elements in the list use g_list_first(), g_list_last(), g_list_next(),
95 * g_list_previous(), g_list_nth(), g_list_nth_data(), g_list_find() and
96 * g_list_find_custom().
97 * To find the index of an element use g_list_position() and g_list_index().
98 * To call a function for each element in the list use g_list_foreach().
99 * To free the entire list, use g_list_free().
101 public class ListG
104 /** the main Gtk struct */
105 protected GList* gList;
108 public GList* getListGStruct()
110 return gList;
114 /** the main Gtk struct as a void* */
115 protected void* getStruct()
117 return cast(void*)gList;
121 * Sets our main struct and passes it to the parent class
123 public this (GList* gList)
125 version(noAssert)
127 if ( gList is null )
129 int zero = 0;
130 version(Tango)
132 Stdout("struct gList is null on constructor").newline;
134 else
136 printf("struct gList is null on constructor");
138 zero = zero / zero;
141 else
143 assert(gList !is null, "struct gList is null on constructor");
145 this.gList = gList;
149 void* data()
151 int* pt =cast(int*)getStruct();
152 return cast(void *)(*pt);
162 * Adds a new element on to the end of the list.
163 * Note
164 * The return value is the new start of the list, which may have changed, so
165 * make sure you store the new value.
166 * Note
167 * Note that g_list_append() has to traverse the entire list to find the end,
168 * which is inefficient when adding multiple elements. A common idiom to
169 * avoid the inefficiency is to prepend the elements and reverse the list
170 * when all elements have been added.
171 * /+* Notice that these are initialized to the empty list. +/
172 * GList *list = NULL, *number_list = NULL;
173 * /+* This is a list of strings. +/
174 * list = g_list_append (list, "first");
175 * list = g_list_append (list, "second");
176 * /+* This is a list of integers. +/
177 * number_list = g_list_append (number_list, GINT_TO_POINTER (27));
178 * number_list = g_list_append (number_list, GINT_TO_POINTER (14));
179 * list:
180 * a pointer to a GList.
181 * data:
182 * the data for the new element.
183 * Returns:
184 * the new start of the GList.
186 public ListG append(void* data)
188 // GList* g_list_append (GList *list, gpointer data);
189 return new ListG( g_list_append(gList, data) );
193 * Adds a new element on to the start of the list.
194 * Note
195 * The return value is the new start of the list, which may have changed, so
196 * make sure you store the new value.
197 * /+* Notice that it is initialized to the empty list. +/
198 * GList *list = NULL;
199 * list = g_list_prepend (list, "last");
200 * list = g_list_prepend (list, "first");
201 * list:
202 * a pointer to a GList.
203 * data:
204 * the data for the new element.
205 * Returns:
206 * the new start of the GList.
208 public ListG prepend(void* data)
210 // GList* g_list_prepend (GList *list, gpointer data);
211 return new ListG( g_list_prepend(gList, data) );
215 * Inserts a new element into the list at the given position.
216 * list:
217 * a pointer to a GList.
218 * data:
219 * the data for the new element.
220 * position:
221 * the position to insert the element. If this is negative, or is
222 * larger than the number of elements in the list, the new element is added on
223 * to the end of the list.
224 * Returns:
225 * the new start of the GList.
227 public ListG insert(void* data, int position)
229 // GList* g_list_insert (GList *list, gpointer data, gint position);
230 return new ListG( g_list_insert(gList, data, position) );
234 * Inserts a new element into the list before the given position.
235 * list:
236 * a pointer to a GList.
237 * sibling:
238 * the list element before which the new element is inserted
239 * or NULL to insert at the end of the list.
240 * data:
241 * the data for the new element.
242 * Returns:
243 * the new start of the GList.
245 public ListG insertBefore(ListG sibling, void* data)
247 // GList* g_list_insert_before (GList *list, GList *sibling, gpointer data);
248 return new ListG( g_list_insert_before(gList, (sibling is null) ? null : sibling.getListGStruct(), data) );
252 * Inserts a new element into the list, using the given comparison function
253 * to determine its position.
254 * list:
255 * a pointer to a GList.
256 * data:
257 * the data for the new element.
258 * func:
259 * the function to compare elements in the list. It should return a
260 * number > 0 if the first parameter comes after the second parameter in
261 * the sort order.
262 * Returns:
263 * the new start of the GList.
265 public ListG insertSorted(void* data, GCompareFunc func)
267 // GList* g_list_insert_sorted (GList *list, gpointer data, GCompareFunc func);
268 return new ListG( g_list_insert_sorted(gList, data, func) );
272 * Removes an element from a GList.
273 * If two elements contain the same data, only the first is removed.
274 * If none of the elements contain the data, the GList is unchanged.
275 * list:
276 * a GList.
277 * data:
278 * the data of the element to remove.
279 * Returns:
280 * the new start of the GList.
282 public ListG remove(void* data)
284 // GList* g_list_remove (GList *list, gconstpointer data);
285 return new ListG( g_list_remove(gList, data) );
289 * Removes an element from a GList, without freeing the element.
290 * The removed element's prev and next links are set to NULL, so that it becomes a
291 * self-contained list with one element.
292 * list:
293 * a GList.
294 * llink:
295 * an element in the GList.
296 * Returns:
297 * the new start of the GList, without the element.
299 public ListG removeLink(ListG llink)
301 // GList* g_list_remove_link (GList *list, GList *llink);
302 return new ListG( g_list_remove_link(gList, (llink is null) ? null : llink.getListGStruct()) );
306 * Deletes the node link_ from list.
307 * list:
308 * a GList.
309 * link_:
310 * node to delete from list.
311 * Returns:
312 * the new head of list.
314 public ListG deleteLink(ListG link)
316 // GList* g_list_delete_link (GList *list, GList *link_);
317 return new ListG( g_list_delete_link(gList, (link is null) ? null : link.getListGStruct()) );
321 * Removes all list nodes with data equal to data. Returns the new
322 * head of the list. Contrast with g_list_remove() which removes only
323 * the first node matching the given data.
324 * list:
325 * a GList.
326 * data:
327 * data to remove.
328 * Returns:
329 * new head of list.
331 public ListG removeAll(void* data)
333 // GList* g_list_remove_all (GList *list, gconstpointer data);
334 return new ListG( g_list_remove_all(gList, data) );
338 * Frees all of the memory used by a GList.
339 * The freed elements are returned to the slice allocator.
340 * Note
341 * If list elements contain dynamically-allocated memory, they should be freed
342 * first.
343 * list:
344 * a GList.
346 public void free()
348 // void g_list_free (GList *list);
349 g_list_free(gList);
353 * Allocates space for one GList element.
354 * It is called by g_list_append(), g_list_prepend(), g_list_insert() and
355 * g_list_insert_sorted() and so is rarely used on its own.
356 * Returns:
357 * a pointer to the newly-allocated GList element.
359 public static ListG alloc()
361 // GList* g_list_alloc (void);
362 return new ListG( g_list_alloc() );
366 * Frees one GList element.
367 * It is usually used after g_list_remove_link().
368 * list:
369 * a GList element.
371 public void free1()
373 // void g_list_free_1 (GList *list);
374 g_list_free_1(gList);
379 * Gets the number of elements in a GList.
380 * list:
381 * a GList.
382 * Returns:
383 * the number of elements in the GList.
385 public uint length()
387 // guint g_list_length (GList *list);
388 return g_list_length(gList);
392 * Copies a GList.
393 * Note that this is a "shallow" copy. If the list elements consist of pointers
394 * to data, the pointers are copied but the actual data isn't.
395 * list:
396 * a GList.
397 * Returns:
398 * a copy of list.
400 public ListG copy()
402 // GList* g_list_copy (GList *list);
403 return new ListG( g_list_copy(gList) );
407 * Reverses a GList.
408 * It simply switches the next and prev pointers of each element.
409 * list:
410 * a GList.
411 * Returns:
412 * the start of the reversed GList.
414 public ListG reverse()
416 // GList* g_list_reverse (GList *list);
417 return new ListG( g_list_reverse(gList) );
421 * Sorts a GList using the given comparison function.
422 * list:
423 * a GList.
424 * compare_func:
425 * the comparison function used to sort the GList.
426 * This function is passed the data from 2 elements of the GList and should
427 * return 0 if they are equal, a negative value if the first element
428 * comes before the second, or a positive value if the first element
429 * comes after the second.
430 * Returns:
431 * the start of the sorted GList.
433 public ListG sort(GCompareFunc compareFunc)
435 // GList* g_list_sort (GList *list, GCompareFunc compare_func);
436 return new ListG( g_list_sort(gList, compareFunc) );
441 * Inserts a new element into the list, using the given comparison function
442 * to determine its position.
443 * list:
444 * a pointer to a GList.
445 * data:
446 * the data for the new element.
447 * func:
448 * the function to compare elements in the list. It should return a
449 * number > 0 if the first parameter comes after the second parameter in
450 * the sort order.
451 * user_data:
452 * user data to pass to comparison function.
453 * Returns:
454 * the new start of the GList.
455 * Since 2.10
457 public ListG insertSortedWithData(void* data, GCompareDataFunc func, void* userData)
459 // GList* g_list_insert_sorted_with_data (GList *list, gpointer data, GCompareDataFunc func, gpointer user_data);
460 return new ListG( g_list_insert_sorted_with_data(gList, data, func, userData) );
464 * Like g_list_sort(), but the comparison function accepts a user data argument.
465 * list:
466 * a GList.
467 * compare_func:
468 * comparison function.
469 * user_data:
470 * user data to pass to comparison function.
471 * Returns:
472 * the new head of list.
474 public ListG sortWithData(GCompareDataFunc compareFunc, void* userData)
476 // GList* g_list_sort_with_data (GList *list, GCompareDataFunc compare_func, gpointer user_data);
477 return new ListG( g_list_sort_with_data(gList, compareFunc, userData) );
482 * Adds the second GList onto the end of the first GList.
483 * Note that the elements of the second GList are not copied.
484 * They are used directly.
485 * list1:
486 * a GList.
487 * list2:
488 * the GList to add to the end of the first GList.
489 * Returns:
490 * the start of the new GList.
492 public ListG concat(ListG list2)
494 // GList* g_list_concat (GList *list1, GList *list2);
495 return new ListG( g_list_concat(gList, (list2 is null) ? null : list2.getListGStruct()) );
499 * Calls a function for each element of a GList.
500 * list:
501 * a GList.
502 * func:
503 * the function to call with each element's data.
504 * user_data:
505 * user data to pass to the function.
507 public void foreac(GFunc func, void* userData)
509 // void g_list_foreach (GList *list, GFunc func, gpointer user_data);
510 g_list_foreach(gList, func, userData);
515 * Gets the first element in a GList.
516 * list:
517 * a GList.
518 * Returns:
519 * the first element in a GList, or NULL if the GList has no elements.
521 public ListG first()
523 // GList* g_list_first (GList *list);
524 return new ListG( g_list_first(gList) );
528 * Gets the last element in a GList.
529 * list:
530 * a GList.
531 * Returns:
532 * the last element in the GList, or NULL if the GList has no
533 * elements.
535 public ListG last()
537 // GList* g_list_last (GList *list);
538 return new ListG( g_list_last(gList) );
544 * Gets the element at the given position in a GList.
545 * list:
546 * a GList.
547 * n:
548 * the position of the element, counting from 0.
549 * Returns:
550 * the element, or NULL if the position is off the end of the GList.
552 public ListG nth(uint n)
554 // GList* g_list_nth (GList *list, guint n);
555 return new ListG( g_list_nth(gList, n) );
559 * Gets the data of the element at the given position.
560 * list:
561 * a GList.
562 * n:
563 * the position of the element.
564 * Returns:
565 * the element's data, or NULL if the position is off the end of the
566 * GList.
568 public void* nthData(uint n)
570 // gpointer g_list_nth_data (GList *list, guint n);
571 return g_list_nth_data(gList, n);
575 * Gets the element n places before list.
576 * list:
577 * a GList.
578 * n:
579 * the position of the element, counting from 0.
580 * Returns:
581 * the element, or NULL if the position is off the end of the GList.
583 public ListG nthPrev(uint n)
585 // GList* g_list_nth_prev (GList *list, guint n);
586 return new ListG( g_list_nth_prev(gList, n) );
590 * Finds the element in a GList which contains the given data.
591 * list:
592 * a GList.
593 * data:
594 * the element data to find.
595 * Returns:
596 * the found GList element, or NULL if it is not found.
598 public ListG find(void* data)
600 // GList* g_list_find (GList *list, gconstpointer data);
601 return new ListG( g_list_find(gList, data) );
605 * Finds an element in a GList, using a supplied function to find the desired
606 * element.
607 * It iterates over the list, calling the given function which should return 0
608 * when the desired element is found.
609 * The function takes two gconstpointer arguments, the GList element's data as
610 * the first argument and the given user data.
611 * list:
612 * a GList.
613 * data:
614 * user data passed to the function.
615 * func:
616 * the function to call for each element. It should return 0 when the
617 * desired element is found.
618 * Returns:
619 * the found GList element, or NULL if it is not found.
621 public ListG findCustom(void* data, GCompareFunc func)
623 // GList* g_list_find_custom (GList *list, gconstpointer data, GCompareFunc func);
624 return new ListG( g_list_find_custom(gList, data, func) );
628 * Gets the position of the given element in the GList (starting from 0).
629 * list:
630 * a GList.
631 * llink:
632 * an element in the GList.
633 * Returns:
634 * the position of the element in the GList, or -1 if the element is
635 * not found.
637 public int position(ListG llink)
639 // gint g_list_position (GList *list, GList *llink);
640 return g_list_position(gList, (llink is null) ? null : llink.getListGStruct());
644 * Gets the position of the element containing the given data (starting from 0).
645 * list:
646 * a GList.
647 * data:
648 * the data to find.
649 * Returns:
650 * the index of the element containing the data, or -1 if the data
651 * is not found.
653 public int index(void* data)
655 // gint g_list_index (GList *list, gconstpointer data);
656 return g_list_index(gList, data);
660 * Warning
661 * 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
662 * converted to the slice allocator
663 * Sets the allocator to use to allocate GList elements.
664 * Use g_list_pop_allocator() to restore the previous allocator.
665 * Note that this function is not available if GLib has been compiled
666 * with --disable-mem-pools
667 * allocator:
668 * the GAllocator to use when allocating GList elements.
670 public static void pushAllocator(void* allocator)
672 // void g_list_push_allocator (gpointer allocator);
673 g_list_push_allocator(allocator);
677 * Warning
678 * 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
679 * converted to the slice allocator
680 * Restores the previous GAllocator, used when allocating GList elements.
681 * Note that this function is not available if GLib has been compiled
682 * with --disable-mem-pools
684 public static void popAllocator()
686 // void g_list_pop_allocator (void);
687 g_list_pop_allocator();