本文整理汇总了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;
}