本文整理汇总了C++中xml::Element::clone方法的典型用法代码示例。如果您正苦于以下问题:C++ Element::clone方法的具体用法?C++ Element::clone怎么用?C++ Element::clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml::Element
的用法示例。
在下文中一共展示了Element::clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateFromXMLNode
/* Handle reading older formats/Versioning */
void InverseDynamicsTool::updateFromXMLNode(SimTK::Xml::Element& aNode, int versionNumber)
{
int documentVersion = versionNumber;
if ( documentVersion < XMLDocument::getLatestVersion()){
std::string newFileName = getDocumentFileName();
if (documentVersion < 20300){
std::string origFilename = getDocumentFileName();
newFileName=IO::replaceSubstring(newFileName, ".xml", "_v23.xml");
cout << "Old version setup file encountered. Converting to new file "<< newFileName << endl;
SimTK::Xml::Document doc = SimTK::Xml::Document(origFilename);
doc.writeToFile(newFileName);
}
/*if (documentVersion < 20201) {
AnalyzeTool updateAnalyzeTool(newFileName, false);
updateAnalyzeTool.print(newFileName);
}*/
if (documentVersion < 20202){
// get filename and use SimTK::Xml to parse it
SimTK::Xml::Document doc = SimTK::Xml::Document(newFileName);
Xml::Element oldRoot = doc.getRootElement();
SimTK::Xml::Document newDoc;
string prefix = "";
if (oldRoot.getElementTag()=="AnalyzeTool"){
// Make OpenSimDocument node and copy root underneath it
newDoc.getRootElement().setElementTag("OpenSimDocument");
newDoc.getRootElement().setAttributeValue("Version", "20201");
prefix = oldRoot.getRequiredAttributeValueAs<string>("name");
// Move all children of root to toolNode
newDoc.getRootElement().insertNodeAfter(newDoc.getRootElement().node_end(), oldRoot.clone());
}
else
newDoc = doc;
Xml::Element root = newDoc.getRootElement();
if (root.getElementTag()=="OpenSimDocument"){
int curVersion = root.getRequiredAttributeValueAs<int>("Version");
if (curVersion <= 20201) root.setAttributeValue("Version", "20300");
Xml::element_iterator iterTool(root.element_begin("AnalyzeTool"));
iterTool->setElementTag("InverseDynamicsTool");
prefix = iterTool->getRequiredAttributeValueAs<string>("name");
// Remove children <output_precision>, <initial_time>, <final_time>
Xml::element_iterator initTimeIter(iterTool->element_begin("initial_time"));
double tool_initial_time = initTimeIter->getValueAs<double>();
if (initTimeIter->isValid()) iterTool->eraseNode(initTimeIter);
Xml::element_iterator finalTimeIter(iterTool->element_begin("final_time"));
double tool_final_time = finalTimeIter->getValueAs<double>();
if (finalTimeIter->isValid()) iterTool->eraseNode(finalTimeIter);
Xml::element_iterator precisionIter(iterTool->element_begin("output_precision"));
if (precisionIter->isValid()) iterTool->eraseNode(precisionIter);
bool use_model_forces=false;
// Handle missing or uninitialized values after parsing the old InverseDynamics "Analysis"
// Find Analyses underneath it AnalyzeTool
Xml::element_iterator iterAnalysisSet(iterTool->element_begin("AnalysisSet"));
Xml::element_iterator iterObjects(iterAnalysisSet->element_begin("objects"));
Xml::element_iterator iterAnalysis(iterObjects->element_begin("InverseDynamics"));
if (iterAnalysis!= iterObjects->element_end()){
// move children to top level
Xml::element_iterator p = iterAnalysis->element_begin();
//std::vector<std::string> deprectaed({"on", "in_degrees", "step_interval"});
for (; p!= iterAnalysis->element_end(); ++p) {
// skip <on>, <step_interval>, <in_degrees>
if (p->getElementTag()=="on" ||
p->getElementTag()=="in_degrees" ||
p->getElementTag()=="step_interval" ||
p->getElementTag()=="start_time" ||
p->getElementTag()=="end_time")
continue;
else if (p->getElementTag()=="use_model_force_set"){
String use_model_forcesStr = p->getValueAs<String>();
use_model_forces = (use_model_forcesStr=="true");
}
else
iterTool->insertNodeAfter( iterTool->node_end(), p->clone());
}
// insert elements for "forces_to_exclude" & "time_range"
std::ostringstream stream;
stream << tool_initial_time << " " << tool_final_time;
iterTool->insertNodeAfter( iterTool->node_end(), Xml::Element("time_range", stream.str()));
iterTool->insertNodeAfter( iterTool->node_end(), Xml::Element("forces_to_exclude", use_model_forces?"":"Muscles"));
iterTool->insertNodeAfter( iterTool->node_end(), Xml::Element("output_gen_force_file", prefix+"_InverseDynamics.sto"));
iterTool->insertNodeAfter( iterTool->node_end(), Xml::Element("coordinates_in_degrees", "true"));
iterTool->eraseNode(iterAnalysisSet);
}
newDoc.writeToFile(newFileName);
setDocument(new XMLDocument(newFileName));
aNode = updDocument()->getRootDataElement();
}
}
}
Object::updateFromXMLNode(aNode, versionNumber);
}