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

Method instantiateTree

src/xml_parsing.cpp:697–735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

695}
696
697Tree XMLParser::instantiateTree(const Blackboard::Ptr& root_blackboard,
698 std::string main_tree_ID)
699{
700 Tree output_tree;
701
702 // use the main_tree_to_execute argument if it was provided by the user
703 // or the one in the FIRST document opened
704 if(main_tree_ID.empty())
705 {
706 XMLElement* first_xml_root = _p->opened_documents.front()->RootElement();
707
708 if(auto main_tree_attribute = first_xml_root->Attribute("main_tree_to_execute"))
709 {
710 main_tree_ID = main_tree_attribute;
711 }
712 else if(_p->tree_roots.size() == 1)
713 {
714 // special case: there is only one registered BT.
715 main_tree_ID = _p->tree_roots.begin()->first;
716 }
717 else
718 {
719 throw RuntimeError("[main_tree_to_execute] was not specified correctly");
720 }
721 }
722
723 //--------------------------------------
724 if(!root_blackboard)
725 {
726 throw RuntimeError("XMLParser::instantiateTree needs a non-empty "
727 "root_blackboard");
728 }
729
730 std::unordered_set<std::string> ancestors;
731 _p->recursivelyCreateSubtree(main_tree_ID, {}, {}, output_tree, root_blackboard,
732 TreeNode::Ptr(), ancestors);
733 output_tree.initialize();
734 return output_tree;
735}
736
737void XMLParser::clearInternalState()
738{

Callers 3

createTreeFromTextMethod · 0.80
createTreeFromFileMethod · 0.80
createTreeMethod · 0.80

Calls 7

RuntimeErrorClass · 0.85
AttributeMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
initializeMethod · 0.45

Tested by

no test coverage detected