2.1.26.51 tree_get_values_with_ids_and_labels


Description

Get sub node values with IDs and Labels.

Syntax

int tree_get_values_with_ids_and_labels( const TreeNode & trSetting, vector<int> & vnIDs, vector<string> & vsValues, vector<string> & vsLabels, bool bIncludeSub = true, bool bCheckChange = false, int nRepeatBranchID = 0 )

Parameters

trSetting
[input] a source tree
vnIDs
[output]vector of IDs from tr.
vsValues
[output]vector of strVals from tr.
vsLabels
[output] vector of Label strings in the TreeNode trSetting.
bIncludeSub
[input]TRUE or FALSE, if bIncludeSub == TRUE, this function will go through all tree node;
if not, will just go through the first level.
bCheckChange
[input] if true, will check the treenode change or not.
nRepeatBranchID
[input] DataID of parent or itself, must > 0 and < MAX_REPEAT_ID_VALUE.

Return

the number of the node have ID

-1 mean the treenode invalid,

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

Examples

EX1

void tree_get_values_with_ids_and_labels_ex1()
{
	Tree myTree;
	TreeNode tn1, tn2;
	tn1 = myTree.AddTextNode("a", "tn1", 1);
	tn1.SetAttribute(STR_DATAID_ATTRIB, 1);
	
	tn2 = myTree.AddTextNode("b", "tn2", 2);
	tn2.SetAttribute(STR_DATAID_ATTRIB, 2);

	TreeNode tn11, tn12;
	tn11 = tn1.AddTextNode("c", "tn11", 3);
	tn11.SetAttribute(STR_DATAID_ATTRIB, 3);

	tn12 = tn1.AddTextNode("d", "tn12", 4);
	tn12.SetAttribute(STR_DATAID_ATTRIB, 4);

	TreeNode tn111, tn112;
	tn111 = tn11.AddTextNode("e", "tn111", 5);
	tn111.SetAttribute(STR_DATAID_ATTRIB, 5);

	tn112 = tn11.AddTextNode("f", "tn112", 6);
	tn112.SetAttribute(STR_DATAID_ATTRIB, 6);

	
	vector<int> vnIDs;
	vector<string> vsValues;
	vector<string> vsLabels;
	
	int nn = tree_get_values_with_ids_and_labels(myTree, vnIDs, vsValues, vsLabels);
	out_int("nn = ", nn);
	int nSize = vnIDs.GetSize();
	for( int ii = 0; ii < nSize; ii++ )
	{ 
		out_int("ID: ", vnIDs[ii]);
	}
	
	nSize = vsValues.GetSize();
	for( ii = 0; ii < nSize; ii++ )
	{
		out_str(vsValues[ii]);
	}
	
	nSize = vsLabels.GetSize();
	for( ii = 0; ii < nSize; ii++ )
	{
		out_str(vsLabels[ii]);
	}
}

Remark

See Also

tree_get_values_with_ids

Header to Include

origin.h

Reference