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

Function detectMainTreeId

src/bt_factory.cpp:32–54  ·  view source on GitHub ↗

Extract the main tree ID from an XML root element. Checks main_tree_to_execute attribute first, then falls back to the single BehaviorTree ID if only one is defined.

Source from the content-addressed store, hash-verified

30// Checks main_tree_to_execute attribute first, then falls back to the
31// single BehaviorTree ID if only one is defined.
32std::string detectMainTreeId(const tinyxml2::XMLElement* xml_root)
33{
34 if(const auto* attr = xml_root->Attribute("main_tree_to_execute"))
35 {
36 return attr;
37 }
38 int bt_count = 0;
39 std::string single_id;
40 for(const auto* bt_elem = xml_root->FirstChildElement("BehaviorTree");
41 bt_elem != nullptr; bt_elem = bt_elem->NextSiblingElement("BehaviorTree"))
42 {
43 bt_count++;
44 if(const auto* tree_id = bt_elem->Attribute("ID"))
45 {
46 single_id = tree_id;
47 }
48 }
49 if(bt_count == 1 && !single_id.empty())
50 {
51 return single_id;
52 }
53 return {};
54}
55
56// Load XML into parser and resolve which tree to instantiate.
57// Returns the resolved tree ID (may be empty if parser should use default).

Callers 2

createTreeFromTextMethod · 0.85
createTreeFromFileMethod · 0.85

Calls 4

AttributeMethod · 0.80
FirstChildElementMethod · 0.80
NextSiblingElementMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected