00001 #ifndef XML_PARSING_BT_H 00002 #define XML_PARSING_BT_H 00003 00004 #include "behaviortree_cpp/bt_factory.h" 00005 00006 namespace BT 00007 { 00008 class XMLParser 00009 { 00010 public: 00011 XMLParser(const BehaviorTreeFactory& factory); 00012 00013 ~XMLParser(); 00014 00015 XMLParser(const XMLParser& other) = delete; 00016 XMLParser& operator=(const XMLParser& other) = delete; 00017 00018 void loadFromFile(const std::string& filename); 00019 00020 void loadFromText(const std::string& xml_text); 00021 00022 TreeNode::Ptr instantiateTree(std::vector<TreeNode::Ptr>& nodes, const Blackboard::Ptr &blackboard); 00023 00024 private: 00025 00026 struct Pimpl; 00027 Pimpl* _p; 00028 00029 }; 00030 00031 struct Tree 00032 { 00033 TreeNode* root_node; 00034 std::vector<TreeNode::Ptr> nodes; 00035 00036 Tree() : root_node(nullptr) 00037 { 00038 00039 } 00040 00041 Tree(TreeNode* root_node, std::vector<TreeNode::Ptr> nodes) 00042 : root_node(root_node), nodes(nodes) 00043 { 00044 00045 } 00046 00047 ~Tree() 00048 { 00049 if (root_node) { 00050 haltAllActions(root_node); 00051 } 00052 } 00053 }; 00054 00062 Tree buildTreeFromText(const BehaviorTreeFactory& factory, 00063 const std::string& text, 00064 const Blackboard::Ptr& blackboard = Blackboard::Ptr()); 00065 00073 Tree buildTreeFromFile(const BehaviorTreeFactory& factory, 00074 const std::string& filename, 00075 const Blackboard::Ptr& blackboard = Blackboard::Ptr()); 00076 00077 std::string writeXML(const BehaviorTreeFactory& factory, const TreeNode* root_node, 00078 bool compact_representation = false); 00079 } 00080 00081 #endif // XML_PARSING_BT_H