2.2.3.17.1 TreeNode::AddNodeAddNode
Description
Copy and add an existing node to tree. (in the same tree or another tree).
Creates a new node with the specified name & id and returns that node.
Syntax
BOOL AddNode( TreeNode & tn, BOOL bDeep = TRUE )
TreeNode AddNode( LPCSTR Name = NULL, int nChildID = -1 )
Parameters
- tn
- [input] the node to be added to the tree
- bDeep
- [input] TRUE or FALSE; true will add deep
- Name
- [input]the name of the new node to be added to the tree. The name string must be a valid C identifier name. A valid C Identifier name must begin with a letter and can contain only letters, numbers, and underscore characters.
- nChildID
- [input] the id of the new node to be added to the tree
Return
TRUE if the node is successfully added; FALSE otherwise
A added new node.
Examples
EX1
void TreeNode_AddNode_ex1()
{
Tree tr;
TreeNode trNode1 = tr.AddNode("first", 1); // Add a sub node named "first" with node ID 1 to tr
TreeNode trNode2 = trNode1.AddNode("second", 11); // Add a sub node named "second" with node ID 11 to trNode1
out_tree(tr);
Tree tr1;
bool flag1 = tr1.AddNode(trNode1, FALSE); // If the bDeep is FALSE, only add the node trNode1 itself.
out_tree(tr1);
/*
Output:
OriginStorage
\---first =
*/
Tree tr2;
bool flag2 = tr2.AddNode(trNode1, TRUE); // If TRUE, add the node of trNode1 and all its subnodes.
out_tree(tr2);
/*
Output:
OriginStorage
\---first
\---second =
*/
}
EX2
void TreeNode_AddNode_ex2()
{
Tree tr;
TreeNode tn1, tn2, tn3;
tn1 = tr.AddNode("node1", 1); // Add TreeNode tn1, tn2 to Tree tr.
tn2 = tr.AddNode("node2", 2);
tn3 = tn2.AddNode("node21", 3); // Add TreeNode tn3 to TreeNode tn2.
out_tree(tr);
}
Remark
See Also
TreeNode::AddNumericNode, TreeNode::AddTextNode
Header to Include
origin.h
|