MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / addTreeToXML

Function addTreeToXML

src/xml_parsing.cpp:1344–1438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1342}
1343
1344void addTreeToXML(const Tree& tree, XMLDocument& doc, XMLElement* rootXML,
1345 bool add_metadata, bool add_builtin_models)
1346{
1347 std::function<void(const TreeNode&, XMLElement*)> addNode;
1348 addNode = [&](const TreeNode& node, XMLElement* parent_elem) {
1349 XMLElement* elem = nullptr;
1350
1351 if(const auto* subtree = dynamic_cast<const SubTreeNode*>(&node))
1352 {
1353 elem = doc.NewElement(node.registrationName().c_str());
1354 elem->SetAttribute("ID", subtree->subtreeID().c_str());
1355 if(add_metadata)
1356 {
1357 elem->SetAttribute("_fullpath", subtree->config().path.c_str());
1358 }
1359 }
1360 else
1361 {
1362 elem = doc.NewElement(node.registrationName().c_str());
1363 elem->SetAttribute("name", node.name().c_str());
1364 }
1365
1366 if(add_metadata)
1367 {
1368 elem->SetAttribute("_uid", node.UID());
1369 }
1370
1371 for(const auto& [name, value] : node.config().input_ports)
1372 {
1373 elem->SetAttribute(name.c_str(), value.c_str());
1374 }
1375 for(const auto& [name, value] : node.config().output_ports)
1376 {
1377 // avoid duplicates, in the case of INOUT ports
1378 if(node.config().input_ports.count(name) == 0)
1379 {
1380 elem->SetAttribute(name.c_str(), value.c_str());
1381 }
1382 }
1383
1384 for(const auto& [pre, script] : node.config().pre_conditions)
1385 {
1386 elem->SetAttribute(toStr(pre).c_str(), script.c_str());
1387 }
1388 for(const auto& [post, script] : node.config().post_conditions)
1389 {
1390 elem->SetAttribute(toStr(post).c_str(), script.c_str());
1391 }
1392
1393 parent_elem->InsertEndChild(elem);
1394
1395 if(const auto* control = dynamic_cast<const ControlNode*>(&node))
1396 {
1397 for(const auto& child : control->children())
1398 {
1399 addNode(*child, elem);
1400 }
1401 }

Callers 1

WriteTreeToXMLFunction · 0.85

Calls 9

addNodeModelToXMLFunction · 0.85
NewElementMethod · 0.80
SetAttributeMethod · 0.80
UIDMethod · 0.80
InsertEndChildMethod · 0.80
toStrFunction · 0.70
nameMethod · 0.45
typeMethod · 0.45
childMethod · 0.45

Tested by

no test coverage detected