tree_get_node

 

Contents

Description

Get TreeNode by provided Row and search stop level. Find TreeNode from 0 level.

Syntax

TreeNode tree_get_node( TreeNode & trRoot, int nRow, DWORD dwCntrl = 0, LPCSTR lpcszAttribute = NULL )

Parameters

trRoot
[Input] TreeNode to be searched
nRow
[Input] to find the nRow TreeNode from up to down, 0 based offset
dwCntrl
[Input] rule for getting tree node, See TREENODEAddGetRules
enum TREENODEAddGetRules{ 
        // only go through node with attribute marked. 
        // The option work with variable "lpcszAttribute".
        ATRN_LOOP_MARDED_NODE_ONLY   = 0x00010000,  

        // don't go through leafs
        ATRN_SKIP_LEAFS      = 0x00020000,

        // use lobyte to indicate level to stop, stop level should >= 0, 
        // 0 = show up to 1st child branch
        ATRN_STOP_LEVEL      = 0x00040000  
};
lpcszAttribute
[Input] work with dwCntrl, ATRN_LOOP_MARDED_NODE_ONLY option.

Return

found TreeNode, invalid if not found

Examples

EX1

void tree_get_node_ex1()
{
    Tree tr;
    tr.Math.Score.dVal = 90.5;
    tr.Math.Score.Grade.strVal = "Good";    
    tr.Math.Bookname.strVal = "Advanced Math";
    tr.English.Score.dVal = 95.5;
    tr.English.Score.SetAttribute(STR_STOP_ATTRIB, "stop");
    tr.English.Bookname.strVal = "English 1";
    
    TreeNode trNode = tree_get_node(tr, 2); //trNode is Math.Score.Grade
    out_tree(trNode);    
}

EX2

void tree_get_node_ex2() 
{
    Tree tr;
    
    tr.AddNode("Vegetables");
    
    tr.Fruits.SubNode1.strVal = "Apples";
    tr.Fruits.SubNode2.strVal = "Pears";
    
    tr.Nuts.SubNode1.strVal = "Walnuts";
    tr.Nuts.SubNode2.strVal = "Cashews";
 
    int nRow = 1; // offset is 0. 
    
    // only access the level 0, for example, 
    // tr.Fruits is level 0, tr.Fruits.SubNode1 is level 1.  
    DWORD dwCntrl = ATRN_STOP_LEVEL | 0;
    
    // skip leaf, here will skip tr.Vegetables node.
    dwCntrl |= ATRN_SKIP_LEAFS; 
    
    // Get row 2 of tr, to get Nuts tree.
    TreeNode trNode = tree_get_node(tr, nRow, dwCntrl);   
     
    if( trNode )
        out_tree(trNode);
    else
        out_str("Invalid node.");
    
    //output:
    /*    
    Nuts
        +---SubNode1 = Walnuts
        \---SubNode2 = Cashews  
    */
}

Remark

See Also

tree_check_get_node

header to Include

origin.h

Reference