Node

The GNode struct and its associated functions provide a N-ary tree data structure, where nodes in the tree can contain arbitrary data.

To create a new tree use g_node_new().

To insert a node into a tree use g_node_insert(), g_node_insert_before(), g_node_append() and g_node_prepend().

To create a new node and insert it into a tree use g_node_insert_data(), g_node_insert_data_after(), g_node_insert_data_before(), g_node_append_data() and g_node_prepend_data().

To reverse the children of a node use g_node_reverse_children().

To find a node use g_node_get_root(), g_node_find(), g_node_find_child(), g_node_child_index(), g_node_child_position(), g_node_first_child(), g_node_last_child(), g_node_nth_child(), g_node_first_sibling(), g_node_prev_sibling(), g_node_next_sibling() or g_node_last_sibling().

To get information about a node or tree use G_NODE_IS_LEAF(), G_NODE_IS_ROOT(), g_node_depth(), g_node_n_nodes(), g_node_n_children(), g_node_is_ancestor() or g_node_max_height().

To traverse a tree, calling a function for each node visited in the traversal, use g_node_traverse() or g_node_children_foreach().

To remove a node or subtree from a tree use g_node_unlink() or g_node_destroy().

Constructors

this
this(GNode* gNode)

Sets our main struct and passes it to the parent class

this
this(void* data)

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

Destructor

~this
~this()
Undocumented in source.

Members

Functions

childIndex
int childIndex(void* data)

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

childPosition
int childPosition(Node child)

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

childrenForeach
void childrenForeach(GTraverseFlags flags, GNodeForeachFunc func, void* data)

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

copy
Node copy()

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

copyDeep
Node copyDeep(GCopyFunc copyFunc, void* data)

Recursively copies a GNode and its data. Since 2.4

depth
uint depth()

Gets the depth of a GNode. If node 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.

destroy
void destroy()

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

find
Node find(GTraverseType order, GTraverseFlags flags, void* data)

Finds a GNode in a tree.

findChild
Node findChild(GTraverseFlags flags, void* data)

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

firstSibling
Node firstSibling()

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

getNodeStruct
GNode* getNodeStruct()

Get the main Gtk struct

getRoot
Node getRoot()

Gets the root of a tree.

getStruct
void* getStruct()

the main Gtk struct as a void*

insert
Node insert(int position, Node node)

Inserts a GNode beneath the parent at the given position.

insertAfter
Node insertAfter(Node sibling, Node node)

Inserts a GNode beneath the parent after the given sibling.

insertBefore
Node insertBefore(Node sibling, Node node)

Inserts a GNode beneath the parent before the given sibling.

isAncestor
int isAncestor(Node descendant)

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

lastChild
Node lastChild()

Gets the last child of a GNode.

lastSibling
Node lastSibling()

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

maxHeight
uint maxHeight()

Gets the maximum height of all branches beneath a GNode. This is the maximum distance from the GNode to all leaf nodes. If root is NULL, 0 is returned. If root has no children, 1 is returned. If root has children, 2 is returned. And so on.

nChildren
uint nChildren()

Gets the number of children of a GNode.

nNodes
uint nNodes(GTraverseFlags flags)

Gets the number of nodes in a tree.

nthChild
Node nthChild(uint n)

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.

prepend
Node prepend(Node node)

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

reverseChildren
void reverseChildren()

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

traverse
void traverse(GTraverseType order, GTraverseFlags flags, int maxDepth, GNodeTraverseFunc func, void* data)

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 func.

unlink
void unlink()

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

Variables

gNode
GNode* gNode;

the main Gtk struct

Meta