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
56 import tango
.io
.Stdout
; // use the tango loging?
60 private import gtkc
.glibtypes
;
62 private import gtkc
.glib
;
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
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
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
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().
104 /** the main Gtk struct */
105 protected GList
* gList
;
108 public GList
* getListGStruct()
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
)
132 Stdout("struct gList is null on constructor").newline
;
136 printf("struct gList is null on constructor");
143 assert(gList
!is null, "struct gList is null on constructor");
151 int* pt
=cast(int*)getStruct();
152 return cast(void *)(*pt
);
162 * Adds a new element on to the end of the list.
164 * The return value is the new start of the list, which may have changed, so
165 * make sure you store the new value.
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));
180 * a pointer to a GList.
182 * the data for the new element.
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.
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");
202 * a pointer to a GList.
204 * the data for the new element.
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.
217 * a pointer to a GList.
219 * the data for the new element.
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.
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.
236 * a pointer to a GList.
238 * the list element before which the new element is inserted
239 * or NULL to insert at the end of the list.
241 * the data for the new element.
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.
255 * a pointer to a GList.
257 * the data for the new element.
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
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.
278 * the data of the element to remove.
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.
295 * an element in the GList.
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.
310 * node to delete from list.
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.
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.
341 * If list elements contain dynamically-allocated memory, they should be freed
348 // void g_list_free (GList *list);
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.
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().
373 // void g_list_free_1 (GList *list);
374 g_list_free_1(gList
);
379 * Gets the number of elements in a GList.
383 * the number of elements in the GList.
387 // guint g_list_length (GList *list);
388 return g_list_length(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.
402 // GList* g_list_copy (GList *list);
403 return new ListG( g_list_copy(gList
) );
408 * It simply switches the next and prev pointers of each element.
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.
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.
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.
444 * a pointer to a GList.
446 * the data for the new element.
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
452 * user data to pass to comparison function.
454 * the new start of the GList.
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.
468 * comparison function.
470 * user data to pass to comparison function.
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.
488 * the GList to add to the end of the first GList.
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.
503 * the function to call with each element's 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.
519 * the first element in a GList, or NULL if the GList has no elements.
523 // GList* g_list_first (GList *list);
524 return new ListG( g_list_first(gList
) );
528 * Gets the last element in a GList.
532 * the last element in the GList, or NULL if the GList has no
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.
548 * the position of the element, counting from 0.
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.
563 * the position of the element.
565 * the element's data, or NULL if the position is off the end of the
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.
579 * the position of the element, counting from 0.
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.
594 * the element data to find.
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
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.
614 * user data passed to the function.
616 * the function to call for each element. It should return 0 when the
617 * desired element is found.
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).
632 * an element in the GList.
634 * the position of the element in the GList, or -1 if the element is
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).
650 * the index of the element containing the data, or -1 if the data
653 public int index(void* data
)
655 // gint g_list_index (GList *list, gconstpointer data);
656 return g_list_index(gList
, data
);
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
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
);
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();