2.2.3.17.19 TreeNode::GetValue

Description

Allows recursive access for getting integer values a leaf of with a particular tagname of the TreeNode


Allows recursive access for getting double values a leaf of with a particular tagname of the TreeNode


Allows recursive access for getting string values a leaf of with a particular tagname of the TreeNode


Allows recursive access for getting vector values a leaf of with a particular tagname of the TreeNode

Syntax

BOOL GetValue( int & nval, LPCSTR lpcszPropName = NULL, BOOL bRecusrive = FALSE, BOOL bAll = FALSE )


BOOL GetValue( double & dval, LPCSTR lpcszPropName = NULL, BOOL bRecusrive = FALSE, BOOL bAll = FALSE )


BOOL GetValue( string & strval, LPCSTR lpcszPropName = NULL, BOOL bRecusrive = FALSE, BOOL bAll = FALSE )


BOOL GetValue( vectorbase & vval, LPCSTR lpcszPropName = NULL, BOOL bRecusrive = FALSE, BOOL bAll = FALSE )

Parameters

nval
[output] Recieve the value if succesful, overloaded for these few basic types
lpcszPropName
[input] tag name of leaves to get values to, if NULL will get values to "this" TreeNode object
bRecusrive
[input] if True, will check all leaves, not just children, but there descendants too, for a tag name match else will only search the immediate children
bAll
[input] Useless argument


dval
[output] Recieve the value if succesful, overloaded for these few basic types
lpcszPropName
[input] tag name of leaves to get values to, if NULL will get values to "this" TreeNode object
bRecusrive
[input] if True, will check all leaves, not just children, but there descendants too, for a tag name match else will only search the immediate children
bAll
[input] Useless argument


strval
[output] Recieve the value if succesful, overloaded for these few basic types
lpcszPropName
[input] tag name of leaves to get values to, if NULL will get values to "this" TreeNode object
bRecusrive
[input] if True, will check all leaves, not just children, but there descendants too, for a tag name match else will only search the immediate children
bAll
[input] Useless argument


vval
[output] Recieve the value if succesful, overloaded for these few basic types, not support vector<string> type
lpcszPropName
[input] tag name of leaves to get values to, if NULL will get values to "this" TreeNode object
bRecusrive
[input] if True, will check all leaves, not just children, but there descendants too, for a tag name match else will only search the immediate children
bAll
[input] Useless argument

Return

TRUE if successful FALSE if fail


TRUE if successful FALSE if fail


TRUE if successful FALSE if fail


TRUE if successful FALSE if fail

Examples

EX1

// The example shows how to get integer values
void TreeNode_GetValue_ex1()
{
    Tree tr;
    TreeNode tn1;
    tn1 = tr.AddTextNode("123", "Num", 1);
    out_tree(tr);
    /*
			   tr
               |
            Num(123)
    */
 
    int i;
    tr.GetValue(i, "Num"); // Get the value of node which tagname is Name
    out_int("Num = " , i);
}

EX2

// The example shows how to get double values
void TreeNode_GetValue_ex2()
{
    Tree tr;
    TreeNode tn1;
    tn1 = tr.AddNumericNode(123.456, "Num", 1);
    out_tree(tr);
    /*
			   tr
               |
            Num(123.456)
    */
 
    double d;
    tr.GetValue(d, "Num"); // Get the value of node which tagname is Name
    out_double("Num = " , d);
}

EX3

// The example shows how to get string values
void TreeNode_GetValue_ex3()
{
    Tree tr;
    TreeNode tn1;
    tn1 = tr.AddTextNode("Kenny", "Name", 1);
    out_tree(tr);
    /*
			   tr
               |
            Name(Kenny)
    */
 
    string strValue;
    tr.GetValue(strValue, "Name"); // Get the value of node which tagname is Name
    out_str("Name = " + strValue);
}

EX4

// The example shows how bRecusrive works.
void TreeNode_GetValue_ex4()
{
	Tree tr;
    TreeNode tn1 = tr.AddTextNode("abc", "node1", 1);
    TreeNode tn11 = tn1.AddTextNode("def", "node2", 2);
    TreeNode tn12 = tn1.AddTextNode("ghi", "node3", 3);
    TreeNode tn111 = tn11.AddTextNode("xxf", "node4", 4);
    out_tree(tr);
    /* 
    		   tr
    		   |
    		tn1(abc)
    	   /        \
    	tn11(def)  tn12(ghi)
    	  |
      tn111(xxf)
    */
    
    // Recursiving get the match
    string strValue;
    bool bRecusrive = false; // if set as false, GetValue will return false
	if( tn1.GetValue(strValue, "node4", bRecusrive) )
	{
		out_str("strValue = " + strValue);
	}
}

EX5

// The example shows how to Set/Get vector value
void TreeNode_GetValue_ex5()
{
    vector<double> vValues1;
    for(int nn = 0; nn < 4; ++nn)
        vValues1.Add( rnd() );
 
    Tree tr;
    TreeNode tn = tr.AddNode("Var", 1); 
    if( tr.SetValue(vValues1, "Var") )  // Assign a vector to Var node
    {
        out_str("Assign vector to tn node");
    }
 
    // Get the value of node "Var"
    vector<double> vValues2;
    if( tr.GetValue(vValues2, "Var") )
    { 
        for(int ii = 0; ii < vValues2.GetSize(); ++ii)
        {
            printf("NO.%d = %f\n", ii, vValues2[ii]);
        }
    }
}

Remark

See Also

TreeNode::SetValue

Header to Include

origin.h