2.1.26.66 tree_set_values_by_ids


Description

Walk all nodes, look for nodes with matching DataID, and apply value, if have same DataID, will just save the value of the first one DataID .

Syntax

int tree_set_values_by_ids( TreeNode & trSetting, const vector<int> & vnIDs, const vector<string> & vsValues, int nRepeatBranchID = 0, int * pnDuplicateID = NULL )

Parameters

trSetting
[modify]a source tree
vnIDs
[input]vector of IDs.
vsValues
[input]vector of string values, must be the same size of vnIDs.
nRepeatBranchID
[input] DataID of parent or itself, must > 0 and < MAX_REPEAT_ID_VALUE.
pnDuplicateID
[output] optional point to int to receive the first DataID that appear more then once.
In order to reliably use DataID to map values, all tree nodes must have unique DataID. If this argument is not set (NULL), and there are non-unique ID, then -4 is returned and no setting will be done. If pnDuplicateID is not NULL, then the first duplicate ID is put into this pointer and setting will proceed despite the duplicate

Return

number of matching found nodes,

if return -1 mean input tree node not invalid,

-2 mean the pair of vector size to 0;

-3 when the pair vector not the same size,

-4 mean have duplicate id in id vector.

-5 when nRepeatBranchID out of range or when nRepeatBranchID is valid and subbranch node dataid out of range.

Examples

EX1

//This example reads values of nodes from TreeNode.ini, and saves user's modifications to this file.

#include <GetNBox.h>
enum{ID_NUMEXP, ID_B, ID_B_T1, ID_B_T2, ID_B_T3, ID_DATARANGE, ID_CURVECOLOR};
void tree_set_values_with_ids_ex1()
{        
    GETN_TREE(myTree)
    GETN_COMBO(numExp, "Number of Terms", 1, "1|2|3")    GETN_ID(ID_NUMEXP)
    
    GETN_BEGIN_BRANCH(DecayTime, "Decay Times") GETN_ID_BRANCH(ID_B)
        GETN_NUM(decayT1, "1st Decay Time (t1)", 0.0)    GETN_ID(ID_B_T1)
        GETN_NUM(decayT2, "2nd Decay Time (t2)", 0.0)    GETN_ID(ID_B_T2)
        GETN_NUM(decayT3, "3rd Decay Time (t3)", 0.0)    GETN_ID(ID_B_T3)
    GETN_END_BRANCH(DecayTime)
        
    GETN_RANGE(DataRange, "Data Range", 0, 99, 1, 30)    GETN_ID(ID_DATARANGE)
    
    GETN_COLOR(FitCurveColor, "Fit Curve color", 1)    GETN_ID(ID_CURVECOLOR)
    
    string  strFileName = "TreeNode.ini";
    vector<int> vnIDs;
    vector<string> vsValues;
    vector<string> vsLabels;
                
    if( tree_read_values_with_ids(strFileName, vnIDs, vsValues) )
        tree_set_values_by_ids(myTree, vnIDs, vsValues);
    
    if(GetNBox(myTree, "Fit Exp Decay", "Fit Exponential Decay 1,2,3"))
    {
        out_tree(myTree);
        tree_get_values_with_ids(myTree, vnIDs, vsValues);
        tree_save_values_with_ids(strFileName, vnIDs, vsValues, vsLabels);
    }
}

Remark

See Also

tree_set_values_by_nodeids

Header to Include

origin.h

Reference