ListG

The GList structure and its associated functions provide a standard doubly-linked list data structure.

Each element in the list contains a piece of data, together with pointers which link to the previous and next elements in the list. Using these pointers it is possible to move through the list in both directions (unlike the Singly-Linked Lists which only allows movement through the list in the forward direction).

The data contained in each element can be either integer values, by using one of the Type Conversion Macros, or simply pointers to any type of data.

List elements are allocated from the slice allocator, which is more efficient than allocating elements individually.

Note that most of the GList functions expect to be passed a pointer to the first element in the list. The functions which insert elements return the new start of the list, which may have changed.

There is no function to create a GList. NULL is considered to be the empty list so you simply set a GList* to NULL.

To add elements, use g_list_append(), g_list_prepend(), g_list_insert() and g_list_insert_sorted().

To remove elements, use g_list_remove().

To find elements in the list use g_list_first(), g_list_last(), g_list_next(), g_list_previous(), g_list_nth(), g_list_nth_data(), g_list_find() and g_list_find_custom().

To find the index of an element use g_list_position() and g_list_index().

To call a function for each element in the list use g_list_foreach().

To free the entire list, use g_list_free().

Constructors

this
this(GList* gList)

Sets our main struct and passes it to the parent class

Members

Functions

append
ListG append(void* data)

Adds a new element on to the end of the list. Note The return value is the new start of the list, which may have changed, so make sure you store the new value. Note Note that g_list_append() has to traverse the entire list to find the end, which is inefficient when adding multiple elements. A common idiom to avoid the inefficiency is to prepend the elements and reverse the list when all elements have been added.

concat
ListG concat(ListG list2)

Adds the second GList onto the end of the first GList. Note that the elements of the second GList are not copied. They are used directly.

copy
ListG copy()

Copies a GList. Note Note that this is a "shallow" copy. If the list elements consist of pointers to data, the pointers are copied but the actual data is not. See g_list_copy_deep() if you need to copy the data as well.

copyDeep
ListG copyDeep(GCopyFunc func, void* userData)

Makes a full (deep) copy of a GList. In contrast with g_list_copy(), this function uses func to make a copy of each list element, in addition to copying the list container itself. func, as a GCopyFunc, takes two arguments, the data to be copied and a user pointer. It's safe to pass NULL as user_data, if the copy function takes only one argument. Since 2.34

deleteLink
ListG deleteLink(ListG link)

Removes the node link_ from the list and frees it. Compare this to g_list_remove_link() which removes the node without freeing it.

find
ListG find(void* data)

Finds the element in a GList which contains the given data.

findCustom
ListG findCustom(void* data, GCompareFunc func)

Finds an element in a GList, using a supplied function to find the desired element. It iterates over the list, calling the given function which should return 0 when the desired element is found. The function takes two gconstpointer arguments, the GList element's data as the first argument and the given user data.

first
ListG first()

Gets the first element in a GList.

foreac
void foreac(GFunc func, void* userData)

Calls a function for each element of a GList.

free
void free()

Frees all of the memory used by a GList. The freed elements are returned to the slice allocator. Note If list elements contain dynamically-allocated memory, you should either use g_list_free_full() or free them manually first.

free1
void free1()

Frees one GList element. It is usually used after g_list_remove_link().

freeFull
void freeFull(GDestroyNotify freeFunc)

Convenience method, which frees all the memory used by a GList, and calls the specified destroy function on every element's data. Since 2.28

getListGStruct
GList* getListGStruct()

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

index
int index(void* data)

Gets the position of the element containing the given data (starting from 0).

insert
ListG insert(void* data, int position)

Inserts a new element into the list at the given position.

insertBefore
ListG insertBefore(ListG sibling, void* data)

Inserts a new element into the list before the given position.

insertSorted
ListG insertSorted(void* data, GCompareFunc func)

Inserts a new element into the list, using the given comparison function to determine its position.

insertSortedWithData
ListG insertSortedWithData(void* data, GCompareDataFunc func, void* userData)

Inserts a new element into the list, using the given comparison function to determine its position. Since 2.10

last
ListG last()

Gets the last element in a GList.

length
uint length()

Gets the number of elements in a GList. Note This function iterates over the whole list to count its elements.

nth
ListG nth(uint n)

Gets the element at the given position in a GList.

nthData
void* nthData(uint n)

Gets the data of the element at the given position.

nthPrev
ListG nthPrev(uint n)

Gets the element n places before list.

position
int position(ListG llink)

Gets the position of the given element in the GList (starting from 0).

prepend
ListG prepend(void* data)

Adds a new element on to the start of the list. Note The return value is the new start of the list, which may have changed, so make sure you store the new value.

remove
ListG remove(void* data)

Removes an element from a GList. If two elements contain the same data, only the first is removed. If none of the elements contain the data, the GList is unchanged.

removeAll
ListG removeAll(void* data)

Removes all list nodes with data equal to data. Returns the new head of the list. Contrast with g_list_remove() which removes only the first node matching the given data.

removeLink
ListG removeLink(ListG llink)

Removes an element from a GList, without freeing the element. The removed element's prev and next links are set to NULL, so that it becomes a self-contained list with one element.

reverse
ListG reverse()

Reverses a GList. It simply switches the next and prev pointers of each element.

sort
ListG sort(GCompareFunc compareFunc)

Sorts a GList using the given comparison function. The algorithm used is a stable sort.

sortWithData
ListG sortWithData(GCompareDataFunc compareFunc, void* userData)

Like g_list_sort(), but the comparison function accepts a user data argument.

toArray
T[] toArray()

Turn the list into a D array of the desiered type. Type T wraps should match the type of the data.

Properties

data
void* data [@property getter]
next
ListG next [@property getter]

get the next element

previous
ListG previous [@property getter]

get the previous element

Static functions

alloc
ListG alloc()

Allocates space for one GList element. It is called by g_list_append(), g_list_prepend(), g_list_insert() and g_list_insert_sorted() and so is rarely used on its own.

Variables

gList
GList* gList;

the main Gtk struct

Meta