Package ch.bailu.gtk.glib
Class Node
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.Node
- All Implemented Interfaces:
PointerInterface
The #GNode struct represents one node in a [n-ary tree][glib-N-ary-Trees].
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
points to the first child of the #GNode.static final String
contains the actual data of the node.static final String
points to the node's next sibling (a sibling is another
#GNode with the same parent).static final String
points to the parent of the #GNode, or is %NULL if the
#GNode is the root of the tree.static final String
points to the node's previous sibling. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Node
Creates a new #GNode containing the given data.int
childIndex
(Pointer 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.void
childrenForeach
(int flags, Node.OnNodeForeachFunc func, Pointer data) Calls a function for each of the children of a #GNode.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.OnCopyFunc copy_func, Pointer data) Recursively copies a #GNode and its data.int
depth()
Gets the depth of a #GNode.void
destroy()
Removes @root and its children from the tree, freeing any memory
allocated.Finds a #GNode in a tree.Finds the first child of a #GNode with the given data.Gets the first sibling of a #GNode.static ClassHandler
points to the first child of the #GNode.contains the actual data of the node.points to the node's next sibling (a sibling is another
#GNode with the same parent).points to the parent of the #GNode, or is %NULL if the
#GNode is the root of the tree.points to the node's previous sibling.getRoot()
Gets the root of a tree.Inserts a #GNode beneath the parent at the given position.insertAfter
(Node sibling, Node node) Inserts a #GNode beneath the parent after the given sibling.insertBefore
(Node sibling, Node node) Inserts a #GNode beneath the parent before the given sibling.boolean
isAncestor
(Node descendant) Returns %TRUE if @node is an ancestor of @descendant.Gets the last child of a #GNode.Gets the last sibling of a #GNode.int
Gets the maximum height of all branches beneath a #GNode.int
Gets the number of children of a #GNode.int
nNodes
(int flags) Gets the number of nodes in a tree.nthChild
(int n) Gets a child of a #GNode, using the given index.Inserts a #GNode as the first child of the given parent.void
Reverses the order of the children of a #GNode.void
setFieldChildren
(Node children) points to the first child of the #GNode.void
setFieldData
(Pointer data) contains the actual data of the node.void
setFieldNext
(Node next) points to the node's next sibling (a sibling is another
#GNode with the same parent).void
setFieldParent
(Node parent) points to the parent of the #GNode, or is %NULL if the
#GNode is the root of the tree.void
setFieldPrev
(Node prev) points to the node's previous sibling.void
traverse
(int order, int flags, int max_depth, Node.OnNodeTraverseFunc func, Pointer data) Traverses a tree starting at the given root #GNode.void
unlink()
Unlinks a #GNode from a tree, resulting in two separate trees.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
DATA
contains the actual data of the node.- See Also:
-
NEXT
points to the node's next sibling (a sibling is another
#GNode with the same parent).- See Also:
-
PREV
points to the node's previous sibling.- See Also:
-
PARENT
points to the parent of the #GNode, or is %NULL if the
#GNode is the root of the tree.- See Also:
-
CHILDREN
points to the first child of the #GNode. The other
children are accessed by using the @next pointer of each
child.- See Also:
-
-
Constructor Details
-
Node
-
Node
public Node()
-
-
Method Details
-
getClassHandler
-
setFieldData
contains the actual data of the node. -
getFieldData
contains the actual data of the node. -
setFieldNext
points to the node's next sibling (a sibling is another
#GNode with the same parent). -
getFieldNext
points to the node's next sibling (a sibling is another
#GNode with the same parent). -
setFieldPrev
points to the node's previous sibling. -
getFieldPrev
points to the node's previous sibling. -
setFieldParent
points to the parent of the #GNode, or is %NULL if the
#GNode is the root of the tree. -
getFieldParent
points to the parent of the #GNode, or is %NULL if the
#GNode is the root of the tree. -
setFieldChildren
points to the first child of the #GNode. The other
children are accessed by using the @next pointer of each
child. -
getFieldChildren
points to the first child of the #GNode. The other
children are accessed by using the @next pointer of each
child. -
childIndex
Gets the position of the first child of a #GNode
which contains the given data.- Parameters:
data
- the data to find- Returns:
- the index of the child of @node which contains @data, or -1 if the data is not found
-
childPosition
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.- Parameters:
child
- a child of @node- Returns:
- the position of @child with respect to its siblings
-
childrenForeach
Calls a function for each of the children of a #GNode. Note that it
doesn't descend beneath the child nodes. @func must not do anything
that would modify the structure of the tree.- Parameters:
flags
- which types of children are to be visited, one of %G_TRAVERSE_ALL, %G_TRAVERSE_LEAVES and %G_TRAVERSE_NON_LEAVESfunc
- the function to call for each visited nodedata
- user data to pass to the function
-
copy
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
-
copyDeep
Recursively copies a #GNode and its data.- Parameters:
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.
-
depth
public int 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.- Returns:
- the depth of the #GNode
-
destroy
public void destroy()Removes @root and its children from the tree, freeing any memory
allocated. -
find
Finds a #GNode in a tree.- Parameters:
order
- the order in which nodes are visited - %G_IN_ORDER, %G_PRE_ORDER, %G_POST_ORDER, or %G_LEVEL_ORDERflags
- which types of children are to be searched, one of %G_TRAVERSE_ALL, %G_TRAVERSE_LEAVES and %G_TRAVERSE_NON_LEAVESdata
- the data to find- Returns:
- the found #GNode, or %NULL if the data is not found
-
findChild
Finds the first child of a #GNode with the given data.- Parameters:
flags
- which types of children are to be searched, one of %G_TRAVERSE_ALL, %G_TRAVERSE_LEAVES and %G_TRAVERSE_NON_LEAVESdata
- the data to find- Returns:
- the found child #GNode, or %NULL if the data is not found
-
firstSibling
Gets the first sibling of a #GNode.
This could possibly be the node itself.- Returns:
- the first sibling of @node
-
getRoot
Gets the root of a tree.- Returns:
- the root of the tree
-
insert
Inserts a #GNode beneath the parent at the given position.- Parameters:
position
- the position to place @node at, with respect to its siblings If position is -1, @node is inserted as the last child of @parentnode
- the #GNode to insert- Returns:
- the inserted #GNode
-
insertAfter
Inserts a #GNode beneath the parent after the given sibling.- Parameters:
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
-
insertBefore
Inserts a #GNode beneath the parent before the given sibling.- Parameters:
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
-
isAncestor
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.- Parameters:
descendant
- a #GNode- Returns:
- %TRUE if @node is an ancestor of @descendant
-
lastChild
Gets the last child of a #GNode.- Returns:
- the last child of @node, or %NULL if @node has no children
-
lastSibling
Gets the last sibling of a #GNode.
This could possibly be the node itself.- Returns:
- the last sibling of @node
-
maxHeight
public int 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.- Returns:
- the maximum height of the tree beneath @root
-
nChildren
public int nChildren()Gets the number of children of a #GNode.- Returns:
- the number of children of @node
-
nNodes
public int nNodes(int flags) Gets the number of nodes in a tree.- Parameters:
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
-
nthChild
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.- Parameters:
n
- the index of the desired child- Returns:
- the child of @node at index @n
-
prepend
Inserts a #GNode as the first child of the given parent.- Parameters:
node
- the #GNode to insert- Returns:
- the inserted #GNode
-
reverseChildren
public void reverseChildren()Reverses the order of the children of a #GNode.
(It doesn't change the order of the grandchildren.) -
traverse
public void traverse(int order, int flags, int max_depth, Node.OnNodeTraverseFunc func, @Nullable Pointer 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.
@func must not do anything that would modify the structure of the tree.- Parameters:
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_LEAVESmax_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 #GNodedata
- user data to pass to the function
-
unlink
public void unlink()Unlinks a #GNode from a tree, resulting in two separate trees. -
_new
Creates a new #GNode containing the given data.
Used to create the first node in a tree.- Parameters:
data
- the data of the new node- Returns:
- a new #GNode
-