tree_get_attributes

 

Description

Walk tree and copy the specified attribute from all the nodes into given string vector. If the specified attribute does not exist for a node, it is considered as empty.

Syntax

void tree_get_attributes( TreeNode & tr, vector<string> & vs, LPCSTR lpcszAttribute, bool bSubNodeOnly = false )

Parameters

tr
[Input]TreeNode to walk
vs
[Output]a linearized array of attribute values that should map to every tree node
lpcszAttribute
[Input]the specified attribute to copy
bSubNodeOnly
[Input]true, only walk Sub Node; false, go through every tree node

Return

Examples

EX1

void tree_get_attributes_ex1()
{
    Tree tr;
    tr.First.nVal = 1;
    tr.Second.nVal = 2;
    tr.First.SetAttribute(STR_LABEL_ATTRIB, "The First One");
    tr.Second.SetAttribute(STR_LABEL_ATTRIB, "The Second One");
    vector<string> vsAttribs;
    tree_get_attributes(tr, vsAttribs, STR_LABEL_ATTRIB);
    
    printf("Tree attributes:\n");
    for(int ii=0;ii<vsAttribs.GetSize();ii++)
        printf("%s\n",vsAttribs[ii]);
}

Remark

See Also

header to Include

origin.h

Reference