本文整理汇总了C++中BodyPart::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ BodyPart::addChild方法的具体用法?C++ BodyPart::addChild怎么用?C++ BodyPart::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BodyPart
的用法示例。
在下文中一共展示了BodyPart::addChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadBody
//.........这里部分代码省略.........
else if (!strcmp(_name,"blood_flow")){ blood_flow = atof(attr->value()); }
else if (!strcmp(_name,"resistance")){ resistance = atof(attr->value()); }
else if (!strcmp(_name,"impairment")){ impairment = atof(attr->value()); }
}
debug_print("Read Tissue:\n\tID: %s \n\tName: %s \n\tBlood Flow: %f \n\tResistance: %f \n\tImpairment: %f\n",
id, name, blood_flow, resistance, impairment);
//Create a new Tissue and store the shared pointer to it in the tissue map
boost::shared_ptr<Tissue> t_tissue(new Tissue(id, name, pain, blood_flow, resistance, impairment));
tissue_map->insert(std::pair<std::string, boost::shared_ptr<Tissue>>(std::string(id), t_tissue));
}
//###BODYPART DATA###
//maps for child linking and organ linking
//K: UUID of the child, V: UUID of the parent
std::map<string, string>* child_map = new std::map<string, string>();
//K: UUID of the organ, V: IID(!) of its connector
std::map<string, string>* organ_link_map = new std::map<string, string>();
//Load the bodypart data (First first_node() is "body_def",
// data starts with the second level "body"
xml_node<> *body = doc.first_node()->first_node("body");
string root_uuid = enter(body->first_node(), child_map, organ_link_map);
//Destroy the XML data in memory
delete[] buffer;
//Build IID<->UUID map, which is required for linking
makeIdMap();
//Link children and organs
for (std::map<string, string>::iterator ch_it = child_map->begin();
ch_it != child_map->end(); ch_it++)
{
if (getPartByUUID(ch_it->first) == nullptr)
{
debug_error("ERROR during body part linking: Part UUID %s was requested, but is not in part map!\n",
ch_it->first.c_str());
return nullptr;
}
if (getPartByUUID(ch_it->second) == nullptr)
{
debug_error("ERROR during body part linking: Part UUID %s was requested, but is not in part map!\n",
ch_it->second.c_str());
return nullptr;
}
BodyPart* parent = dynamic_cast<BodyPart*>(getPartByUUID(ch_it->second).get());
if (parent == nullptr)
{
debug_error("ERROR during body part linking: Casting from Part* to BodyPart* on Part %s failed!\n",
ch_it->second.c_str());
return nullptr;
}
parent->addChild(ch_it->first);
}
for (std::map<string, string>::iterator or_it = organ_link_map->begin();
or_it != organ_link_map->end(); or_it++)
{
if (getPartByUUID(or_it->first) == nullptr)
{
debug_error("ERROR during body part linking: Part UUID %s was requested, but is not in part map!\n",
or_it->first.c_str());
return nullptr;
}
if (getPartByIID(or_it->second) == nullptr)
{
debug_error("ERROR during body part linking: Part IID %s was requested, but is not in part map!\n",
or_it->second.c_str());
return nullptr;
}
Part* temp = getPartByIID(or_it->second).get();
Organ* connector = dynamic_cast<Organ*>(temp);
if (connector == nullptr){
debug_error("ERROR during body part linking: Casting from Part* to Organ* on Part %s failed!\n",
or_it->second.c_str());
return nullptr;
}
connector->addConnectedOrgan(or_it->first);
}
//Successfully parsed the body definition file!
//Return the address of the newly created body part.
return root_uuid;
} catch (std::exception& e) {
debug_error("ERROR: %s \n", e.what());
return NULL;
}
catch (bdef_parse_error& pe) {
debug_error("ERROR: %s \n", pe.what());
return NULL;
}
return NULL;
}