@@ -118,15 +118,15 @@ struct XMLParser::PImpl
118118 std::list<std::unique_ptr<XMLDocument> > opened_documents;
119119 std::map<std::string, const XMLElement*> tree_roots;
120120
121- const BehaviorTreeFactory& factory;
121+ const BehaviorTreeFactory* factory = nullptr ;
122122
123123 std::filesystem::path current_path;
124124 std::map<std::string, SubtreeModel> subtree_models;
125125
126- int suffix_count;
126+ int suffix_count = 0 ;
127127
128128 explicit PImpl (const BehaviorTreeFactory& fact)
129- : factory(fact), current_path(std::filesystem::current_path()), suffix_count( 0 )
129+ : factory(& fact), current_path(std::filesystem::current_path())
130130 {}
131131
132132 void clear ()
@@ -162,7 +162,7 @@ XMLParser::~XMLParser()
162162
163163void XMLParser::loadFromFile (const std::filesystem::path& filepath, bool add_includes)
164164{
165- _p->opened_documents .emplace_back ( new XMLDocument ());
165+ _p->opened_documents .push_back (std::make_unique< XMLDocument> ());
166166
167167 XMLDocument* doc = _p->opened_documents .back ().get ();
168168 doc->LoadFile (filepath.string ().c_str ());
@@ -174,7 +174,7 @@ void XMLParser::loadFromFile(const std::filesystem::path& filepath, bool add_inc
174174
175175void XMLParser::loadFromText (const std::string& xml_text, bool add_includes)
176176{
177- _p->opened_documents .emplace_back ( new XMLDocument ());
177+ _p->opened_documents .push_back (std::make_unique< XMLDocument> ());
178178
179179 XMLDocument* doc = _p->opened_documents .back ().get ();
180180 doc->Parse (xml_text.c_str (), xml_text.size ());
@@ -311,7 +311,7 @@ void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes)
311311 file_path = current_path / file_path;
312312 }
313313
314- opened_documents.emplace_back ( new XMLDocument ());
314+ opened_documents.push_back (std::make_unique< XMLDocument> ());
315315 XMLDocument* next_doc = opened_documents.back ().get ();
316316
317317 // change current path to the included file for handling additional relative paths
@@ -327,7 +327,7 @@ void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes)
327327
328328 // Collect the names of all nodes registered with the behavior tree factory
329329 std::unordered_map<std::string, BT::NodeType> registered_nodes;
330- for (const auto & it : factory. manifests ())
330+ for (const auto & it : factory-> manifests ())
331331 {
332332 registered_nodes.insert ({ it.first , it.second .type });
333333 }
@@ -629,7 +629,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
629629 {
630630 // This is the case of nodes like <MyCustomAction>
631631 // check if the factory has this name
632- if (factory. builders ().count (element_name) == 0 )
632+ if (factory-> builders ().count (element_name) == 0 )
633633 {
634634 throw RuntimeError (element_name, " is not a registered node" );
635635 }
@@ -657,8 +657,8 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
657657
658658 const TreeNodeManifest* manifest = nullptr ;
659659
660- auto manifest_it = factory. manifests ().find (type_ID);
661- if (manifest_it != factory. manifests ().end ())
660+ auto manifest_it = factory-> manifests ().find (type_ID);
661+ if (manifest_it != factory-> manifests ().end ())
662662 {
663663 manifest = &manifest_it->second ;
664664 }
@@ -758,7 +758,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
758758 {
759759 config.input_ports = port_remap;
760760 new_node =
761- factory. instantiateTreeNode (instance_name, toStr (NodeType::SUBTREE), config);
761+ factory-> instantiateTreeNode (instance_name, toStr (NodeType::SUBTREE), config);
762762 auto subtree_node = dynamic_cast <SubTreeNode*>(new_node.get ());
763763 subtree_node->setSubtreeID (type_ID);
764764 }
@@ -873,7 +873,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
873873 }
874874 }
875875
876- new_node = factory. instantiateTreeNode (instance_name, type_ID, config);
876+ new_node = factory-> instantiateTreeNode (instance_name, type_ID, config);
877877 }
878878
879879 // add the pointer of this node to the parent
@@ -1517,25 +1517,6 @@ std::string writeTreeXSD(const BehaviorTreeFactory& factory)
15171517 return std::string (printer.CStr (), size_t (printer.CStrSize () - 1 ));
15181518}
15191519
1520- namespace
1521- {
1522- Tree buildTreeFromText (const BehaviorTreeFactory& factory, const std::string& text,
1523- const Blackboard::Ptr& blackboard)
1524- {
1525- XMLParser parser (factory);
1526- parser.loadFromText (text);
1527- return parser.instantiateTree (blackboard);
1528- }
1529-
1530- Tree buildTreeFromFile (const BehaviorTreeFactory& factory, const std::string& filename,
1531- const Blackboard::Ptr& blackboard)
1532- {
1533- XMLParser parser (factory);
1534- parser.loadFromFile (filename);
1535- return parser.instantiateTree (blackboard);
1536- }
1537- } // namespace
1538-
15391520std::string WriteTreeToXML (const Tree& tree, bool add_metadata, bool add_builtin_models)
15401521{
15411522 XMLDocument doc;
0 commit comments