tree_find_node_by_dataID
Description
Finds a tree node given its data id, and optionally its parent data id and repeat id, and granparent data id and repeat id.
Syntax
TreeNode tree_find_node_by_dataID( TreeNode tr, int nID, int nIDParent = 0, int nParentRepeatID = -1, int nIDGrandParent = 0, int nGrandParentRepeatID = -1 )
Parameters
- tr
- [input] the tree to search
- nID
- [input] the data id to find
- nIDParent
- [input] optional parent data id
- nParentRepeatID
- [input] optional parent repeat id
- nIDGrandParent
- [input] optional grandparent data id
- nGrandParentRepeatID
- [input] optional grandparent repeat id
Return
the TreeNode found if successful, an invalid TreeNode if not found.
Examples
EX1
void tree_find_node_by_dataID_ex1()
{
Tree trTest;
TreeNode tn1, tn2;
tn1 = trTest.AddTextNode("node 1", "Node1");
tn1.SetAttribute(STR_DATAID_ATTRIB, 1);
tn1.SetAttribute(STR_REPEAT_ID_ATTRIB, 1);
tn2 = trTest.AddTextNode("node 2", "Node2");
tn2.SetAttribute(STR_DATAID_ATTRIB, 2);
tn2.SetAttribute(STR_REPEAT_ID_ATTRIB, 2);
TreeNode tn1_1, tn1_2;
tn1_1 = tn1.AddTextNode("node 1.1", "Node1.1");
tn1_1.SetAttribute(STR_DATAID_ATTRIB, 3);
tn1_1.SetAttribute(STR_REPEAT_ID_ATTRIB, 3);
tn1_2 = tn1.AddTextNode("node 1.2", "Node1.2");
tn1_2.SetAttribute(STR_DATAID_ATTRIB, 4);
tn1_2.SetAttribute(STR_REPEAT_ID_ATTRIB, 4);
TreeNode tn1_1_1, tn1_1_2;
tn1_1_1 = tn1_1.AddTextNode("node 1.1.1", "Node1.1.1");
tn1_1_1.SetAttribute(STR_DATAID_ATTRIB, 5);
tn1_1_1.SetAttribute(STR_REPEAT_ID_ATTRIB, 5);
tn1_1_2 = tn1_1.AddTextNode("node 1.1.2", "Node1.1.2");
tn1_1_2.SetAttribute(STR_DATAID_ATTRIB, 6);
tn1_1_2.SetAttribute(STR_REPEAT_ID_ATTRIB, 6);
TreeNode tnRet;
tnRet = tree_find_node_by_dataID(trTest, 1, 0, -1, 0, -1);
if( tnRet )
out_str(tnRet.tagName);
else
out_str("can't find");
tnRet = tree_find_node_by_dataID(trTest, 7, 0, -1, 0, -1);
if( tnRet )
out_str(tnRet.tagName);
else
out_str("can't find");
tnRet = tree_find_node_by_dataID(trTest, 5, 3, -1, 1, -1);
if( tnRet )
out_str(tnRet.tagName);
else
out_str("can't find");
}
Remark
See Also
tree_get_node_by_dataid
header to Include
origin.h
Reference
|