ListSG

The GSList structure and its associated functions provide a standard singly-linked list data structure.

Each element in the list contains a piece of data, together with a pointer which links to the next element in the list. Using this pointer it is possible to move through the list in one direction only (unlike the Doubly-Linked Lists which allow movement in both directions).

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 GSList 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 GSList. NULL is considered to be the empty list so you simply set a GSList* to NULL.

To add elements, use g_slist_append(), g_slist_prepend(), g_slist_insert() and g_slist_insert_sorted().

To remove elements, use g_slist_remove().

To find elements in the list use g_slist_last(), g_slist_next(), g_slist_nth(), g_slist_nth_data(), g_slist_find() and g_slist_find_custom().

To find the index of an element use g_slist_position() and g_slist_index().

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

To free the entire list, use g_slist_free().

Constructors

this
this(GSList* gSList)

Sets our main struct and passes it to the parent class

Members

Functions

append
ListSG 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_slist_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
ListSG concat(ListSG list2)

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

copy
ListSG copy()

Copies a GSList. 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 isn't. See g_slist_copy_deep() if you need to copy the data as well.

copyDeep
ListSG copyDeep(GCopyFunc func, void* userData)

Makes a full (deep) copy of a GSList. In contrast with g_slist_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
ListSG deleteLink(ListSG link)

Removes the node link_ from the list and frees it. Compare this to g_slist_remove_link() which removes the node without freeing it. Note Removing arbitrary nodes from a singly-linked list requires time that is proportional to the length of the list (ie. O(n)). If you find yourself using g_slist_delete_link() frequently, you should consider a different data structure, such as the doubly-linked GList.

find
ListSG find(void* data)

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

findCustom
ListSG findCustom(void* data, GCompareFunc func)

Finds an element in a GSList, 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 GSList element's data as the first argument and the given user data.

foreac
void foreac(GFunc func, void* userData)

Calls a function for each element of a GSList.

free
void free()

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

free1
void free1()

Frees one GSList element. It is usually used after g_slist_remove_link().

freeFull
void freeFull(GDestroyNotify freeFunc)

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

getListSGStruct
GSList* getListSGStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
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
ListSG insert(void* data, int position)

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

insertBefore
ListSG insertBefore(ListSG sibling, void* data)

Inserts a node before sibling containing data.

insertSorted
ListSG insertSorted(void* data, GCompareFunc func)

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

insertSortedWithData
ListSG 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
ListSG last()

Gets the last element in a GSList. Note This function iterates over the whole list.

length
uint length()

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

nth
ListSG nth(uint n)

Gets the element at the given position in a GSList.

nthData
void* nthData(uint n)

Gets the data of the element at the given position.

position
int position(ListSG llink)

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

prepend
ListSG 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
ListSG remove(void* data)

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

removeAll
ListSG removeAll(void* data)

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

removeLink
ListSG removeLink(ListSG link)

Removes an element from a GSList, without freeing the element. The removed element's next link is set to NULL, so that it becomes a self-contained list with one element. Note Removing arbitrary nodes from a singly-linked list requires time that is proportional to the length of the list (ie. O(n)). If you find yourself using g_slist_remove_link() frequently, you should consider a different data structure, such as the doubly-linked GList.

reverse
ListSG reverse()

Reverses a GSList.

sort
ListSG sort(GCompareFunc compareFunc)

Sorts a GSList using the given comparison function.

sortWithData
ListSG sortWithData(GCompareDataFunc compareFunc, void* userData)

Like g_slist_sort(), but the sort 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
ListSG next [@property getter]

get the next element

Static functions

alloc
ListSG alloc()

Allocates space for one GSList element. It is called by the g_slist_append(), g_slist_prepend(), g_slist_insert() and g_slist_insert_sorted() functions and so is rarely used on its own.

Variables

gSList
GSList* gSList;

the main Gtk struct

Meta