gnode.h File Reference

__G_NODE_H__

Typedef GNode

typedef typedefG_BEGIN_DECLS struct _GNodeGNode

Enum GTraverseFlags

EnumeratorValueDescription
G_TRAVERSE_LEAVES1 << 0
G_TRAVERSE_NON_LEAVES1 << 1
G_TRAVERSE_ALLG_TRAVERSE_LEAVES | G_TRAVERSE_NON_LEAVES
G_TRAVERSE_MASK0x03
G_TRAVERSE_LEAFSG_TRAVERSE_LEAVES
G_TRAVERSE_NON_LEAFSG_TRAVERSE_NON_LEAVES

Enum GTraverseType

Typedef GNodeTraverseFunc

typedef gboolean(*GNodeTraverseFunc

Typedef GNodeForeachFunc

typedef void(*GNodeForeachFunc

Typedef GCopyFunc

typedef gpointer(*GCopyFunc

GCopyFunc: : A pointer to the data which should be copied : Additional data

A function of this signature is used to copy the node data when doing a deep-copy of a tree.

Returns: A pointer to the copy

Since: 2.4

G_NODE_IS_ROOT

G_NODE_IS_ROOT: : a GNode

Returns TRUE if a GNode is the root of a tree.

Returns: TRUE if the GNode is the root of a tree (i.e. it has no parent or siblings)

G_NODE_IS_LEAF

G_NODE_IS_LEAF: : a GNode

Returns TRUE if a GNode is a leaf node.

Returns: TRUE if the GNode is a leaf node (i.e. it has no children)

g_node_new ( gpointer )

IMPORT_C GNode *g_node_new(gpointerdata)

g_node_new: : the data of the new node

Creates a new GNode containing the given data. Used to create the first node in a tree.

Returns: a new GNode

g_node_destroy ( GNode * )

IMPORT_C voidg_node_destroy(GNode *root)

g_node_destroy: : the root of the tree/subtree to destroy

Removes and its children from the tree, freeing any memory allocated.

g_node_unlink ( GNode * )

IMPORT_C voidg_node_unlink(GNode *node)

g_node_unlink: : the GNode to unlink, which becomes the root of a new tree

Unlinks a GNode from a tree, resulting in two separate trees.

g_node_copy_deep ( GNode *, GCopyFunc, gpointer )

IMPORT_C GNode *g_node_copy_deep(GNode *node,
GCopyFunccopy_func,
gpointerdata
)

g_node_copy_deep: : a GNode : the function which is called to copy the data inside each node, or NULL to use the original data. : data to pass to

Recursively copies a GNode and its data.

Return value: a new GNode containing copies of the data in .

Since: 2.4

g_node_copy ( GNode * )

IMPORT_C GNode *g_node_copy(GNode *node)

g_node_copy: : a GNode

Recursively copies a GNode (but does not deep-copy the data inside the nodes, see g_node_copy_deep() if you need that).

Returns: a new GNode containing the same data pointers

g_node_insert ( GNode *, gint, GNode * )

IMPORT_C GNode *g_node_insert(GNode *parent,
gintposition,
GNode *node
)

g_node_insert: : the GNode to place under : the position to place at, with respect to its siblings If position is -1, is inserted as the last child of : the GNode to insert

Inserts a GNode beneath the parent at the given position.

Returns: the inserted GNode

g_node_insert_before ( GNode *, GNode *, GNode * )

IMPORT_C GNode *g_node_insert_before(GNode *parent,
GNode *sibling,
GNode *node
)

g_node_insert_before: : the GNode to place under : the sibling GNode to place before. If sibling is NULL, the node is inserted as the last child of . : the GNode to insert

Inserts a GNode beneath the parent before the given sibling.

Returns: the inserted GNode

g_node_insert_after ( GNode *, GNode *, GNode * )

IMPORT_C GNode *g_node_insert_after(GNode *parent,
GNode *sibling,
GNode *node
)

g_node_insert_after: : the GNode to place under : the sibling GNode to place after. If sibling is NULL, the node is inserted as the first child of . : the GNode to insert

Inserts a GNode beneath the parent after the given sibling.

Returns: the inserted GNode

g_node_prepend ( GNode *, GNode * )

IMPORT_C GNode *g_node_prepend(GNode *parent,
GNode *node
)

g_node_prepend: : the GNode to place the new GNode under : the GNode to insert

Inserts a GNode as the first child of the given parent.

Returns: the inserted GNode

g_node_n_nodes ( GNode *, GTraverseFlags )

IMPORT_C guintg_node_n_nodes(GNode *root,
GTraverseFlagsflags
)

g_node_n_nodes: : a GNode : which types of children are to be counted, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES

Gets the number of nodes in a tree.

Returns: the number of nodes in the tree

g_node_get_root ( GNode * )

IMPORT_C GNode *g_node_get_root(GNode *node)

g_node_get_root: : a GNode

Gets the root of a tree.

Returns: the root of the tree

g_node_is_ancestor ( GNode *, GNode * )

IMPORT_C gbooleang_node_is_ancestor(GNode *node,
GNode *descendant
)

g_node_is_ancestor: : a GNode : a GNode

Returns TRUE if is an ancestor of . This is true if node is the parent of , or if node is the grandparent of etc.

Returns: TRUE if is an ancestor of

g_node_depth ( GNode * )

IMPORT_C guintg_node_depth(GNode *node)

g_node_depth: : a GNode

Gets the depth of a GNode.

If is NULL the depth is 0. The root node has a depth of 1. For the children of the root node the depth is 2. And so on.

Returns: the depth of the GNode

g_node_find ( GNode *, GTraverseType, GTraverseFlags, gpointer )

IMPORT_C GNode *g_node_find(GNode *root,
GTraverseTypeorder,
GTraverseFlagsflags,
gpointerdata
)

g_node_find: : the root GNode of the tree to search : the order in which nodes are visited - G_IN_ORDER, G_PRE_ORDER, G_POST_ORDER, or G_LEVEL_ORDER : which types of children are to be searched, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES : the data to find

Finds a GNode in a tree.

Returns: the found GNode, or NULL if the data is not found

g_node_append

g_node_append: : the GNode to place the new GNode under : the GNode to insert

Inserts a GNode as the last child of the given parent.

Returns: the inserted GNode

g_node_insert_data

g_node_insert_data: : the GNode to place the new GNode under : the position to place the new GNode at. If position is -1, the new GNode is inserted as the last child of : the data for the new GNode

Inserts a new GNode at the given position.

Returns: the new GNode

g_node_insert_data_before

g_node_insert_data_before: : the GNode to place the new GNode under : the sibling GNode to place the new GNode before : the data for the new GNode

Inserts a new GNode before the given sibling.

Returns: the new GNode

g_node_prepend_data

g_node_prepend_data: : the GNode to place the new GNode under : the data for the new GNode

Inserts a new GNode as the first child of the given parent.

Returns: the new GNode

g_node_append_data

g_node_append_data: : the GNode to place the new GNode under : the data for the new GNode

Inserts a new GNode as the last child of the given parent.

Returns: the new GNode

g_node_traverse ( GNode *, GTraverseType, GTraverseFlags, gint, GNodeTraverseFunc, gpointer )

IMPORT_C voidg_node_traverse(GNode *root,
GTraverseTypeorder,
GTraverseFlagsflags,
gintmax_depth,
GNodeTraverseFuncfunc,
gpointerdata
)

g_node_traverse: : the root GNode of the tree to traverse : the order in which nodes are visited - G_IN_ORDER, G_PRE_ORDER, G_POST_ORDER, or G_LEVEL_ORDER. : which types of children are to be visited, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES : the maximum depth of the traversal. Nodes below this depth will not be visited. If max_depth is -1 all nodes in the tree are visited. If depth is 1, only the root is visited. If depth is 2, the root and its children are visited. And so on. : the function to call for each visited GNode : user data to pass to the function

Traverses a tree starting at the given root GNode. It calls the given function for each node visited. The traversal can be halted at any point by returning TRUE from .

g_node_max_height ( GNode * )

IMPORT_C guintg_node_max_height(GNode *root)

g_node_max_height: : a GNode

Gets the maximum height of all branches beneath a GNode. This is the maximum distance from the GNode to all leaf nodes.

If is NULL, 0 is returned. If has no children, 1 is returned. If has children, 2 is returned. And so on.

Returns: the maximum height of the tree beneath

g_node_children_foreach ( GNode *, GTraverseFlags, GNodeForeachFunc, gpointer )

IMPORT_C voidg_node_children_foreach(GNode *node,
GTraverseFlagsflags,
GNodeForeachFuncfunc,
gpointerdata
)

g_node_children_foreach: : a GNode : which types of children are to be visited, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES : the function to call for each visited node : user data to pass to the function

Calls a function for each of the children of a GNode. Note that it doesn't descend beneath the child nodes.

g_node_reverse_children ( GNode * )

IMPORT_C voidg_node_reverse_children(GNode *node)

g_node_reverse_children: : a GNode.

Reverses the order of the children of a GNode. (It doesn't change the order of the grandchildren.)

g_node_n_children ( GNode * )

IMPORT_C guintg_node_n_children(GNode *node)

g_node_n_children: : a GNode

Gets the number of children of a GNode.

Returns: the number of children of

g_node_nth_child ( GNode *, guint )

IMPORT_C GNode *g_node_nth_child(GNode *node,
guintn
)

g_node_nth_child: : a GNode : the index of the desired child

Gets a child of a GNode, using the given index. The first child is at index 0. If the index is too big, NULL is returned.

Returns: the child of at index

g_node_last_child ( GNode * )

IMPORT_C GNode *g_node_last_child(GNode *node)

g_node_last_child: : a GNode (must not be NULL)

Gets the last child of a GNode.

Returns: the last child of , or NULL if has no children

g_node_find_child ( GNode *, GTraverseFlags, gpointer )

IMPORT_C GNode *g_node_find_child(GNode *node,
GTraverseFlagsflags,
gpointerdata
)

g_node_find_child: : a GNode : which types of children are to be searched, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES : the data to find

Finds the first child of a GNode with the given data.

Returns: the found child GNode, or NULL if the data is not found

g_node_child_position ( GNode *, GNode * )

IMPORT_C gintg_node_child_position(GNode *node,
GNode *child
)

g_node_child_position: : a GNode : a child of

Gets the position of a GNode with respect to its siblings. must be a child of . The first child is numbered 0, the second 1, and so on.

Returns: the position of with respect to its siblings

g_node_child_index ( GNode *, gpointer )

IMPORT_C gintg_node_child_index(GNode *node,
gpointerdata
)

g_node_child_index: : a GNode : the data to find

Gets the position of the first child of a GNode which contains the given data.

Returns: the index of the child of which contains , or -1 if the data is not found

g_node_first_sibling ( GNode * )

IMPORT_C GNode *g_node_first_sibling(GNode *node)

g_node_first_sibling: : a GNode

Gets the first sibling of a GNode. This could possibly be the node itself.

Returns: the first sibling of

g_node_last_sibling ( GNode * )

IMPORT_C GNode *g_node_last_sibling(GNode *node)

g_node_last_sibling: : a GNode

Gets the last sibling of a GNode. This could possibly be the node itself.

Returns: the last sibling of

g_node_prev_sibling

g_node_prev_sibling: : a GNode

Gets the previous sibling of a GNode.

Returns: the previous sibling of , or NULL if is NULL

g_node_next_sibling

g_node_next_sibling: : a GNode

Gets the next sibling of a GNode.

Returns: the next sibling of , or NULL if is NULL

g_node_first_child

g_node_first_child: : a GNode

Gets the first child of a GNode.

Returns: the first child of , or NULL if is NULL or has no children

g_node_push_allocator ( gpointer )

IMPORT_C voidg_node_push_allocator(gpointerdummy)

g_node_pop_allocator ( void )

IMPORT_C voidg_node_pop_allocator(void)