tree_rename_tags

 

Description

Change all subnodes's tagnames in tree

Syntax

bool tree_rename_tags( TreeNode & trRoot, const StringArray & saOldTagNames, const StringArray & saNewTagNames )

Parameters

trRoot
[input/output] treenode to check and update
saOldTagNames
[input] tagnames list want to be replaced
saNewTagNames
[input] new tagnames list
trRoot's tagname will not be changed
tagname must be pair. New one will replace old one. they are linked by array index on saOlderTagNames and saNewerTagNames

Return

true on success, false on failed or trRoot is invalid

Examples

EX1

#include <GetNBox.h>
void tree_rename_tags_ex1()
{
    Tree tree;

    GETN_USE(tree)
        GETN_NUM(node1, "", 0)
        GETN_BEGIN_BRANCH(branch1, "")
            GETN_NUM(node2, "", 0)
            GETN_NUM(node3, "", 0)
            GETN_BEGIN_BRANCH(branch2, "")
                GETN_NUM(node4, "", 0)
                GETN_NUM(node5, "", 0)
            GETN_END_BRANCH(branch2)
        GETN_END_BRANCH(branch1)
        GETN_BEGIN_BRANCH(branch3, "")
            GETN_NUM(node6, "", 0)
            GETN_BEGIN_BRANCH(branch4, "")
                GETN_NUM(node7, "", 0)
                GETN_NUM(node8, "", 0)
            GETN_END_BRANCH(branch4)
            GETN_NUM(node9, "", 0)
        GETN_END_BRANCH(branch3)
        GETN_BEGIN_BRANCH(branch5, "")
            GETN_BEGIN_BRANCH(branch6, "")
                GETN_NUM(node10, "", 0)
                GETN_NUM(node11, "", 0)
            GETN_END_BRANCH(branch6)
            GETN_NUM(node12, "", 0)
            GETN_NUM(node13, "", 0)
        GETN_END_BRANCH(branch5)
    
    StringArray saOlder = {"node1", "node2", "node3", "node4", "node5", "node6", "node7", "node8", "node9", "node10", "node11", "node12", "node13"
                        , "branch1", "branch2", "branch3", "branch4", "branch5", "branch6"};
    StringArray saNewer = {"_node1", "_node2", "_node3", "_node4", "_node5", "_node6", "_node7", "_node8", "_node9", "_node10", "_node11", "_node12", "_node13"
                        , "_branch1", "_branch2", "_branch3", "_branch4", "_branch5", "_branch6"};
            
    tree_remove_attribute(tree, STR_LABEL_ATTRIB); // for only display tagname 
    out_tree(tree);
    tree_rename_tags(tree, saOlder, saNewer);
    out_tree(tree);
}

Remark

See Also

header to Include

origin.h

Reference