tree_count_items_by_attribute

 

Description

Count all node number of the given tree by attribute or attribute and value.

Syntax

int tree_count_items_by_attribute( TreeNode & tr, LPCSTR lpcszAttribute = NULL, LPCSTR lpcszValue = NULL, bool bMissingIsMatch = true, bool bRecursive = true )

Parameters

tr
[Input] TreeNode to count
lpcszAttribute
[Input] if given, then count the number of the tree that contain the attribute;
else count all subnode
lpcszValue
[Input] if given, then count the number of attribute lpcszAttribute value equal to this;
else just count the node with attribute
bMissingIsMatch
[Input] used only if both lpcszAttribute and lpcszValue are given, and when set to true,
then if node dose not have the attribute, consider it has attribute with specified value
bRecursive
[input]true, go through all the tree node in tr;
false, just go through the Children of tr

Return

total number of sub nodes with attribute or all sub nodes.

Examples

EX1

void tree_count_items_by_attribute_ex1()
{
    Tree tr;
    tr.Math.Grade.dVal = 90.5;
    tr.DataID = 12;
    tr.Math.DataID = 13;
    tr.English.Grade.dVal = 95.5;
    tr.English.Grade.DataID = 12;
    tr.Math.Bookname.strVal = "Advanced Math";
    tr.Math.Bookname.DataID = 12;
    tr.English.Bookname.strVal = "English 1";
    
    int nCount = tree_count_items_by_attribute(tr); 
    ASSERT(nCount == 6);
    int nSections;
    nCount = tree_count_items_by_attribute(tr, STR_DATAID_ATTRIB, "12");
}

Remark

See Also

tree_count_items

header to Include

origin.h

Reference