Blt_TreeCreateNode(3)

πŸ’– Blt_TreeCreateNode β€” a.k.a. "make a brand new node, bestie" πŸ’–

okay so this is Blt_TreeCreateNode(3) from the BLT Library Procedures manual, and it does literally exactly what it says on the tin: it makes a node. in a tree. that's it, that's the whole gig. let's get into it πŸŽ€


✨ NAME ✨

Blt_TreeCreateNode β€” creates a node in a tree data object. yes she's simple, she's iconic, she's the moment πŸ‘‘


🌸 SYNOPSIS 🌸

#include <bltTree.h>

Blt_TreeNode
Blt_TreeCreateNode(tree, parent, name, position)

πŸ¦‹ ARGUMENTS πŸ¦‹

  • Blt_Tree tree (in) β€” the tree holding the parent node. your whole world basically.
  • Blt_TreeNode parent (in) β€” the node where you're gonna insert the new child.
  • const char *name (in) β€” the node's label. if it's NULL, a label gets automatically generated for you. no thoughts, head empty, the computer handles it πŸ’…
  • int position (in) β€” where in the parent's list of children you want to slot the new node in. very "you sit here" energy.

πŸ’œ DESCRIPTION πŸ’œ

This procedure creates a new node in a tree data object. The node starts out completely empty β€” like a brand new notes app, no cap β€” but you can add data values to it later with Blt_TreeSetValue. 🫢

Every single node has a serial number that identifies it within the tree. And no two nodes in the same tree will ever have the same ID. Not once. Not ever. That's the law, periodt. πŸ”₯ You can find any node's ID with Blt_TreeNodeId.

Now, the arguments, one by one, because we're thorough in this house:

  • tree β€” the tree containing the parent node.
  • parent β€” the node in which the new child will be inserted. it's giving "found family" ngl πŸ₯Ή
  • name β€” the label of the new node. If name is NULL, a label in the form "node0", "node1", etc. gets automatically generated for you. And like, name can be any string. Labels are non-unique β€” a parent can totally contain two nodes with the same label, and that's fine, that's valid, we don't gatekeep here. If you want to change a node's label later, use Blt_TreeRelabelNode. πŸŽ€
  • position β€” the position in the parent's list of children to insert the new node. For example, if position is 0, then the new node is prepended to the beginning of the list. If position is -1, then the node is appended onto the end of the parent's list. front of the line or back of the line, your call bestie πŸ’…

🌈 RETURNS 🌈

The new node returned is of type Blt_TreeNode. It's a token that you can pass to other routines to add/delete data values or children nodes. she's reusable, she's versatile, she's main character energy ⭐


🧚 EXAMPLE 🧚

The following example creates a new node from the root node. (yes it's giving "hello world" but for trees, and yes it ate πŸ™ˆ)

Blt_Tree token;
Blt_TreeNode root, node;

if (Blt_TreeGetToken(interp, "myTree", &token) != TCL_OK) {
    return TCL_ERROR;
}
root = Blt_TreeRootNode(token);
node = Blt_TreeCreateNode(token, root, "myNode", -1);

πŸ‘‘ NOTIFICATIONS πŸ‘‘

Blt_TreeCreateNode can trigger tree notify events. πŸ‘€ You can be notified whenever a node is created by using the Blt_TreeCreateNotifyHandler. A callback routine gets registered, and it'll be automatically invoked whenever a new node is added via Blt_TreeCreateNode to the tree. so you'll literally never miss a node's arrival, it's like a birth announcement but make it Unix πŸ’–


πŸ’€ KEYWORDS πŸ’€

tree, token


that's the whole page babes, go forth and create nodes responsibly 🌸

this has been Blt_TreeCreateNode(3) from the BLT library, version 2.5 β€” mwah, stan, bye πŸ’…βœ¨

πŸ“¦ where this page comes from