AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
TreeDocument Class Reference

This class offers a programmatic approach for building behavior trees and stores the registration data of all tree nodes. More...

#include <auto_apms_behavior_tree_core/tree/tree_document.hpp>

Inheritance diagram for TreeDocument:

Classes

class  NodeElement
 Handle for a single node of a TreeDocument. More...
 
struct  NodeModel
 Data structure encapsulating the information of all ports implemented by a behavior tree node. More...
 
struct  NodePortInfo
 Implementation details of a single data port. More...
 
class  TreeElement
 Handle for a single behavior tree of a TreeDocument. More...
 

Public Types

using NodeModelMap = std::map<std::string, NodeModel>
 Mapping of node registration names and their implementation details.
 

Public Member Functions

 TreeDocument (const std::string &format_version=BTCPP_FORMAT_DEFAULT_VERSION, NodeRegistrationLoader::SharedPtr tree_node_loader=NodeRegistrationLoader::make_shared())
 Create a an empty tree document.
 
TreeDocumentmergeTreeDocument (const XMLDocument &other, bool adopt_root_tree=false)
 Merge another tree document with this one.
 
TreeDocumentmergeTreeDocument (const TreeDocument &other, bool adopt_root_tree=false)
 Merge another tree document with this one.
 
TreeDocumentmergeString (const std::string &tree_str, bool adopt_root_tree=false)
 Create a tree document from a string and merge it with this one.
 
TreeDocumentmergeFile (const std::string &path, bool adopt_root_tree=false)
 Create a tree document from a file and merge it with this one.
 
TreeDocumentmergeResource (const TreeResource &resource, bool adopt_root_tree=false)
 Merge the behavior trees from one of the installed package's behavior tree resources.
 
TreeDocumentmergeTree (const TreeElement &tree, bool make_root_tree=false)
 Merge an existing behavior tree with this tree document.
 
TreeElement newTree (const std::string &tree_name)
 Create a new behavior tree inside this document.
 
TreeElement newTree (const TreeElement &other_tree)
 Create a new behavior tree inside this document with the same content of another.
 
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 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 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.
 
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 particular behavior tree resource.
 
bool hasTreeName (const std::string &tree_name) const
 Determine if this document specifies a behavior tree with a particular name.
 
TreeElement getTree (const std::string &tree_name)
 Get the corresponding behavior tree element for a tree inside this document.
 
TreeDocumentsetRootTreeName (const std::string &tree_name)
 Define the root tree of this document.
 
bool hasRootTreeName () const
 Determine if this document specifies which of its trees is the root tree.
 
std::string getRootTreeName () const
 Get the name of this document's root tree.
 
TreeElement getRootTree ()
 Get the corresponding behavior tree element for the root tree of this document.
 
TreeDocumentremoveTree (const std::string &tree_name)
 Remove a particular behavior tree from this document.
 
TreeDocumentremoveTree (const TreeElement &tree)
 Remove a particular behavior tree from this document.
 
std::vector< std::string > getAllTreeNames () const
 Get the names of all behavior trees inside this document.
 
virtual TreeDocumentregisterNodes (const NodeManifest &tree_node_manifest, bool override=false)
 Load behavior tree node plugins and register them with the internal behavior tree factory.
 
std::set< std::string > getRegisteredNodeNames (bool include_native=true) const
 Get the names of all nodes that are known to this document.
 
NodeManifest getRequiredNodeManifest () const
 Assemble the node manifest that is required for successfully creating an instance of any of the document's trees.
 
TreeDocumentaddNodeModel (bool include_native=false)
 Add an behavior tree node model element to the document.
 
NodeModelMap getNodeModel (bool include_native=false) const
 Create a behavior tree node model for all nodes registered with this document.
 
BT::Result verify () const
 Verify that all behavior trees of this document are structured correctly and can be created successfully.
 
std::string writeToString () const
 Write the XML of this tree document to a string.
 
void writeToFile (const std::string &path) const
 Write the XML of this tree document to a file.
 
TreeDocumentreset ()
 Clear this document and reset it to its initial state.
 

Static Public Member Functions

static NodeModelMap getNodeModel (tinyxml2::XMLDocument &doc)
 Convert a behavior tree node model document to the corresponding data structure.
 

Detailed Description

This class offers a programmatic approach for building behavior trees and stores the registration data of all tree nodes.

A single tree document may contain multiple behavior trees (represented by TreeElement). Each behavior tree may contain an arbitrary amount of tree nodes (represented by NodeElement). There are various different types of nodes. For each one of the standard nodes, there is a model available under the auto_apms_behavior_tree::model namespace. Refer to the BehaviorTree.CPP website for more infos on the basic concepts of behavior trees used in this implementation.

A TreeDocument instance must be kept alive for as long as its behavior trees are accessed in any way. When a document instance is destroyed, the memory of the associated behavior trees is deleted. Hence, a TreeDocument acts the same as a tinyxml2::XMLDocument.

Copy assignment is not supported to enforce the builder design pattern. To copy certain behavior trees from one document to another, the user must explicitly invoke TreeDocument::mergeTreeDocument of another document instance.

The XML schema of a tree document is defined here and looks similar to this:

<root BTCPP_format="4" main_tree_to_execute="RootTree">
<!-- Each TreeDocument may have zero or more behavior tree elements -->
<BehaviorTree ID="RootTree">
<!-- Each behavior tree element has exactly one child. This child may again have zero or more children -->
</BehaviorTree>
<BehaviorTree ID="AnotherTree">
<!-- Each behavior tree element has exactly one child. This child may again have zero or more children -->
</BehaviorTree>
</root>
Note
A tree document always has a single root element that holds the format version and the name of the root tree acting as an entry point for execution.

The content of the document can be configured as desired using its member functions. For example like this:

#include "auto_apms_behavior_tree_core/tree/tree_document.hpp"
// Bring the behavior tree API into scope.
using namespace auto_apms_behavior_tree;
// Initially, the document is created. It must be kept alive throughout this scope.
// You may hold on to the returned tree and node elements (they're only valid as long as the document is).
core::TreeDocument::TreeElement root_tree = doc.newTree("RootTree");
core::TreeDocument::NodeElement sequence = root_tree.insertNode("Sequence");
// You may add more nodes to the sequence node created above.
// ...
// Method chaining is supported as well.
doc.newTree("AnotherTree").insertNode("AlwaysSuccess");
// "AnotherTree" has an action node as first child. Action nodes act as tree leaves, meaning they cannot have
// children themselves.
Handle for a single node of a TreeDocument.
NodeElement insertNode(const std::string &name, const NodeElement *before_this=nullptr)
Add a new node to the children of this node.
Handle for a single behavior tree of a TreeDocument.
This class offers a programmatic approach for building behavior trees and stores the registration dat...
TreeElement newTree(const std::string &tree_name)
Create a new behavior tree inside this document.
Useful tooling for incorporating behavior trees for task development.
Definition builder.hpp:30

Alternatively (and preferably), the user may profit from static type validation and more convenience methods by incorporating node models as template arguments:

#include "auto_apms_behavior_tree_core/tree/tree_document.hpp"
#include "auto_apms_behavior_tree/standard_nodes.hpp" // This includes the node models
// Bring the behavior tree API into scope.
using namespace auto_apms_behavior_tree;
// Initially, the document is created. It must be kept alive throughout this scope.
// You may hold on to the returned tree and node elements (they're only valid as long as the document is).
core::TreeDocument::TreeElement root_tree = doc.newTree("RootTree");
model::Sequence sequence = root_tree.insertNode<model::Sequence>();
// You may add more nodes to the sequence node created above.
// ...
// Method chaining is supported as well.
doc.newTree("AnotherTree").insertNode<model::AlwaysSuccess>();
// "AnotherTree" has an action node as first child. Action nodes act as tree leaves, meaning they cannot have
// children themselves. This is enforced by the compiler when using a node model as a template argument.

The former approach can be achieved using the API offered by the auto_apms_behavior_tree_core package, while the latter requires to build and link against the auto_apms_behavior_tree package, since the node models are generated automatically by that package.

Definition at line 133 of file tree_document.hpp.

Member Typedef Documentation

◆ NodeModelMap

using NodeModelMap = std::map<std::string, NodeModel>

Mapping of node registration names and their implementation details.

Definition at line 179 of file tree_document.hpp.

Constructor & Destructor Documentation

◆ TreeDocument()

TreeDocument ( const std::string & format_version = BTCPP_FORMAT_DEFAULT_VERSION,
NodeRegistrationLoader::SharedPtr tree_node_loader = NodeRegistrationLoader::make_shared() )

Create a an empty tree document.

You may specify a format version. Two tree documents must have the same format version for them to be mergeable.

Additionally, you may pass a pointer to an already existing behavior tree node loader. By default, a new one is created with default arguments.

Parameters
format_versionFormat version number encoded in a string.
tree_node_loaderShared pointer to an existing behavior tree node loader.

Definition at line 598 of file tree_document.cpp.

Member Function Documentation

◆ mergeTreeDocument() [1/2]

TreeDocument & mergeTreeDocument ( const XMLDocument & other,
bool adopt_root_tree = false )

Merge another tree document with this one.

This function copies all behavior trees of other and adds them to this document. The other document must either have a root element <root> that may contain an arbitrary amount of <BehaviorTree> child elements, or a single <BehaviorTree> element as its root element.

If adopt_root_tree is true and there is only a single behavior tree, this tree will be considered the new root tree of this document. However, if there are multiple behavior trees under a top-level <root> element and this element has the optional main_tree_to_execute attribute specifying the root tree name, the value of this attribute will be copied to this document. If the other root element doesn't have this attribute, the current root tree name is kept.

Parameters
otherLow-level XML document containing the trees to be merged.
adopt_root_treeSet to true if you additionally want to update this document's root tree name according to other.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the tree names found in other are already taken by this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the format of other is not the same as the format of this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the trees inside other are malformed.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the content of other cannot be interpreted.

Definition at line 614 of file tree_document.cpp.

◆ mergeTreeDocument() [2/2]

TreeDocument & mergeTreeDocument ( const TreeDocument & other,
bool adopt_root_tree = false )

Merge another tree document with this one.

This function copies all behavior trees of other and adds them to this document.

If adopt_root_tree is true and there is only a single behavior tree, this tree will be considered the new root tree of this document. However, if there are multiple behavior trees, the root tree name of the other document will be copied to this document. If the other document doesn't specify which tree is the root tree, the current one is kept.

Parameters
otherOther tree document containing the trees to be merged.
adopt_root_treeSet to true if you additionally want to update this document's root tree name according to other.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the tree names found in other are already taken by this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the format of other is not the same as the format of this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the trees inside other are malformed.

Definition at line 705 of file tree_document.cpp.

◆ mergeString()

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.

This function copies all behavior trees found inside tree_str and adds them to this document. The XML string must either have a root element <root> that may contain an arbitrary amount of <BehaviorTree> child elements, or a single <BehaviorTree> element as its root element.

If adopt_root_tree is true and there is only a single behavior tree, this tree will be considered the new root tree of this document. However, if there are multiple behavior trees under a top-level <root> element and this element has the optional main_tree_to_execute attribute specifying the root tree name, the value of this attribute will be copied to this document. If the other root element doesn't have this attribute, the current root tree name is kept.

Parameters
tree_strXML string specifying the tree document to be merged.
adopt_root_treeSet to true if you additionally want to update this document's root tree name according to tree_str.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the tree names found in tree_str are already taken by this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the format of the XML in tree_str is not the same as the format of this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the trees inside tree_str are malformed.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the content of tree_str cannot be interpreted.

Definition at line 711 of file tree_document.cpp.

◆ mergeFile()

TreeDocument & mergeFile ( const std::string & path,
bool adopt_root_tree = false )

Create a tree document from a file and merge it with this one.

This function copies all behavior trees found inside path and adds them to this document. The XML file must either have a root element <root> that may contain an arbitrary amount of <BehaviorTree> child elements, or a single <BehaviorTree> element as its root element.

If adopt_root_tree is true and there is only a single behavior tree, this tree will be considered the new root tree of this document. However, if there are multiple behavior trees under a top-level <root> element and this element has the optional main_tree_to_execute attribute specifying the root tree name, the value of this attribute will be copied to this document. If the other root element doesn't have this attribute, the current root tree name is kept.

Parameters
pathPath to an XML file specifying the tree document to be merged.
adopt_root_treeSet to true if you additionally want to update this document's root tree name according to path.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the tree names found under path are already taken by this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the format of the XML in path is not the same as the format of this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the trees inside the XML in path are malformed.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the content of path cannot be interpreted.

Definition at line 720 of file tree_document.cpp.

◆ mergeResource()

TreeDocument & mergeResource ( const TreeResource & resource,
bool adopt_root_tree = false )

Merge the behavior trees from one of the installed package's behavior tree resources.

This function parses the XML and the node manifest associated with resource. First, it registers all behavior tree nodes specified by the manifest with this document and then merges the tree document created from the resource's XML file.

If adopt_root_tree is true and there is only a single behavior tree, this tree will be considered the new root tree of this document. However, if there are multiple behavior trees, the root tree name of the other document will be copied to this document. If the other document doesn't specify which one is the root tree, the current one is kept.

See also
TreeResourceIdentity for more information about how to refer to a specific resource.
Parameters
resourceBehavior tree resource that specifies the tree document to be merged.
adopt_root_treeSet to true if you additionally want to update this document's root tree name according to resource.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the tree names found under resource are already taken by this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the format of the XML associated with resource is not the same as the format of this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif any of the trees associated with resource are malformed.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the content of the XML associated with resource cannot be interpreted.

Definition at line 729 of file tree_document.cpp.

◆ mergeTree()

TreeDocument & mergeTree ( const TreeElement & tree,
bool make_root_tree = false )

Merge an existing behavior tree with this tree document.

Before merging the behavior tree represented by tree, all required nodes are automatically registered with this document.

This function is intended for copying a behavior tree from another tree document. If you call this with a tree element that was created using this document or the other tree has the same name as one of the existing trees, an error is raised since a document's tree names must be unique.

Parameters
treeTree element representing the tree to merge.
make_root_treeSet to true if you want to make tree the new root tree of this document.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the tree's name already exists inside this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the tree is malformed.

Definition at line 735 of file tree_document.cpp.

◆ newTree() [1/2]

TreeDocument::TreeElement newTree ( const std::string & tree_name)

Create a new behavior tree inside this document.

Parameters
tree_nameName of the behavior tree.
Returns
Tree element representing the new behavior tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif a tree with name tree_name already exists inside this document.

Definition at line 744 of file tree_document.cpp.

◆ newTree() [2/2]

TreeDocument::TreeElement newTree ( const TreeElement & other_tree)

Create a new behavior tree inside this document with the same content of another.

Before creating a new tree using other_tree, all required nodes are automatically registered with this document.

This function is intended for copying a behavior tree from another tree document. If you call this with a tree element that was created using this document or the other tree has the same name as one of the existing trees, an error is raised since a document's tree names must be unique.

Parameters
other_treeOther behavior tree to be copied.
Returns
Tree element representing the new behavior tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif other_tree has the same name as one of this document's trees.

Definition at line 763 of file tree_document.cpp.

◆ newTreeFromDocument()

TreeDocument::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 document.

Which behavior tree will be used to create the new tree is determined by tree_name. By default, this argument is empty, which means that the root tree will be used. If other only contains a single tree, this one is considered the root tree.

Parameters
otherOther tree document that contains the tree to be copied.
tree_nameName of the tree to be copied. It must exist inside other.
Returns
Tree element representing the new behavior tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree_name is empty but other doesn't specify which tree is the root tree.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree_name cannot be found in other.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif a tree with name tree_name already exists inside this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the respective tree contains any nodes that are not available with the currently configured node manifest.

Definition at line 768 of file tree_document.cpp.

◆ newTreeFromString()

TreeDocument::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.

Which behavior tree will be used to create the new tree is determined by tree_name. By default, this argument is empty, which means that the root tree will be used. If tree_str only contains a single tree, this one is considered the root tree.

Parameters
tree_strString specifying the XML of a tree document that holds the tree to be copied.
tree_nameName of the tree to be copied. It must exist inside tree_str.
Returns
Tree element representing the new behavior tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree_name is empty but tree_str doesn't specify which tree is the root tree.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree_name cannot be found in tree_str.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif a tree with name tree_name already exists inside this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the respective tree contains any nodes that are not available with the currently configured node manifest.

Definition at line 787 of file tree_document.cpp.

◆ newTreeFromFile()

TreeDocument::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.

Which behavior tree will be used to create the new tree is determined by tree_name. By default, this argument is empty, which means that the root tree will be used. If the file under path only contains a single tree, this one is considered the root tree.

Parameters
pathPath to an XML file specifying the tree document that holds the tree to be copied.
tree_nameName of the tree to be copied. It must exist inside the given file.
Returns
Tree element representing the new behavior tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree_name is empty but the given file doesn't specify which tree is the root tree.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree_name cannot be found in the given file.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif a tree with name tree_name already exists inside this document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif the respective tree contains any nodes that are not available with the currently configured node manifest.

Definition at line 794 of file tree_document.cpp.

◆ newTreeFromResource()

TreeDocument::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 particular behavior tree resource.

Before creating a new tree using resource, all required nodes are automatically registered with this document.

Which behavior tree will be used to create the new tree is determined by tree_name. By default, this argument is empty, which means that the root tree will be used. If the given resource only contains a single tree, this one is considered the root tree. Another way to define the root tree with this function is to specify the <tree_name> token when creating the resource object with an identity string. However, the tree_name argument takes precedence over this token.

See also
TreeResourceIdentity for more information about how to refer to a specific resource.
Parameters
resourceBehavior tree resource that specifies the tree to be copied.
tree_nameName of the tree to be copied. It must exist inside the given file.
Returns
Tree element representing the new behavior tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree_name is empty but the root tree cannot be determined.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree_name cannot be found in the resource's tree document.
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif a tree with name tree_name already exists inside this document.

Definition at line 801 of file tree_document.cpp.

◆ hasTreeName()

bool hasTreeName ( const std::string & tree_name) const

Determine if this document specifies a behavior tree with a particular name.

Parameters
tree_nameName of the tree.
Returns
true if a tree named tree_name exists in this document, false otherwise.

Definition at line 811 of file tree_document.cpp.

◆ getTree()

TreeDocument::TreeElement getTree ( const std::string & tree_name)

Get the corresponding behavior tree element for a tree inside this document.

Parameters
tree_nameName of the tree.
Returns
Tree element representing an existing behavior tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif no tree named tree_name exists inside this document.

Definition at line 817 of file tree_document.cpp.

◆ setRootTreeName()

TreeDocument & setRootTreeName ( const std::string & tree_name)

Define the root tree of this document.

Parameters
tree_nameName of an existing tree to be considered the root tree.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif no tree named tree_name exists inside this document.

Definition at line 822 of file tree_document.cpp.

◆ hasRootTreeName()

bool hasRootTreeName ( ) const

Determine if this document specifies which of its trees is the root tree.

Returns
true if this document specifies a root tree, false otherwise.

Definition at line 835 of file tree_document.cpp.

◆ getRootTreeName()

std::string getRootTreeName ( ) const

Get the name of this document's root tree.

Returns
Name of the root tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif this document doesn't specify which tree is the root tree.

Definition at line 841 of file tree_document.cpp.

◆ getRootTree()

TreeDocument::TreeElement getRootTree ( )

Get the corresponding behavior tree element for the root tree of this document.

Returns
Tree element representing this document's root tree.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif this document doesn't specify which tree is the root tree.

Definition at line 849 of file tree_document.cpp.

◆ removeTree() [1/2]

TreeDocument & removeTree ( const std::string & tree_name)

Remove a particular behavior tree from this document.

We only remove the tree and it's child nodes, but not the corresponding node registrations with the behavior tree factory, since this just means more work and is really unnecessary, especially if you consider that if we remove any node registration now and insert it again later somewhere inside the document, we would need to register the node again. Since we assume that the amount of memory is not an issue (and the callbacks that we store when registering don't need much anyways), it would just be extra work.

Parameters
tree_nameName of the tree to be removed.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif no tree named tree_name exists inside this document.

Definition at line 851 of file tree_document.cpp.

◆ removeTree() [2/2]

TreeDocument & removeTree ( const TreeElement & tree)

Remove a particular behavior tree from this document.

We only remove the tree and it's child nodes, but not the corresponding node registrations with the behavior tree factory, since this just means more work and is really unnecessary, especially if you consider that if we remove any node registration now and insert it again later somewhere inside the document, we would need to register the node again. Since we assume that the amount of memory is not an issue (and the callbacks that we store when registering don't need much anyways), it would just be extra work.

Parameters
treeTree element representing the tree to be removed.
Returns
Modified tree document.
Exceptions
auto_apms_behavior_tree::exceptions::TreeDocumentErrorif tree does not belong to this document.

Definition at line 857 of file tree_document.cpp.

◆ getAllTreeNames()

std::vector< std::string > getAllTreeNames ( ) const

Get the names of all behavior trees inside this document.

Returns
Vector of all behavior tree names inside this document.

Definition at line 859 of file tree_document.cpp.

◆ registerNodes()

TreeDocument & registerNodes ( const NodeManifest & tree_node_manifest,
bool override = false )
virtual

Load behavior tree node plugins and register them with the internal behavior tree factory.

This makes it possible to add any nodes specified in tree_node_manifest to the tree.

Parameters
tree_node_manifestParameters for locating and configuring the behavior tree node plugins.
overrideIf tree_node_manifest specifies nodes that have already been registered, unregister the existing plugin and use the new one instead.
Exceptions
auto_apms_behavior_tree::exceptions::NodeRegistrationErrorif registration fails.

Reimplemented in TreeBuilder.

Definition at line 861 of file tree_document.cpp.

◆ getRegisteredNodeNames()

std::set< std::string > getRegisteredNodeNames ( bool include_native = true) const

Get the names of all nodes that are known to this document.

Parameters
include_nativeSet to true if the native BehaviorTree.CPP nodes should be included, false to only consider node plugins.
Returns
Names of all nodes registered with this document.

Definition at line 950 of file tree_document.cpp.

◆ getRequiredNodeManifest()

NodeManifest getRequiredNodeManifest ( ) const

Assemble the node manifest that is required for successfully creating an instance of any of the document's trees.

Returns
Node manifest which contains the registration options for all nodes inside this document.
Exceptions
auto_apms_behavior_tree::exceptions::NodeManifestErrorif there are no registration options for a specific node.

Definition at line 958 of file tree_document.cpp.

◆ addNodeModel()

TreeDocument & addNodeModel ( bool include_native = false)

Add an behavior tree node model element to the document.

This is required when using the Groot2 visual editor.

Parameters
include_nativeSet to true if the native BehaviorTree.CPP nodes should be included, false to only consider registered node plugins.
Returns
Modified tree document.

Definition at line 970 of file tree_document.cpp.

◆ getNodeModel() [1/2]

TreeDocument::NodeModelMap getNodeModel ( tinyxml2::XMLDocument & doc)
static

Convert a behavior tree node model document to the corresponding data structure.

Parameters
docXML document containing the node model.
Returns
Mapping of node models for all nodes specified by doc.

Definition at line 993 of file tree_document.cpp.

◆ getNodeModel() [2/2]

TreeDocument::NodeModelMap getNodeModel ( bool include_native = false) const

Create a behavior tree node model for all nodes registered with this document.

Parameters
include_nativeSet to true if the native BehaviorTree.CPP nodes should be included, false to only consider registered node plugins.
Returns
Mapping of node models for all nodes registered with this document.

Definition at line 1062 of file tree_document.cpp.

◆ verify()

BT::Result verify ( ) const

Verify that all behavior trees of this document are structured correctly and can be created successfully.

Returns
Result that evaluates to true if verification succeeded. Otherwise, it encapsulates a reason why it failed.

Definition at line 1073 of file tree_document.cpp.

◆ writeToString()

std::string writeToString ( ) const

Write the XML of this tree document to a string.

Returns
String representing this document in XML format.

Definition at line 1088 of file tree_document.cpp.

◆ writeToFile()

void writeToFile ( const std::string & path) const

Write the XML of this tree document to a file.

Parameters
pathPath to the output file.

Definition at line 1095 of file tree_document.cpp.

◆ reset()

TreeDocument & reset ( )

Clear this document and reset it to its initial state.

Returns
Modified tree document.

Definition at line 1106 of file tree_document.cpp.


The documentation for this class was generated from the following files: