2.2.3.17.6 TreeNode::CreateDiff


Version

Description

Construct a new tree that collects all the tree nodes that are different between the two given.

Syntax

int CreateDiff( const TreeNode & tnTarget, const TreeNode & tnRef, DWORD dwCntrl = 0, int nRealPrecision = 0, LPCSTR lpcszAttribs = NULL )

Parameters

tnTarget
[input]
TreeNode to compare
tnRef
[input]
TreeNode for reference
dwCntrl
[input]
TRDIFF_CHK_ATTRIB compare both value and attribute
TRDIFF_KEEP_INDIVI_TARGET consider diff if node missing in tnRef but exsits in tnTarget,
if TRDIFF_KEEP_REF_VALUES set, a attribute named STR_TRDIFF_REF_VALUE_ATTRIB will be set, and the attribute value is Empty
TRDIFF_KEEP_INDIVI_REF consider diff if node missing in tnTarget but exists in tnRef
if TRDIFF_KEEP_REF_VALUES set, values will be kept as attribute named STR_TRDIFF_REF_VALUE_ATTRIB, otherwise they will be kept as value
TRDIFF_KEEP_BRANCH_NO_LEAF keep such branch even if no any childens diff, etc. category branch
TRDIFF_KEEP_REF_VALUES keep the values in tnRef as attribute(named STR_TRDIFF_REF_VALUE_ATTRIB) if the node's value is different from the value of the corresponding node in tnTarget
TRDIFF_BY_NODE_INDEX check diff by index of children node
nRealPrecision
[input] for compare double value
default: 0, means origin default
-1, means full precision
lpcszAttribs
[input] specify one or more attributes to compare
must enable TRDIFF_CHK_ATTRIB first

Return

-1 if error, like tnTarget or tnRef invalid

0 if no diff

>0 for number of diff nodes found

Examples

EX1

void test_create_diff_ex1()
{
    Tree tr1;
    tr1.node1.nVal = 1;
    tr1.node2.nVal = 1;
    tr1.node2.SetAttribute("attrib1", 1);
    tr1.node2.SetAttribute("attrib2", 1);
    tr1.branch.node21.dVal = 12.3333333;
    tr1.branch.node22.dVal = 12.3333333;
    tr1.branch.node23.strVal = "abc";
    
    
    Tree tr2;
    tr2.node10.nVal = 1;
    tr2.node2.SetAttribute("attrib1", 1);
    tr2.node2.SetAttribute("attrib2", 2);
    tr2.node2.nVal = 1;
    tr2.branch.node21.dVal = 12.333456;
    tr2.branch.node22.dVal = 12.343333;
    tr2.branch.node23.strVal = "edf";
    
    Tree trDiff;
    trDiff.CreateDiff(tr1, tr2, TRDIFF_KEEP_INDIVI_TARGET | TRDIFF_CHK_ATTRIB, 4, "attrib1|attrib2");
    
    out_tree(tr1);
    out_tree(tr2);
    out_tree(trDiff);
    ASSERT(trDiff.node1.nVal == 1);
    ASSERT(trDiff.node2.nVal == 1);
    ASSERT(trDiff.branch.node22.dVal == 12.3333333);
    ASSERT(trDiff.branch.node23.strVal == "abc");
}

Remark

See Also

Header to Included

origin.h