AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
tree_document.hpp
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <tinyxml2.h>
18
19#include <functional>
20#include <iterator>
21#include <set>
22#include <string>
23#include <type_traits>
24#include <vector>
25
26#include "auto_apms_behavior_tree_core/definitions.hpp"
27#include "auto_apms_behavior_tree_core/node/node_manifest.hpp"
28#include "auto_apms_behavior_tree_core/node/node_registration_loader.hpp"
29#include "auto_apms_behavior_tree_core/node/node_registration_options.hpp"
30#include "auto_apms_behavior_tree_core/tree/script.hpp"
31#include "behaviortree_cpp/bt_factory.h"
32#include "behaviortree_cpp/tree_node.h"
33#include "rclcpp/rclcpp.hpp"
34
36{
37class SubTree;
38}
39
41{
42
43class TreeResource;
44class NodeModelType;
45
140class TreeDocument : private tinyxml2::XMLDocument
141{
142 using XMLElement = tinyxml2::XMLElement;
143
144 inline static const std::string LOGGER_NAME = "tree_document";
145
146public:
147 static inline const char BTCPP_FORMAT_ATTRIBUTE_NAME[] = "BTCPP_format";
148 static inline const char BTCPP_FORMAT_DEFAULT_VERSION[] = "4";
149 static inline const char ROOT_ELEMENT_NAME[] = "root";
150 static inline const char ROOT_TREE_ATTRIBUTE_NAME[] = "main_tree_to_execute";
151 static inline const char TREE_ELEMENT_NAME[] = "BehaviorTree";
152 static inline const char SUBTREE_ELEMENT_NAME[] = "SubTree";
153 static inline const char TREE_NAME_ATTRIBUTE_NAME[] = "ID";
154 static inline const char TREE_NODE_MODEL_ELEMENT_NAME[] = "TreeNodesModel";
155 static inline const char NODE_INSTANCE_NAME_ATTRIBUTE_NAME[] = "name";
156 static inline const char INCLUDE_ELEMENT_NAME[] = "include";
157 static inline const char INCLUDE_PATH_ATTRIBUTE_NAME[] = "path";
158 static inline const char INCLUDE_ROS_PKG_ATTRIBUTE_NAME[] = "ros_pkg";
159
160 class TreeElement;
161
175 {
176 public:
178 using PortValues = std::map<std::string, std::string>;
180 using DeepApplyCallback = std::function<bool(NodeElement &)>;
182 using ConstDeepApplyCallback = std::function<bool(const NodeElement &)>;
183
184 protected:
190 explicit NodeElement(TreeDocument * doc_ptr, XMLElement * ele_ptr);
191
192 public:
197 NodeElement(const NodeElement & ele) = default;
198
210 NodeElement & operator=(const NodeElement & other);
211
220 bool operator==(const NodeElement & other) const;
221
222 bool operator!=(const NodeElement & other) const;
223
238 NodeElement insertNode(const std::string & name, const NodeElement * before_this = nullptr);
239
254 const std::string & name, const NodeRegistrationOptions & registration_options,
255 const NodeElement * before_this = nullptr);
256
270 template <class T>
271 typename std::enable_if_t<std::is_base_of_v<NodeModelType, T> && !std::is_same_v<model::SubTree, T>, T> insertNode(
272 const NodeElement * before_this = nullptr);
273
289 template <class SubTreeT>
290 typename std::enable_if_t<std::is_same_v<model::SubTree, SubTreeT>, model::SubTree> insertNode(
291 const std::string & tree_name, const NodeElement * before_this = nullptr);
292
311 template <class SubTreeT>
312 typename std::enable_if_t<std::is_same_v<model::SubTree, SubTreeT>, model::SubTree> insertNode(
313 const TreeElement & tree, const NodeElement * before_this = nullptr);
314
327 model::SubTree insertSubTreeNode(const std::string & tree_name, const NodeElement * before_this = nullptr);
328
344 model::SubTree insertSubTreeNode(const TreeElement & tree, const NodeElement * before_this = nullptr);
345
361 NodeElement insertTree(const TreeElement & tree, const NodeElement * before_this = nullptr);
362
381 const TreeDocument & doc, const std::string & tree_name, const NodeElement * before_this = nullptr);
382
401 NodeElement insertTreeFromDocument(const TreeDocument & doc, const NodeElement * before_this = nullptr);
402
423 const std::string & tree_str, const std::string & tree_name, const NodeElement * before_this = nullptr);
424
444 NodeElement insertTreeFromString(const std::string & tree_str, const NodeElement * before_this = nullptr);
445
466 const std::string & path, const std::string & tree_name, const NodeElement * before_this = nullptr);
467
487 NodeElement insertTreeFromFile(const std::string & path, const NodeElement * before_this = nullptr);
488
515 const TreeResource & resource, const std::string & tree_name, const NodeElement * before_this = nullptr);
516
543 NodeElement insertTreeFromResource(const TreeResource & resource, const NodeElement * before_this = nullptr);
544
549 bool hasChildren() const;
550
551 // clang-format off
573 const std::string & registration_name = "", const std::string & instance_name = "",
574 bool deep_search = false) const;
575
576 // clang-format off
598 template <class T>
599 typename std::enable_if_t<std::is_base_of_v<NodeModelType, T>, T> getFirstNode(
600 const std::string & instance_name = "", bool deep_search = false) const;
601
602 // clang-format off
624 const std::string & registration_name = "", const std::string & instance_name = "",
625 bool deep_search = false);
626
627 // clang-format off
649 template <class T>
650 typename std::enable_if_t<std::is_base_of_v<NodeModelType, T>, NodeElement &> removeFirstChild(
651 const std::string & instance_name = "", bool deep_search = false);
652 // clang-format on
653
659
668 const std::vector<std::string> & getPortNames() const;
669
681 PortValues getPorts() const;
682
696 NodeElement & setPorts(const PortValues & port_values);
697
706
717 NodeElement & setConditionalScript(BT::PreCond type, const Script & script);
718
725 NodeElement & setConditionalScript(BT::PostCond type, const Script & script);
726
732 virtual NodeElement & setName(const std::string & instance_name);
733
738 virtual std::string getRegistrationName() const;
739
744 virtual std::string getName() const;
745
750 std::string getFullyQualifiedName() const;
751
760 const TreeDocument & getParentDocument() const;
761
769 XMLElement * getXMLElement();
770
788 const std::vector<NodeElement> deepApplyConst(ConstDeepApplyCallback apply_callback) const;
789
805 std::vector<NodeElement> deepApply(DeepApplyCallback apply_callback);
806
814 {
815 friend class NodeElement;
816
817 public:
818 using iterator_category = std::forward_iterator_tag;
819 using value_type = NodeElement;
820 using difference_type = std::ptrdiff_t;
821 using pointer = value_type *;
822 using reference = value_type;
823
826
828 value_type operator*() const;
829
832
835
836 bool operator==(const ChildIterator & other) const;
837 bool operator!=(const ChildIterator & other) const;
838
839 private:
840 ChildIterator(TreeDocument * doc_ptr, tinyxml2::XMLElement * current);
841
842 TreeDocument * doc_ptr_;
843 tinyxml2::XMLElement * current_;
844 };
845
850 ChildIterator begin() const;
851
856 ChildIterator end() const;
857
858 private:
859 NodeElement insertBeforeImpl(const NodeElement * before_this, XMLElement * add_this);
860
861 static void deepApplyImpl(
862 const NodeElement & parent, ConstDeepApplyCallback apply_callback, std::vector<NodeElement> & vec);
863
864 static void deepApplyImpl(NodeElement & parent, DeepApplyCallback apply_callback, std::vector<NodeElement> & vec);
865
866 protected:
870 tinyxml2::XMLElement * ele_ptr_;
871
872 private:
873 std::vector<std::string> port_names_;
874 PortValues port_default_values_;
875 };
876
886 {
887 friend class TreeDocument;
888
889 protected:
895 explicit TreeElement(TreeDocument * doc_ptr, XMLElement * ele_ptr);
896
897 public:
902 TreeElement(const TreeElement & ele) = default;
903
913 TreeElement & operator=(const TreeElement & other);
914
920 TreeElement & setName(const std::string & tree_name) override;
921
926 std::string getName() const override;
927
936
948
954 BT::Result verify() const;
955
963 std::string writeToString() const;
964
970 const std::string & registration_name = "", const std::string & instance_name = "", bool deep_search = false);
971
976 template <class T>
977 typename std::enable_if_t<std::is_base_of_v<NodeModelType, T>, TreeElement &> removeFirstChild(
978 const std::string & instance_name = "", bool deep_search = false);
979
985
986 /* Not supported methods for TreeElement instances */
987
988 const std::vector<std::string> & getPortNames() = delete;
989 PortValues getPorts() = delete;
990 NodeElement & setPorts() = delete;
991 NodeElement & resetPorts() = delete;
992 NodeElement & setConditionalScript() = delete;
993 };
994
1006 const std::string & format_version = BTCPP_FORMAT_DEFAULT_VERSION,
1007 NodeRegistrationLoader::SharedPtr tree_node_loader = NodeRegistrationLoader::make_shared());
1008
1009 TreeDocument(const TreeDocument & other) = delete;
1010
1011 virtual ~TreeDocument() = default;
1012
1036 TreeDocument & mergeTreeDocument(const XMLDocument & other, bool adopt_root_tree = false);
1037
1057 TreeDocument & mergeTreeDocument(const TreeDocument & other, bool adopt_root_tree = false);
1058
1082 TreeDocument & mergeString(const std::string & tree_str, bool adopt_root_tree = false);
1083
1108 TreeDocument & mergeFile(const std::string & path, bool adopt_root_tree = false);
1109
1135 TreeDocument & mergeResource(const TreeResource & resource, bool adopt_root_tree = false);
1136
1153 TreeDocument & mergeTree(const TreeElement & tree, bool make_root_tree = false);
1154
1162 TreeElement newTree(const std::string & tree_name);
1163
1177 TreeElement newTree(const TreeElement & other_tree);
1178
1196 TreeElement newTreeFromDocument(const TreeDocument & other, const std::string & tree_name = "");
1197
1215 TreeElement newTreeFromString(const std::string & tree_str, const std::string & tree_name = "");
1216
1234 TreeElement newTreeFromFile(const std::string & path, const std::string & tree_name = "");
1235
1259 TreeElement newTreeFromResource(const TreeResource & resource, const std::string & tree_name = "");
1260
1266 bool hasTreeName(const std::string & tree_name) const;
1267
1275 TreeElement getTree(const std::string & tree_name);
1276
1284 TreeDocument & setRootTreeName(const std::string & tree_name);
1285
1290 bool hasRootTreeName() const;
1291
1298 std::string getRootTreeName() const;
1299
1307
1321 TreeDocument & removeTree(const std::string & tree_name);
1322
1335 TreeDocument & removeTree(const TreeElement & tree);
1336
1341 std::vector<std::string> getAllTreeNames() const;
1342
1355 const std::string & node_namespace,
1356 const std::string & sep = _AUTO_APMS_BEHAVIOR_TREE_CORE__NODE_NAMESPACE_DEFAULT_SEP);
1357
1370 virtual TreeDocument & registerNodes(const NodeManifest & tree_node_manifest, bool override = false);
1371
1378 std::set<std::string> getRegisteredNodeNames(bool include_native = true) const;
1379
1388
1397
1405 static NodeModelMap getNodeModel(tinyxml2::XMLDocument & doc, const NodeManifest & manifest);
1406
1416 NodeModelMap getNodeModel(bool include_native = false) const;
1417
1423 BT::Result verify() const;
1424
1429 std::string writeToString() const;
1430
1435 void writeToFile(const std::string & path) const;
1436
1441 TreeDocument & reset();
1442
1443private:
1444 template <typename ReturnT, typename DocumentT>
1445 static ReturnT getXMLElementForTreeWithNameImpl(DocumentT & doc, const std::string & tree_name);
1446
1447 const XMLElement * getXMLElementForTreeWithName(const std::string & tree_name) const;
1448
1449 XMLElement * getXMLElementForTreeWithName(const std::string & tree_name);
1450
1458 TreeDocument & mergeFileImpl(const std::string & path, bool adopt_root_tree, std::set<std::string> & include_stack);
1459
1467 TreeDocument & mergeTreeDocumentImpl(
1468 const XMLDocument & other, bool adopt_root_tree, std::set<std::string> & include_stack);
1469
1470 const std::map<std::string, std::string> all_node_classes_package_map_;
1471 const std::set<std::string> native_node_names_;
1472 std::string format_version_;
1473 NodeRegistrationLoader::SharedPtr tree_node_loader_ptr_;
1474
1475protected:
1476 NodeManifest registered_nodes_manifest_;
1477 BT::BehaviorTreeFactory factory_;
1478 rclcpp::Logger logger_;
1479 rclcpp::Node::WeakPtr ros_node_wptr_;
1480 rclcpp::CallbackGroup::WeakPtr tree_node_waitables_callback_group_wptr_;
1481 rclcpp::executors::SingleThreadedExecutor::WeakPtr tree_node_waitables_executor_wptr_;
1482 bool only_non_ros_nodes_ = false;
1483};
1484
1485// #####################################################################################################################
1486// ################################ DEFINITIONS ##############################################
1487// #####################################################################################################################
1488
1490template <typename T, typename = void>
1491struct has_static_method_registrationOptions : std::false_type
1492{
1493};
1494
1495template <typename T>
1496struct has_static_method_registrationOptions<
1497 T, typename std::enable_if_t<std::is_same_v<decltype(T::registrationOptions()), NodeRegistrationOptions>>>
1498: std::true_type
1499{
1500};
1502
1503template <class T>
1504inline typename std::enable_if_t<std::is_base_of_v<NodeModelType, T> && !std::is_same_v<model::SubTree, T>, T>
1506{
1507 // Determine if overload for automatically trying to register the node can be used. Models for native nodes don't
1508 // implement the required static method, thus the other overload must be used.
1509 if constexpr (has_static_method_registrationOptions<T>::value) {
1510 NodeElement ele = insertNode(T::name(), T::registrationOptions(), before_this);
1511 return T(ele.doc_ptr_, ele.ele_ptr_);
1512 } else {
1513 NodeElement ele = insertNode(T::name(), before_this);
1514 return T(ele.doc_ptr_, ele.ele_ptr_);
1515 }
1516}
1517
1518template <class T>
1519inline typename std::enable_if_t<std::is_same_v<model::SubTree, T>, model::SubTree>
1520TreeDocument::NodeElement::insertNode(const std::string & tree_name, const NodeElement * before_this)
1521{
1522 return insertSubTreeNode(tree_name, before_this);
1523}
1524
1525template <class T>
1526inline typename std::enable_if_t<std::is_same_v<model::SubTree, T>, model::SubTree>
1527TreeDocument::NodeElement::insertNode(const TreeElement & tree, const NodeElement * before_this)
1528{
1529 return insertSubTreeNode(tree, before_this);
1530}
1531
1532template <class T>
1533inline typename std::enable_if_t<std::is_base_of_v<NodeModelType, T>, T> core::TreeDocument::NodeElement::getFirstNode(
1534 const std::string & instance_name, bool deep_search) const
1535{
1536 const NodeElement ele = getFirstNode(T::name(), instance_name, deep_search);
1537 return T(ele.doc_ptr_, ele.ele_ptr_);
1538}
1539
1540template <class T>
1541inline typename std::enable_if_t<std::is_base_of_v<NodeModelType, T>, TreeDocument::NodeElement &>
1542core::TreeDocument::NodeElement::removeFirstChild(const std::string & instance_name, bool deep_search)
1543{
1544 return removeFirstChild(T::name(), instance_name, deep_search);
1545}
1546
1547template <class T>
1548inline typename std::enable_if_t<std::is_base_of_v<NodeModelType, T>, TreeDocument::TreeElement &>
1549TreeDocument::TreeElement::removeFirstChild(const std::string & instance_name, bool deep_search)
1550{
1551 NodeElement::removeFirstChild<T>(instance_name, deep_search);
1552 return *this;
1553}
1554
1555} // namespace auto_apms_behavior_tree::core
1556
1557// Include after TreeDocument is fully defined to provide complete type for model::SubTree
1558// which is forward declared above but used as return type in insertSubTreeNode methods.
1559#include "auto_apms_behavior_tree_core/node/node_model_type.hpp"
Data structure for information about which behavior tree node plugin to load and how to configure the...
Abstract base for all automatically generated behavior tree node model classes to be used in interact...
Class that encapsulates behavior tree script expressions.
Definition script.hpp:30
Forward iterator for traversing the first-level children of a node.
ChildIterator & operator++()
Pre-increment: advance to the next sibling element.
value_type operator*() const
Dereference the iterator to obtain a NodeElement handle for the current child.
Handle for a single node of a TreeDocument.
std::enable_if_t< std::is_base_of_v< NodeModelType, T >, T > getFirstNode(const std::string &instance_name="", bool deep_search=false) const
Get the first node with a particular instance name.
const TreeDocument & getParentDocument() const
Get a const view of this node's parent tree document.
NodeElement insertTreeFromResource(const TreeResource &resource, const std::string &tree_name, const NodeElement *before_this=nullptr)
Concatenate a tree from one of the installed package's behavior tree resources and add its first chil...
const std::vector< std::string > & getPortNames() const
Get the names of the data ports implemented by the node represented by this element.
virtual std::string getRegistrationName() const
Get the name of this node given during registration representing its dynamic type.
XMLElement * getXMLElement()
Get a pointer to the underlying tinyxml2::XMLElement of this node.
std::function< bool(const NodeElement &)> ConstDeepApplyCallback
Callback invoked for every node found under another node. It cannot modify the current node.
NodeElement & resetPorts()
Delete all currently specified port values and reset with the defaults.
NodeElement(const NodeElement &ele)=default
Copy constructor for a node element.
std::function< bool(NodeElement &)> DeepApplyCallback
Callback invoked for every node found under another node. It may modify the current node.
NodeElement & setPorts(const PortValues &port_values)
Populate the the node's data ports.
std::enable_if_t< std::is_same_v< model::SubTree, SubTreeT >, model::SubTree > insertNode(const TreeElement &tree, const NodeElement *before_this=nullptr)
Add a subtree node for a specific tree element to the children of this node.
virtual NodeElement & setName(const std::string &instance_name)
Assign a name for this specific node instance.
NodeElement(TreeDocument *doc_ptr, XMLElement *ele_ptr)
Protected constructor intended for internal use only.
std::map< std::string, std::string > PortValues
Mapping of port names and its respective value encoded as string.
const std::vector< NodeElement > deepApplyConst(ConstDeepApplyCallback apply_callback) const
Recursively apply a callback to this node's children.
TreeDocument * doc_ptr_
Pointer to the tree document that created the tree this node belongs to.
ChildIterator end() const
Get a past-the-end iterator for the children of this node.
virtual std::string getName() const
Get the name of this node given to this specific instance by the developer.
PortValues getPorts() const
Assemble the values given to each data port implemented by this node.
NodeElement & setConditionalScript(BT::PreCond type, const Script &script)
Specify a script that is evaluated before this node is ticked.
NodeElement insertTreeFromString(const std::string &tree_str, const std::string &tree_name, const NodeElement *before_this=nullptr)
Concatenate a tree from a document created from a string and add its first child node to the children...
std::enable_if_t< std::is_base_of_v< NodeModelType, T >, NodeElement & > removeFirstChild(const std::string &instance_name="", bool deep_search=false)
Remove the first node with a particular instance name.
tinyxml2::XMLElement * ele_ptr_
Pointer to the corresponding XMLElement of the base document.
NodeElement insertTree(const TreeElement &tree, const NodeElement *before_this=nullptr)
Concatenate a tree and add its first child node to the children of this node.
std::string getFullyQualifiedName() const
Create a string that uniquely identifies this node considering its registration and its instance name...
NodeElement insertTreeFromDocument(const TreeDocument &doc, const std::string &tree_name, const NodeElement *before_this=nullptr)
Concatenate a tree from a document and add its first child node to the children of this node.
model::SubTree insertSubTreeNode(const std::string &tree_name, const NodeElement *before_this=nullptr)
Add a subtree node for a specific tree element to the children of this node.
bool hasChildren() const
Determine whether any children have been given to this node.
std::enable_if_t< std::is_same_v< model::SubTree, SubTreeT >, model::SubTree > insertNode(const std::string &tree_name, const NodeElement *before_this=nullptr)
Add a subtree node for a specific tree element to the children of this node.
bool operator==(const NodeElement &other) const
Determine if two node elements refer to the same node.
NodeElement getFirstNode(const std::string &registration_name="", const std::string &instance_name="", bool deep_search=false) const
Get the first node with a particular registration and instance name.
ChildIterator begin() const
Get an iterator to the first child of this node.
NodeElement insertNode(const std::string &name, const NodeElement *before_this=nullptr)
Add a new node to the children of this node.
NodeElement & removeFirstChild(const std::string &registration_name="", const std::string &instance_name="", bool deep_search=false)
Remove the first node with a particular registration and instance name.
NodeElement insertTreeFromFile(const std::string &path, const std::string &tree_name, const NodeElement *before_this=nullptr)
Concatenate a tree from a document created from a file and add its first child node to the children o...
NodeElement & removeChildren()
Recursively remove all children of this node element.
NodeElement & operator=(const NodeElement &other)
Replace this node with another.
std::vector< NodeElement > deepApply(DeepApplyCallback apply_callback)
Recursively apply a callback to this node's children.
Handle for a single behavior tree of a TreeDocument.
TreeElement & removeFirstChild(const std::string &registration_name="", const std::string &instance_name="", bool deep_search=false)
TreeElement(TreeDocument *doc_ptr, XMLElement *ele_ptr)
Protected constructor intended to be used only by certain factory methods of TreeDocument.
std::string getName() const override
Get the name of the behavior tree.
BT::Result verify() const
Verify that this behavior tree is structured correctly and can be created successfully.
NodeManifest getRequiredNodeManifest() const
Assemble the node manifest that is required for successfully creating an instance of this tree.
TreeElement & makeRoot()
Set this behavior tree as the root tree of the parent document.
TreeElement & operator=(const TreeElement &other)
Replace the behavior tree represented by this element with another.
TreeElement & setName(const std::string &tree_name) override
Set the name of the behavior tree.
std::string writeToString() const
Write this behavior tree to an XML encoded in a string.
TreeElement(const TreeElement &ele)=default
Copy constructor for a tree element.
std::enable_if_t< std::is_base_of_v< NodeModelType, T >, TreeElement & > removeFirstChild(const std::string &instance_name="", bool deep_search=false)
TreeElement getRootTree()
Get the corresponding behavior tree element for the root tree of this document.
TreeDocument & mergeResource(const TreeResource &resource, bool adopt_root_tree=false)
Merge the behavior trees from one of the installed package's behavior tree resources.
std::string getRootTreeName() const
Get the name of this document's root tree.
TreeDocument & mergeTreeDocument(const XMLDocument &other, bool adopt_root_tree=false)
Merge another tree document with this one.
TreeDocument & mergeString(const std::string &tree_str, bool adopt_root_tree=false)
Create a tree document from a string and merge it with this one.
TreeElement newTreeFromDocument(const TreeDocument &other, const std::string &tree_name="")
Create a new behavior tree inside this document with the content of one found inside another tree doc...
void writeToFile(const std::string &path) const
Write the XML of this tree document to a file.
TreeElement newTreeFromFile(const std::string &path, const std::string &tree_name="")
Create a new behavior tree inside this document with the content of one found inside the XML file.
TreeDocument & applyNodeNamespace(const std::string &node_namespace, const std::string &sep=_AUTO_APMS_BEHAVIOR_TREE_CORE__NODE_NAMESPACE_DEFAULT_SEP)
Prepend a namespace to all nodes associated with this document.
BT::Result verify() const
Verify that all behavior trees of this document are structured correctly and can be created successfu...
NodeManifest getRequiredNodeManifest() const
Assemble the node manifest that is required for successfully creating an instance of any of the docum...
std::set< std::string > getRegisteredNodeNames(bool include_native=true) const
Get the names of all nodes that are known to this document.
TreeElement newTreeFromString(const std::string &tree_str, const std::string &tree_name="")
Create a new behavior tree inside this document with the content of one found inside the XML string.
TreeElement newTreeFromResource(const TreeResource &resource, const std::string &tree_name="")
Create a new behavior tree inside this document with the content of one the trees found inside a part...
TreeDocument & reset()
Clear this document and reset it to its initial state.
TreeElement getTree(const std::string &tree_name)
Get the corresponding behavior tree element for a tree inside this document.
virtual TreeDocument & registerNodes(const NodeManifest &tree_node_manifest, bool override=false)
Load behavior tree node plugins and register them with the internal behavior tree factory.
TreeDocument & setRootTreeName(const std::string &tree_name)
Define the root tree of this document.
bool hasTreeName(const std::string &tree_name) const
Determine if this document contains a behavior tree with a particular name.
TreeDocument & mergeFile(const std::string &path, bool adopt_root_tree=false)
Create a tree document from a file and merge it with this one.
std::vector< std::string > getAllTreeNames() const
Get the names of all behavior trees inside this document.
TreeDocument & addNodeModel(NodeModelMap model_map)
Add a behavior tree node model element to the document by parsing the contents of model_map.
TreeDocument & mergeTree(const TreeElement &tree, bool make_root_tree=false)
Merge an existing behavior tree with this tree document.
std::string writeToString() const
Write the XML of this tree document to a string.
bool hasRootTreeName() const
Determine if this document specifies which of its trees is the root tree.
TreeDocument & removeTree(const std::string &tree_name)
Remove a particular behavior tree from this document.
TreeDocument(const std::string &format_version=BTCPP_FORMAT_DEFAULT_VERSION, NodeRegistrationLoader::SharedPtr tree_node_loader=NodeRegistrationLoader::make_shared())
Create a an empty tree document.
static NodeModelMap getNodeModel(tinyxml2::XMLDocument &doc, const NodeManifest &manifest)
Convert a behavior tree node model document to the corresponding data structure.
TreeElement newTree(const std::string &tree_name)
Create a new behavior tree inside this document.
Class containing behavior tree resource data.
Subtree behavior tree node model.
Core API for AutoAPMS's behavior tree implementation.
Definition behavior.hpp:32
Models for all available behavior tree nodes.
std::map< std::string, NodeModel > NodeModelMap
Mapping of node registration names and their implementation details.
Parameters for loading and registering a behavior tree node class from a shared library using e....