Package org.gnome.glib
Class Node
java.lang.Object
io.github.jwharm.javagi.base.ProxyInstance
org.gnome.glib.Node
- All Implemented Interfaces:
Proxy
The
GNode
struct represents one node in a [n-ary tree][glib-N-ary-Trees].-
Constructor Summary
ConstructorDescriptionNode()
Allocate a new Node.Allocate a new Node.Node
(MemorySegment address) Create a Node proxy instance for the provided memory address.Allocate a new Node with the fields set to the provided values.Allocate a new Node with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionint
childIndex
(@Nullable MemorySegment data) Gets the position of the first child of aGNode
which contains the given data.int
childPosition
(Node child) Gets the position of aGNode
with respect to its siblings.void
childrenForeach
(Set<TraverseFlags> flags, NodeForeachFunc func) Calls a function for each of the children of aGNode
.void
childrenForeach
(TraverseFlags flags, NodeForeachFunc func) Calls a function for each of the children of aGNode
.copy()
Recursively copies aGNode
(but does not deep-copy the data inside the nodes, see g_node_copy_deep() if you need that).Recursively copies aGNode
and its data.int
depth()
Gets the depth of aGNode
.void
destroy()
Removes this Node and its children from the tree, freeing any memory allocated.find
(TraverseType order, Set<TraverseFlags> flags, @Nullable MemorySegment data) Finds aGNode
in a tree.find
(TraverseType order, TraverseFlags flags, @Nullable MemorySegment data) Finds aGNode
in a tree.findChild
(Set<TraverseFlags> flags, @Nullable MemorySegment data) Finds the first child of aGNode
with the given data.findChild
(TraverseFlags flags, @Nullable MemorySegment data) Finds the first child of aGNode
with the given data.Gets the first sibling of aGNode
.static MemoryLayout
The memory layout of the native struct.getRoot()
Gets the root of a tree.Inserts aGNode
beneath the parent at the given position.insertAfter
(Node sibling, Node node) Inserts aGNode
beneath the parent after the given sibling.insertBefore
(Node sibling, Node node) Inserts aGNode
beneath the parent before the given sibling.boolean
isAncestor
(Node descendant) Returnstrue
if this Node is an ancestor ofdescendant
.Gets the last child of aGNode
.Gets the last sibling of aGNode
.int
Gets the maximum height of all branches beneath aGNode
.int
Gets the number of children of aGNode
.static Node
new_
(@Nullable MemorySegment data) Creates a newGNode
containing the given data.int
nNodes
(Set<TraverseFlags> flags) Gets the number of nodes in a tree.int
nNodes
(TraverseFlags... flags) Gets the number of nodes in a tree.nthChild
(int n) Gets a child of aGNode
, using the given index.static void
Inserts aGNode
as the first child of the given parent.static void
pushAllocator
(Allocator allocator) Read the value of the fieldchildren
.readData()
Read the value of the fielddata
.readNext()
Read the value of the fieldnext
.Read the value of the fieldparent
.readPrev()
Read the value of the fieldprev
.void
Reverses the order of the children of aGNode
.void
traverse
(TraverseType order, Set<TraverseFlags> flags, int maxDepth, NodeTraverseFunc func) Traverses a tree starting at the given rootGNode
.void
traverse
(TraverseType order, TraverseFlags flags, int maxDepth, NodeTraverseFunc func) Traverses a tree starting at the given rootGNode
.void
unlink()
Unlinks aGNode
from a tree, resulting in two separate trees.void
writeChildren
(Node children) Write a value in the fieldchildren
.void
writeData
(MemorySegment data) Write a value in the fielddata
.void
Write a value in the fieldnext
.void
writeParent
(Node parent) Write a value in the fieldparent
.void
Write a value in the fieldprev
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Node
Create a Node proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Node
Allocate a new Node.- Parameters:
arena
- to control the memory allocation scope
-
Node
public Node()Allocate a new Node. The memory is allocated withArena.ofAuto()
. -
Node
Allocate a new Node with the fields set to the provided values.- Parameters:
data
- value for the fielddata
next
- value for the fieldnext
prev
- value for the fieldprev
parent
- value for the fieldparent
children
- value for the fieldchildren
arena
- to control the memory allocation scope
-
Node
Allocate a new Node with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
data
- value for the fielddata
next
- value for the fieldnext
prev
- value for the fieldprev
parent
- value for the fieldparent
children
- value for the fieldchildren
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readData
Read the value of the fielddata
.- Returns:
- The value of the field
data
-
writeData
Write a value in the fielddata
.- Parameters:
data
- The new value for the fielddata
-
readNext
-
writeNext
Write a value in the fieldnext
.- Parameters:
next
- The new value for the fieldnext
-
readPrev
-
writePrev
Write a value in the fieldprev
.- Parameters:
prev
- The new value for the fieldprev
-
readParent
-
writeParent
Write a value in the fieldparent
.- Parameters:
parent
- The new value for the fieldparent
-
readChildren
Read the value of the fieldchildren
.- Returns:
- The value of the field
children
-
writeChildren
Write a value in the fieldchildren
.- Parameters:
children
- The new value for the fieldchildren
-
new_
Creates a newGNode
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
-
popAllocator
public static void popAllocator() -
pushAllocator
-
childIndex
Gets the position of the first child of aGNode
which contains the given data.- Parameters:
data
- the data to find- Returns:
- the index of the child of this Node which contains
data
, or -1 if the data is not found
-
childPosition
Gets the position of aGNode
with respect to its siblings.child
must be a child of this Node. The first child is numbered 0, the second 1, and so on.- Parameters:
child
- a child of this Node- Returns:
- the position of
child
with respect to its siblings
-
childrenForeach
Calls a function for each of the children of aGNode
. 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 ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
func
- the function to call for each visited node
-
childrenForeach
Calls a function for each of the children of aGNode
. 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 ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
func
- the function to call for each visited node
-
copy
Recursively copies aGNode
(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
-
depth
public int depth()Gets the depth of aGNode
.If this 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 this Node and its children from the tree, freeing any memory allocated. -
find
public Node find(TraverseType order, Set<TraverseFlags> flags, @Nullable @Nullable MemorySegment data) Finds aGNode
in a tree.- Parameters:
order
- the order in which nodes are visited -TraverseType.IN_ORDER
,TraverseType.PRE_ORDER
,TraverseType.POST_ORDER
, orTraverseType.LEVEL_ORDER
flags
- which types of children are to be searched, one ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
data
- the data to find- Returns:
- the found
GNode
, ornull
if the data is not found
-
find
Finds aGNode
in a tree.- Parameters:
order
- the order in which nodes are visited -TraverseType.IN_ORDER
,TraverseType.PRE_ORDER
,TraverseType.POST_ORDER
, orTraverseType.LEVEL_ORDER
flags
- which types of children are to be searched, one ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
data
- the data to find- Returns:
- the found
GNode
, ornull
if the data is not found
-
findChild
Finds the first child of aGNode
with the given data.- Parameters:
flags
- which types of children are to be searched, one ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
data
- the data to find- Returns:
- the found child
GNode
, ornull
if the data is not found
-
findChild
Finds the first child of aGNode
with the given data.- Parameters:
flags
- which types of children are to be searched, one ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
data
- the data to find- Returns:
- the found child
GNode
, ornull
if the data is not found
-
firstSibling
Gets the first sibling of aGNode
. This could possibly be the node itself.- Returns:
- the first sibling of this Node
-
getRoot
-
insert
Inserts aGNode
beneath the parent at the given position.- Parameters:
position
- the position to placenode
at, with respect to its siblings If position is -1,node
is inserted as the last child of this Nodenode
- theGNode
to insert- Returns:
- the inserted
GNode
-
insertAfter
-
insertBefore
Inserts aGNode
beneath the parent before the given sibling.- Parameters:
sibling
- the siblingGNode
to placenode
before. If sibling isnull
, the node is inserted as the last child of this Node.node
- theGNode
to insert- Returns:
- the inserted
GNode
-
isAncestor
Returnstrue
if this Node is an ancestor ofdescendant
. This is true if node is the parent ofdescendant
, or if node is the grandparent ofdescendant
etc.- Parameters:
descendant
- aGNode
- Returns:
true
if this Node is an ancestor ofdescendant
-
lastChild
Gets the last child of aGNode
.- Returns:
- the last child of this Node, or
null
if this Node has no children
-
lastSibling
Gets the last sibling of aGNode
. This could possibly be the node itself.- Returns:
- the last sibling of this Node
-
maxHeight
public int maxHeight()Gets the maximum height of all branches beneath aGNode
. This is the maximum distance from theGNode
to all leaf nodes.If this Node is
null
, 0 is returned. If this Node has no children, 1 is returned. If this Node has children, 2 is returned. And so on.- Returns:
- the maximum height of the tree beneath this Node
-
nChildren
public int nChildren()Gets the number of children of aGNode
.- Returns:
- the number of children of this Node
-
nNodes
Gets the number of nodes in a tree.- Parameters:
flags
- which types of children are to be counted, one ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
- Returns:
- the number of nodes in the tree
-
nNodes
Gets the number of nodes in a tree.- Parameters:
flags
- which types of children are to be counted, one ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
- Returns:
- the number of nodes in the tree
-
nthChild
Gets a child of aGNode
, 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 this Node at index
n
-
prepend
-
reverseChildren
public void reverseChildren()Reverses the order of the children of aGNode
. (It doesn't change the order of the grandchildren.) -
traverse
public void traverse(TraverseType order, Set<TraverseFlags> flags, int maxDepth, NodeTraverseFunc func) Traverses a tree starting at the given rootGNode
. It calls the given function for each node visited. The traversal can be halted at any point by returningtrue
fromfunc
.func
must not do anything that would modify the structure of the tree.- Parameters:
order
- the order in which nodes are visited -TraverseType.IN_ORDER
,TraverseType.PRE_ORDER
,TraverseType.POST_ORDER
, orTraverseType.LEVEL_ORDER
.flags
- which types of children are to be visited, one ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
maxDepth
- 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 visitedGNode
-
traverse
Traverses a tree starting at the given rootGNode
. It calls the given function for each node visited. The traversal can be halted at any point by returningtrue
fromfunc
.func
must not do anything that would modify the structure of the tree.- Parameters:
order
- the order in which nodes are visited -TraverseType.IN_ORDER
,TraverseType.PRE_ORDER
,TraverseType.POST_ORDER
, orTraverseType.LEVEL_ORDER
.flags
- which types of children are to be visited, one ofTraverseFlags.ALL
,TraverseFlags.LEAVES
andTraverseFlags.NON_LEAVES
maxDepth
- 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 visitedGNode
-
unlink
public void unlink()Unlinks aGNode
from a tree, resulting in two separate trees.
-