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

Method loadDocImpl

src/xml_parsing.cpp:341–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339}
340
341void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes)
342{
343 if(doc->Error())
344 {
345 char buffer[512];
346 std::ignore =
347 snprintf(buffer, sizeof buffer, "Error parsing the XML: %s", doc->ErrorStr());
348 throw RuntimeError(buffer);
349 }
350
351 const XMLElement* xml_root = doc->RootElement();
352 if(xml_root == nullptr)
353 {
354 throw RuntimeError("Invalid XML: missing root element");
355 }
356
357 auto format = xml_root->Attribute("BTCPP_format");
358 if(format == nullptr)
359 {
360 std::cout << "Warnings: The first tag of the XML (<root>) should contain the "
361 "attribute [BTCPP_format=\"4\"]\n"
362 << "Please check if your XML is compatible with version 4.x of BT.CPP"
363 << std::endl;
364 }
365
366 // recursively include other files
367 for(auto incl_node = xml_root->FirstChildElement("include"); incl_node != nullptr;
368 incl_node = incl_node->NextSiblingElement("include"))
369 {
370 if(!add_includes)
371 {
372 break;
373 }
374
375 const char* path_attr = incl_node->Attribute("path");
376 if(path_attr == nullptr)
377 {
378 throw RuntimeError("Invalid <include> tag: missing 'path' attribute");
379 }
380
381#if __bt_cplusplus >= 202002L
382 auto file_path{ std::filesystem::path(path_attr) };
383#else
384 auto file_path{ std::filesystem::u8path(path_attr) };
385#endif
386
387 const char* ros_pkg_relative_path = incl_node->Attribute("ros_pkg");
388
389 if(ros_pkg_relative_path != nullptr)
390 {
391 if(file_path.is_absolute())
392 {
393 std::cout << "WARNING: <include path=\"...\"> contains an absolute path.\n"
394 << "Attribute [ros_pkg] will be ignored." << std::endl;
395 }
396 else
397 {
398 std::string ros_pkg_path; // NOLINT(misc-const-correctness)

Callers 2

loadFromFileMethod · 0.80
loadFromTextMethod · 0.80

Calls 13

RuntimeErrorClass · 0.85
stringFunction · 0.85
VerifyXMLFunction · 0.85
ErrorStrMethod · 0.80
AttributeMethod · 0.80
FirstChildElementMethod · 0.80
NextSiblingElementMethod · 0.80
push_backMethod · 0.80
LoadFileMethod · 0.80
PrintMethod · 0.80
to_stringFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected