当前位置: 首页>>代码示例>>C++>>正文


C++ Composite::set_root方法代码示例

本文整理汇总了C++中Composite::set_root方法的典型用法代码示例。如果您正苦于以下问题:C++ Composite::set_root方法的具体用法?C++ Composite::set_root怎么用?C++ Composite::set_root使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Composite的用法示例。


在下文中一共展示了Composite::set_root方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Composite

/** Currently not used. Need to check whether all data should be copied or just pointers. 
 Current code only copies the pointers **/
Composite * Composite::copy(){
    Composite * copy = new Composite();
    
    printf("Composite::copy 1\n");
    std::map<CompositeBranchContainer *,CompositeBranchContainer *> new_to_old_map;
    std::map<CompositeBranchContainer *,CompositeBranchContainer *> old_to_new_map;
    
    printf("Composite::copy  creating new branches\n");
    for (CompositeBranchContainer * branch : get_branches()){
        CompositeBranchContainer * branch_copy = new CompositeBranchContainer(branch);
        new_to_old_map[branch_copy] = branch;
        old_to_new_map[branch] = branch_copy;
        copy->add_branch(branch_copy);
    }
    //for (CompositeBranchContainer * new_branch : branches){
    // Create parent/child pointers
    printf("Composite::copy connecting branches\n");
    int count = 0;
    for (std::map<CompositeBranchContainer *,CompositeBranchContainer *>::iterator it = new_to_old_map.begin(); it != new_to_old_map.end(); ++it){
        CompositeBranchContainer * new_branch = it->first;
        CompositeBranchContainer * orig_branch = it->second;
        //CompositeBranchContainer * orig_branch = new_to_old_map[new_branch];
        CompositeBranchContainer * orig_parent = orig_branch->get_parent();
        
        count++;
        //printf("Branch connecting %d; orig_parent %p\n",count,orig_parent);
        
        if (orig_parent){
            CompositeBranchContainer * new_parent = old_to_new_map[orig_parent];
            // Make child->parent connection
            new_branch->set_parent(new_parent);

            // Copy parent-side decision points
            if (new_parent->get_decision_point2()){
                // When the copied decision point already exists
                new_branch->set_decision_point1(new_parent->get_decision_point2());
            }else{
                DecisionPoint * dp_copy = new DecisionPoint(orig_branch->get_decision_point1());
                new_branch->set_decision_point1(dp_copy);
                decision_points.push_back(dp_copy);
            }
        }else{
            // No parent, so this branch must be the root
            printf("setting root\n");
            copy->set_root(new_branch);
        }
        // Copy child-side decision point (if it isn't a certain terminal branch)
        if (orig_branch->get_decision_point2()){
            //printf("copying dp2 %p\n",orig_branch->get_decision_point2());
            DecisionPoint * dp_copy = new DecisionPoint(orig_branch->get_decision_point2());
            new_branch->set_decision_point2(dp_copy);
            decision_points.push_back(dp_copy);
        }
    }
    printf("Done making copy\n");
    
    return copy;
}
开发者ID:CBL-ORION,项目名称:vaa3d_tools,代码行数:60,代码来源:Composite.cpp


注:本文中的Composite::set_root方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。