glist.h File Reference

__G_LIST_H__

Typedef GList

typedef typedefG_BEGIN_DECLS struct _GListGList

g_list_alloc ( void )

IMPORT_C GList *g_list_alloc(void)

g_list_free ( GList * )

IMPORT_C voidg_list_free(GList *list)

g_list_free: : a GList

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, they should be freed first.

</note>

g_list_free_1 ( GList * )

IMPORT_C voidg_list_free_1(GList *list)

g_list_free_1: : a GList element

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

g_list_free1

g_list_append ( GList *, gpointer )

IMPORT_C GList *g_list_append(GList *list,
gpointerdata
)

g_list_append: : a pointer to a GList : the data for the new element

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>

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.

</note>

|[ / Notice that these are initialized to the empty list. / GList *list = NULL, *number_list = NULL;

/ This is a list of strings. / list = g_list_append (list, "first"); list = g_list_append (list, "second");

/ This is a list of integers. / number_list = g_list_append (number_list, GINT_TO_POINTER (27)); number_list = g_list_append (number_list, GINT_TO_POINTER (14)); ]|

Returns: the new start of the GList

g_list_prepend ( GList *, gpointer )

IMPORT_C GList *g_list_prepend(GList *list,
gpointerdata
)

g_list_prepend: : a pointer to a GList : the data for the new element

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.

</note>

|[ / Notice that it is initialized to the empty list. / GList *list = NULL; list = g_list_prepend (list, "last"); list = g_list_prepend (list, "first"); ]|

Returns: the new start of the GList

g_list_insert ( GList *, gpointer, gint )

IMPORT_C GList *g_list_insert(GList *list,
gpointerdata,
gintposition
)

g_list_insert: : a pointer to a GList : the data for the new element : the position to insert the element. If this is negative, or is larger than the number of elements in the list, the new element is added on to the end of the list.

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

Returns: the new start of the GList

g_list_insert_sorted ( GList *, gpointer, GCompareFunc )

IMPORT_C GList *g_list_insert_sorted(GList *list,
gpointerdata,
GCompareFuncfunc
)

g_list_insert_sorted: : a pointer to a GList : the data for the new element : the function to compare elements in the list. It should return a number > 0 if the first parameter comes after the second parameter in the sort order.

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

Returns: the new start of the GList

g_list_insert_sorted_with_data ( GList *, gpointer, GCompareDataFunc, gpointer )

IMPORT_C GList *g_list_insert_sorted_with_data(GList *list,
gpointerdata,
GCompareDataFuncfunc,
gpointeruser_data
)

g_list_insert_sorted_with_data: : a pointer to a GList : the data for the new element : the function to compare elements in the list. It should return a number > 0 if the first parameter comes after the second parameter in the sort order. : user data to pass to comparison function.

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

Returns: the new start of the GList

Since: 2.10

g_list_insert_before ( GList *, GList *, gpointer )

IMPORT_C GList *g_list_insert_before(GList *list,
GList *sibling,
gpointerdata
)

g_list_insert_before: : a pointer to a GList : the list element before which the new element is inserted or NULL to insert at the end of the list : the data for the new element

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

Returns: the new start of the GList

g_list_concat ( GList *, GList * )

IMPORT_C GList *g_list_concat(GList *list1,
GList *list2
)

g_list_concat: : a GList : the GList to add to the end of the first GList

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.

Returns: the start of the new GList

g_list_remove ( GList *, gconstpointer )

IMPORT_C GList *g_list_remove(GList *list,
gconstpointerdata
)

g_list_remove: : a GList : the data of the element to remove

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.

Returns: the new start of the GList

g_list_remove_all ( GList *, gconstpointer )

IMPORT_C GList *g_list_remove_all(GList *list,
gconstpointerdata
)

g_list_remove_all: : a GList : data to remove

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

Returns: new head of

g_list_remove_link ( GList *, GList * )

IMPORT_C GList *g_list_remove_link(GList *list,
GList *llink
)

g_list_remove_link: : a GList : an element in the GList

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.

Returns: the new start of the GList, without the element

g_list_delete_link ( GList *, GList * )

IMPORT_C GList *g_list_delete_link(GList *list,
GList *link_
)

g_list_delete_link: : a GList : node to delete from

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

Returns: the new head of

g_list_reverse ( GList * )

IMPORT_C GList *g_list_reverse(GList *list)

g_list_reverse: : a GList

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

Returns: the start of the reversed GList

g_list_copy ( GList * )

IMPORT_C GList *g_list_copy(GList *list)

g_list_copy: : a GList

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.

</note>

Returns: a copy of

g_list_nth ( GList *, guint )

IMPORT_C GList *g_list_nth(GList *list,
guintn
)

g_list_nth: : a GList : the position of the element, counting from 0

Gets the element at the given position in a GList.

Returns: the element, or NULL if the position is off the end of the GList

g_list_nth_prev ( GList *, guint )

IMPORT_C GList *g_list_nth_prev(GList *list,
guintn
)

g_list_nth_prev: : a GList : the position of the element, counting from 0

Gets the element places before .

Returns: the element, or NULL if the position is off the end of the GList

g_list_find ( GList *, gconstpointer )

IMPORT_C GList *g_list_find(GList *list,
gconstpointerdata
)

g_list_find: : a GList : the element data to find

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

Returns: the found GList element, or NULL if it is not found

g_list_find_custom ( GList *, gconstpointer, GCompareFunc )

IMPORT_C GList *g_list_find_custom(GList *list,
gconstpointerdata,
GCompareFuncfunc
)

g_list_find_custom: : a GList : user data passed to the function : the function to call for each element. It should return 0 when the desired element is found

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.

Returns: the found GList element, or NULL if it is not found

g_list_position ( GList *, GList * )

IMPORT_C gintg_list_position(GList *list,
GList *llink
)

g_list_position: : a GList : an element in the GList

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

Returns: the position of the element in the GList, or -1 if the element is not found

g_list_index ( GList *, gconstpointer )

IMPORT_C gintg_list_index(GList *list,
gconstpointerdata
)

g_list_index: : a GList : the data to find

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

Returns: the index of the element containing the data, or -1 if the data is not found

g_list_last ( GList * )

IMPORT_C GList *g_list_last(GList *list)

g_list_last: : a GList

Gets the last element in a GList.

Returns: the last element in the GList, or NULL if the GList has no elements

g_list_first ( GList * )

IMPORT_C GList *g_list_first(GList *list)

g_list_first: : a GList

Gets the first element in a GList.

Returns: the first element in the GList, or NULL if the GList has no elements

g_list_length ( GList * )

IMPORT_C guintg_list_length(GList *list)

g_list_length: : a GList

Gets the number of elements in a GList.

<note>

This function iterates over the whole list to count its elements.

</note>

Returns: the number of elements in the GList

g_list_foreach ( GList *, GFunc, gpointer )

IMPORT_C voidg_list_foreach(GList *list,
GFuncfunc,
gpointeruser_data
)

g_list_foreach: : a GList : the function to call with each element's data : user data to pass to the function

Calls a function for each element of a GList.

g_list_sort ( GList *, GCompareFunc )

IMPORT_C GList *g_list_sort(GList *list,
GCompareFunccompare_func
)

g_list_sort: : a GList : the comparison function used to sort the GList. This function is passed the data from 2 elements of the GList and should return 0 if they are equal, a negative value if the first element comes before the second, or a positive value if the first element comes after the second.

Sorts a GList using the given comparison function.

Returns: the start of the sorted GList

g_list_sort_with_data ( GList *, GCompareDataFunc, gpointer )

IMPORT_C GList *g_list_sort_with_data(GList *list,
GCompareDataFunccompare_func,
gpointeruser_data
)

g_list_sort_with_data: : a GList : comparison function : user data to pass to comparison function

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

Returns: the new head of

g_list_nth_data ( GList *, guint )

IMPORT_C gpointerg_list_nth_data(GList *list,
guintn
)

g_list_nth_data: : a GList : the position of the element

Gets the data of the element at the given position.

Returns: the element's data, or NULL if the position is off the end of the GList

g_list_previous

g_list_next

g_list_push_allocator ( gpointer )

IMPORT_C voidg_list_push_allocator(gpointerallocator)

g_list_pop_allocator ( void )

IMPORT_C voidg_list_pop_allocator(void)