glib.Node.Node Class Reference

List of all members.

Detailed Description

Description 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_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().


Public Member Functions

GNodegetNodeStruct ()
 this (GNode *gNode)
 Sets our main struct and passes it to the parent class.
 this (void *data)
 Creates a new GNode containing the given data.
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).
Node copyDeep (GCopyFunc copyFunc, void *data)
 Recursively copies a GNode and its data.
Node insert (int position, Node node)
 Inserts a GNode beneath the parent at the given position.
Node insertBefore (Node sibling, Node node)
 Inserts a GNode beneath the parent before the given sibling.
Node insertAfter (Node sibling, Node node)
 Inserts a GNode beneath the parent after the given sibling.
Node prepend (Node node)
 Inserts a GNode as the first child of the given parent.
void reverseChildren ()
 Reverses the order of the children of a GNode.
void traverse (GTraverseType order, GTraverseFlags flags, int maxDepth, GNodeTraverseFunc func, void *data)
 Traverses a tree starting at the given root GNode.
void childrenForeach (GTraverseFlags flags, GNodeForeachFunc func, void *data)
 Calls a function for each of the children of a GNode.
Node getRoot ()
 Gets the root of a tree.
Node find (GTraverseType order, GTraverseFlags flags, void *data)
 Finds a GNode in a tree.
Node findChild (GTraverseFlags flags, void *data)
 Finds the first child of a GNode with the given data.
int childIndex (void *data)
 Gets the position of the first child of a GNode which contains the given data.
int childPosition (Node child)
 Gets the position of a GNode with respect to its siblings.
Node lastChild ()
 Gets the last child of a GNode.
Node nthChild (uint n)
 Gets a child of a GNode, using the given index.
Node firstSibling ()
 Gets the first sibling of a GNode.
Node lastSibling ()
 Gets the last sibling of a GNode.
uint depth ()
 Gets the depth of a GNode.
uint nNodes (GTraverseFlags flags)
 Gets the number of nodes in a tree.
uint nChildren ()
 Gets the number of children of a GNode.
int isAncestor (Node descendant)
 Returns TRUE if node is an ancestor of descendant.
uint maxHeight ()
 Gets the maximum height of all branches beneath a GNode.
void unlink ()
 Unlinks a GNode from a tree, resulting in two separate trees.
void destroy ()
 Removes the GNode and its children from the tree, freeing any memory allocated.

Static Public Member Functions

static void pushAllocator (void *dummy)
 Warning g_node_push_allocator has been deprecated since version 2.10 and should not be used in newly-written code.
static void popAllocator ()
 Warning g_node_pop_allocator has been deprecated since version 2.10 and should not be used in newly-written code.

Protected Member Functions

void * getStruct ()
 the main Gtk struct as a void*

Protected Attributes

GNodegNode
 the main Gtk struct


Constructor & Destructor Documentation

glib.Node.Node.this ( GNode gNode  ) 

Sets our main struct and passes it to the parent class.

glib.Node.Node.this ( void *  data  ) 

Creates a new GNode containing the given data.

Used to create the first node in a tree. data: the data of the new node. Returns: a new GNode.


Member Function Documentation

int glib.Node.Node.childIndex ( void *  data  ) 

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

node: a GNode. data: the data to find. Returns: the index of the child of node which contains data, or -1 if the data is not found.

int glib.Node.Node.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. node: a GNode. child: a child of node. Returns: the position of child with respect to its siblings.

void glib.Node.Node.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. node: a GNode. flags: which types of children are to be visited, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES. func: the function to call for each visited node. data: user data to pass to the function.

Node glib.Node.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).

node: a GNode. Returns: a new GNode containing the same data pointers.

Node glib.Node.Node.copyDeep ( GCopyFunc  copyFunc,
void *  data 
)

Recursively copies a GNode and its data.

node: a GNode copy_func: the function which is called to copy the data inside each node, or NULL to use the original data. data: data to pass to copy_func Returns: a new GNode containing copies of the data in node. Since 2.4

uint glib.Node.Node.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. node: a GNode. Returns: the depth of the GNode.

void glib.Node.Node.destroy (  ) 

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

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

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

Finds a GNode in a tree.

root: the root GNode of the tree to search. order: the order in which nodes are visited - G_IN_ORDER, G_PRE_ORDER, G_POST_ORDER, or G_LEVEL_ORDER. flags: which types of children are to be searched, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES. data: the data to find. Returns: the found GNode, or NULL if the data is not found.

Node glib.Node.Node.findChild ( GTraverseFlags  flags,
void *  data 
)

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

node: a GNode. flags: which types of children are to be searched, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES. data: the data to find. Returns: the found child GNode, or NULL if the data is not found.

Node glib.Node.Node.firstSibling (  ) 

Gets the first sibling of a GNode.

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

GNode* glib.Node.Node.getNodeStruct (  ) 

Node glib.Node.Node.getRoot (  ) 

Gets the root of a tree.

node: a GNode. Returns: the root of the tree.

void* glib.Node.Node.getStruct (  )  [protected]

the main Gtk struct as a void*

Node glib.Node.Node.insert ( int  position,
Node  node 
)

Inserts a GNode beneath the parent at the given position.

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

Node glib.Node.Node.insertAfter ( Node  sibling,
Node  node 
)

Inserts a GNode beneath the parent after the given sibling.

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

Node glib.Node.Node.insertBefore ( Node  sibling,
Node  node 
)

Inserts a GNode beneath the parent before the given sibling.

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

int glib.Node.Node.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. node: a GNode. descendant: a GNode. Returns: TRUE if node is an ancestor of descendant.

Node glib.Node.Node.lastChild (  ) 

Gets the last child of a GNode.

node: a GNode (must not be NULL). Returns: the last child of node, or NULL if node has no children.

Node glib.Node.Node.lastSibling (  ) 

Gets the last sibling of a GNode.

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

uint glib.Node.Node.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. root: a GNode. Returns: the maximum height of the tree beneath root.

uint glib.Node.Node.nChildren (  ) 

Gets the number of children of a GNode.

node: a GNode. Returns: the number of children of node.

uint glib.Node.Node.nNodes ( GTraverseFlags  flags  ) 

Gets the number of nodes in a tree.

root: a GNode. flags: which types of children are to be counted, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES. Returns: the number of nodes in the tree.

Node glib.Node.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. node: a GNode. n: the index of the desired child. Returns: the child of node at index n.

static void glib.Node.Node.popAllocator (  )  [static]

Warning g_node_pop_allocator has been deprecated since version 2.10 and should not be used in newly-written code.

It does nothing, since GNode has been converted to the slice allocator Restores the previous GAllocator, used when allocating GNode elements. Note that this function is not available if GLib has been compiled with --disable-mem-pools

Node glib.Node.Node.prepend ( Node  node  ) 

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

parent: the GNode to place the new GNode under. node: the GNode to insert. Returns: the inserted GNode.

static void glib.Node.Node.pushAllocator ( void *  dummy  )  [static]

Warning g_node_push_allocator has been deprecated since version 2.10 and should not be used in newly-written code.

It does nothing, since GNode has been converted to the slice allocator Sets the allocator to use to allocate GNode elements. Use g_node_pop_allocator() to restore the previous allocator. Note that this function is not available if GLib has been compiled with --disable-mem-pools dummy: the GAllocator to use when allocating GNode elements.

void glib.Node.Node.reverseChildren (  ) 

Reverses the order of the children of a GNode.

(It doesn't change the order of the grandchildren.) node: a GNode.

void glib.Node.Node.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. root: the root GNode of the tree to traverse. order: the order in which nodes are visited - G_IN_ORDER, G_PRE_ORDER, G_POST_ORDER, or G_LEVEL_ORDER. flags: which types of children are to be visited, one of G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES. max_depth: 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. func: the function to call for each visited GNode. data: user data to pass to the function.

void glib.Node.Node.unlink (  ) 

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

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


Member Data Documentation

GNode* glib.Node.Node.gNode [protected]

the main Gtk struct


SourceForge.net Logo DSource.org Logo digitalmars.com Logo