Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
BT::BehaviorTreeFactory Class Reference

The BehaviorTreeFactory is used to create instances of a TreeNode at run-time. More...

#include <bt_factory.h>

Public Member Functions

 BehaviorTreeFactory ()
 
const std::unordered_map< std::string, NodeBuilder > & builders () const
 All the builders. Made available mostly for debug purposes. More...
 
const std::set< std::string > & builtinNodes () const
 List of builtin IDs. More...
 
Tree createTreeFromFile (const std::string &file_path, Blackboard::Ptr blackboard=Blackboard::create())
 
Tree createTreeFromText (const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
 
std::unique_ptr< TreeNodeinstantiateTreeNode (const std::string &name, const std::string &ID, const NodeConfiguration &config) const
 instantiateTreeNode creates an instance of a previously registered TreeNode. More...
 
const std::unordered_map< std::string, TreeNodeManifest > & manifests () const
 Manifests of all the registered TreeNodes. More...
 
void registerBuilder (const TreeNodeManifest &manifest, const NodeBuilder &builder)
 The most generic way to register your own builder. More...
 
template<typename T >
void registerBuilder (const std::string &ID, const NodeBuilder &builder)
 
void registerFromPlugin (const std::string &file_path)
 registerFromPlugin load a shared library and execute the function BT_REGISTER_NODES (see macro). More...
 
template<typename T >
void registerNodeType (const std::string &ID)
 
void registerSimpleAction (const std::string &ID, const SimpleActionNode::TickFunctor &tick_functor, PortsList ports={})
 registerSimpleAction help you register nodes of type SimpleActionNode. More...
 
void registerSimpleCondition (const std::string &ID, const SimpleConditionNode::TickFunctor &tick_functor, PortsList ports={})
 registerSimpleCondition help you register nodes of type SimpleConditionNode. More...
 
void registerSimpleDecorator (const std::string &ID, const SimpleDecoratorNode::TickFunctor &tick_functor, PortsList ports={})
 registerSimpleDecorator help you register nodes of type SimpleDecoratorNode. More...
 
bool unregisterBuilder (const std::string &ID)
 Remove a registered ID. More...
 

Static Public Member Functions

template<typename T >
static TreeNodeManifest buildManifest (const std::string &ID)
 

Private Types

template<typename T >
using has_default_constructor = typename std::is_constructible< T, const std::string & >
 
template<typename T >
using has_params_constructor = typename std::is_constructible< T, const std::string &, const NodeConfiguration & >
 

Private Member Functions

template<typename T >
void registerNodeTypeImpl (const std::string &ID)
 

Static Private Member Functions

template<typename T >
static NodeBuilder getBuilder (typename std::enable_if< has_default_constructor< T >::value &&has_params_constructor< T >::value >::type *=nullptr)
 
template<typename T >
static NodeBuilder getBuilder (typename std::enable_if<!has_default_constructor< T >::value &&has_params_constructor< T >::value >::type *=nullptr)
 
template<typename T >
static NodeBuilder getBuilder (typename std::enable_if< has_default_constructor< T >::value &&!has_params_constructor< T >::value >::type *=nullptr)
 

Private Attributes

std::unordered_map< std::string, NodeBuilderbuilders_
 
std::set< std::string > builtin_IDs_
 
std::unordered_map< std::string, TreeNodeManifestmanifests_
 

Detailed Description

The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.

Some node types are "builtin", whilst other are used defined and need to be registered using a unique ID.

Definition at line 98 of file bt_factory.h.

Member Typedef Documentation

template<typename T >
using BT::BehaviorTreeFactory::has_default_constructor = typename std::is_constructible<T, const std::string&>
private

Definition at line 240 of file bt_factory.h.

template<typename T >
using BT::BehaviorTreeFactory::has_params_constructor = typename std::is_constructible<T, const std::string&, const NodeConfiguration&>
private

Definition at line 243 of file bt_factory.h.

Constructor & Destructor Documentation

BT::BehaviorTreeFactory::BehaviorTreeFactory ( )

Definition at line 19 of file bt_factory.cpp.

Member Function Documentation

const std::unordered_map< std::string, NodeBuilder > & BT::BehaviorTreeFactory::builders ( ) const

All the builders. Made available mostly for debug purposes.

Definition at line 155 of file bt_factory.cpp.

template<typename T >
static TreeNodeManifest BT::BehaviorTreeFactory::buildManifest ( const std::string &  ID)
inlinestatic

Definition at line 226 of file bt_factory.h.

const std::set< std::string > & BT::BehaviorTreeFactory::builtinNodes ( ) const

List of builtin IDs.

Definition at line 165 of file bt_factory.cpp.

Tree BT::BehaviorTreeFactory::createTreeFromFile ( const std::string &  file_path,
Blackboard::Ptr  blackboard = Blackboard::create() 
)

Definition at line 180 of file bt_factory.cpp.

Tree BT::BehaviorTreeFactory::createTreeFromText ( const std::string &  text,
Blackboard::Ptr  blackboard = Blackboard::create() 
)

Definition at line 170 of file bt_factory.cpp.

template<typename T >
static NodeBuilder BT::BehaviorTreeFactory::getBuilder ( typename std::enable_if< has_default_constructor< T >::value &&has_params_constructor< T >::value >::type *  = nullptr)
inlinestaticprivate

Definition at line 253 of file bt_factory.h.

template<typename T >
static NodeBuilder BT::BehaviorTreeFactory::getBuilder ( typename std::enable_if<!has_default_constructor< T >::value &&has_params_constructor< T >::value >::type *  = nullptr)
inlinestaticprivate

Definition at line 272 of file bt_factory.h.

template<typename T >
static NodeBuilder BT::BehaviorTreeFactory::getBuilder ( typename std::enable_if< has_default_constructor< T >::value &&!has_params_constructor< T >::value >::type *  = nullptr)
inlinestaticprivate

Definition at line 282 of file bt_factory.h.

std::unique_ptr< TreeNode > BT::BehaviorTreeFactory::instantiateTreeNode ( const std::string &  name,
const std::string &  ID,
const NodeConfiguration config 
) const

instantiateTreeNode creates an instance of a previously registered TreeNode.

Parameters
namename of this particular instance
IDID used when it was registered
configconfiguration that is passed to the constructor of the TreeNode.
Returns
new node.

Definition at line 134 of file bt_factory.cpp.

const std::unordered_map< std::string, TreeNodeManifest > & BT::BehaviorTreeFactory::manifests ( ) const

Manifests of all the registered TreeNodes.

Definition at line 160 of file bt_factory.cpp.

void BT::BehaviorTreeFactory::registerBuilder ( const TreeNodeManifest manifest,
const NodeBuilder builder 
)

The most generic way to register your own builder.

Definition at line 68 of file bt_factory.cpp.

template<typename T >
void BT::BehaviorTreeFactory::registerBuilder ( const std::string &  ID,
const NodeBuilder builder 
)
inline

Definition at line 110 of file bt_factory.h.

void BT::BehaviorTreeFactory::registerFromPlugin ( const std::string &  file_path)

registerFromPlugin load a shared library and execute the function BT_REGISTER_NODES (see macro).

Parameters
file_pathpath of the file

Definition at line 116 of file bt_factory.cpp.

template<typename T >
void BT::BehaviorTreeFactory::registerNodeType ( const std::string &  ID)
inline

registerNodeType is the method to use to register your custom TreeNode.

It accepts only classed derived from either ActionNodeBase, DecoratorNode, ControlNode or ConditionNode.

Definition at line 174 of file bt_factory.h.

template<typename T >
void BT::BehaviorTreeFactory::registerNodeTypeImpl ( const std::string &  ID)
inlineprivate

Definition at line 246 of file bt_factory.h.

void BT::BehaviorTreeFactory::registerSimpleAction ( const std::string &  ID,
const SimpleActionNode::TickFunctor tick_functor,
PortsList  ports = {} 
)

registerSimpleAction help you register nodes of type SimpleActionNode.

Parameters
IDregistration ID
tick_functorthe callback to be invoked in the tick() method.
portsif your SimpleNode requires ports, provide the list here.

Definition at line 92 of file bt_factory.cpp.

void BT::BehaviorTreeFactory::registerSimpleCondition ( const std::string &  ID,
const SimpleConditionNode::TickFunctor tick_functor,
PortsList  ports = {} 
)

registerSimpleCondition help you register nodes of type SimpleConditionNode.

Parameters
IDregistration ID
tick_functorthe callback to be invoked in the tick() method.
portsif your SimpleNode requires ports, provide the list here.

Definition at line 80 of file bt_factory.cpp.

void BT::BehaviorTreeFactory::registerSimpleDecorator ( const std::string &  ID,
const SimpleDecoratorNode::TickFunctor tick_functor,
PortsList  ports = {} 
)

registerSimpleDecorator help you register nodes of type SimpleDecoratorNode.

Parameters
IDregistration ID
tick_functorthe callback to be invoked in the tick() method.
portsif your SimpleNode requires ports, provide the list here.

Definition at line 104 of file bt_factory.cpp.

bool BT::BehaviorTreeFactory::unregisterBuilder ( const std::string &  ID)

Remove a registered ID.

Definition at line 52 of file bt_factory.cpp.

Member Data Documentation

std::unordered_map<std::string, NodeBuilder> BT::BehaviorTreeFactory::builders_
private

Definition at line 232 of file bt_factory.h.

std::set<std::string> BT::BehaviorTreeFactory::builtin_IDs_
private

Definition at line 234 of file bt_factory.h.

std::unordered_map<std::string, TreeNodeManifest> BT::BehaviorTreeFactory::manifests_
private

Definition at line 233 of file bt_factory.h.


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


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:06