BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
xml_parsing.h
1#ifndef XML_PARSING_BT_H
2#define XML_PARSING_BT_H
3
4#include "behaviortree_cpp/bt_parser.h"
5
6#include <filesystem>
7#include <unordered_map>
8
9namespace BT
10{
11/**
12 * @brief The XMLParser is a class used to read the model
13 * of a BehaviorTree from file or text and instantiate the
14 * corresponding tree using the BehaviorTreeFactory.
15 */
16class XMLParser : public Parser
17{
18public:
19 XMLParser(const BehaviorTreeFactory& factory);
20
21 ~XMLParser() override;
22
23 XMLParser(const XMLParser& other) = delete;
24 XMLParser& operator=(const XMLParser& other) = delete;
25
26 XMLParser(XMLParser&& other) noexcept;
27 XMLParser& operator=(XMLParser&& other) noexcept;
28
29 void loadFromFile(const std::filesystem::path& filename,
30 bool add_includes = true) override;
31
32 void loadFromText(const std::string& xml_text, bool add_includes = true) override;
33
34 [[nodiscard]] std::vector<std::string> registeredBehaviorTrees() const override;
35
36 [[nodiscard]] Tree instantiateTree(const Blackboard::Ptr& root_blackboard,
37 std::string main_tree_to_execute = {}) override;
38
39 void clearInternalState() override;
40
41private:
42 struct PImpl;
43 std::unique_ptr<PImpl> _p;
44};
45
46void VerifyXML(const std::string& xml_text,
47 const std::unordered_map<std::string, NodeType>& registered_nodes);
48
49/**
50 * @brief writeTreeNodesModelXML generates an XMl that contains the manifests in the
51 * <TreeNodesModel>
52 *
53 * @param factory the factory with the registered types
54 * @param include_builtin if true, include the builtin Nodes
55 *
56 * @return string containing the XML.
57 */
58[[nodiscard]] std::string writeTreeNodesModelXML(const BehaviorTreeFactory& factory,
59 bool include_builtin = false);
60
61/**
62 * @brief writeTreeXSD generates an XSD for the nodes defined in the factory
63 *
64 * @param factory the factory with the registered types
65 *
66 * @return string containing the XML.
67 */
68[[nodiscard]] std::string writeTreeXSD(const BehaviorTreeFactory& factory);
69
70/**
71 * @brief WriteTreeToXML create a string that contains the XML that corresponds to a given tree.
72 * When using this function with a logger, you should probably set both add_metadata and
73 * add_builtin_models to true.
74 *
75 * @param tree the input tree
76 * @param add_metadata if true, the attributes "_uid" and "_fullPath" will be added to the nodes
77 * @param add_builtin_models if true, include the builtin Nodes into the <TreeNodesModel>
78 *
79 * @return string containing the XML.
80 */
81[[nodiscard]] std::string WriteTreeToXML(const Tree& tree, bool add_metadata,
82 bool add_builtin_models);
83
84} // namespace BT
85
86#endif // XML_PARSING_BT_H
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:227
The Blackboard is the mechanism used by BehaviorTrees to exchange typed data.
Definition: blackboard.h:35
The BehaviorTreeParser is a class used to read the model of a BehaviorTree from file or text and inst...
Definition: bt_parser.h:28
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:96
The XMLParser is a class used to read the model of a BehaviorTree from file or text and instantiate t...
Definition: xml_parsing.h:17
Definition: action_node.h:24
std::string writeTreeXSD(const BehaviorTreeFactory &factory)
writeTreeXSD generates an XSD for the nodes defined in the factory
std::string WriteTreeToXML(const Tree &tree, bool add_metadata, bool add_builtin_models)
WriteTreeToXML create a string that contains the XML that corresponds to a given tree....
std::string writeTreeNodesModelXML(const BehaviorTreeFactory &factory, bool include_builtin=false)
writeTreeNodesModelXML generates an XMl that contains the manifests in the <TreeNodesModel>