| 1342 | } |
| 1343 | |
| 1344 | void 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 | } |
no test coverage detected