2.1.26.27 tree_copy_values_to_attributes 
 
Description
copy value to attributes from tree to tree by specific attribute value matching
 
Syntax
bool tree_copy_values_to_attributes( TreeNode & trSrc, TreeNode & trDest, LPCSTR lpcsz2ndAttributeToTransfer = NULL, LPCSTR lpcszDestAttribute = NULL, LPCSTR lpcszAttributeToMatch = NULL, bool bRecursive = true, bool bAllMatched = true, bool bCaseSensitive = false ) 
Parameters
-  trSrc
 
- [input]Source TreeNode copy from
 
-  trDest
 
- [modify]TreeNode copied to
 
-  lpcsz2ndAttributeToTransfer
 
- [input]in addition to transfer value to attribute, there is also an option to transfer an attribute from source to destination
 
-  lpcszDestAttribute
 
- [input]The attribute of target that copy source value to, if NULL, then STR_SHOW_ATTRIB is assumed
 
-  lpcszAttributeToMatch
 
- [input]Match attribute and its value to copy, if NULL, then STR_DATAID_ATTRIB is assumed
 
-  bRecursive
 
- [input]true, go through all the tree node in trSrc;
 
- false, just go through the Children of trSrc
 
-  bAllMatched
 
- [input]true, apply to all the match node in trDest;
 
- false, only apply to 1st matched in trDest
 
-  bCaseSensitive
 
- [input]true, compare the attribute value case sensitive
 
- false, not case sensitive
  
Return
false if copy none
 
Examples
EX1
 
void tree_copy_values_to_attributes_ex1()
{
    Tree tr;
    TreeNode trSrc, trDest;
    trSrc = tr.AddNode("Math");
    trSrc.Score.strVal = "0";
    trSrc.Score.SetAttribute(STR_DATAID_ATTRIB, "1");
    
    trSrc.Bookname.strVal = "1";
    trSrc.Bookname.SetAttribute(STR_DATAID_ATTRIB, "2");
    
    trDest = tr.AddNode("English");
    trDest.Score.strVal = "90.5";
    trDest.Score.SetAttribute(STR_DATAID_ATTRIB, "1");    
    
    trDest.Bookname.strVal = "English 1";    
    trDest.Bookname.SetAttribute(STR_DATAID_ATTRIB, "2");    
    
    //Copy values {0, 1} from trSrc to the Show attribute of the trDest by matching DataID attribute
    bool bRet = tree_copy_values_to_attributes(trSrc, trDest);
    ASSERT( 0 == trDest.Score.Show);  //copy value 0 form trSrc to the Show attribute of Score matched by DataID
    ASSERT( 1 == trDest.Bookname.Show);     //copy value 1 from trDest to the Show attribute of Bookname matched by DataID
}
Remark
See Also
Header to Include
origin.h
 
Reference
             |