29 typedef std::function<std::unique_ptr<TreeNode>(
const std::string&,
const NodeParameters&)>
41 #define BT_REGISTER_NODES(factory) \ 42 extern "C" void __attribute__((visibility("default"))) \ 43 BT_RegisterNodesFromPlugin(BT::BehaviorTreeFactory& factory) 50 bool unregisterBuilder(
const std::string& ID);
58 void registerSimpleAction(
const std::string& ID,
62 void registerSimpleCondition(
const std::string& ID,
66 void registerSimpleDecorator(
const std::string& ID,
76 void registerFromPlugin(
const std::string file_path);
86 std::unique_ptr<TreeNode> instantiateTreeNode(
const std::string& ID,
const std::string& name,
100 static_assert(std::is_base_of<ActionNodeBase, T>::value ||
101 std::is_base_of<ControlNode, T>::value ||
102 std::is_base_of<DecoratorNode, T>::value ||
103 std::is_base_of<ConditionNode, T>::value,
104 "[registerBuilder]: accepts only classed derived from either ActionNodeBase, " 105 "DecoratorNode, ControlNode or ConditionNode");
107 static_assert(!std::is_abstract<T>::value,
108 "[registerBuilder]: Some methods are pure virtual. " 109 "Did you override the methods tick() and halt()?");
111 constexpr
bool default_constructable = std::is_constructible<T, const std::string&>::value;
112 constexpr
bool param_constructable =
113 std::is_constructible<T, const std::string&, const NodeParameters&>::value;
114 constexpr
bool has_static_required_parameters =
117 static_assert(default_constructable || param_constructable,
118 "[registerBuilder]: the registered class must have at least one of these two " 120 " (const std::string&, const NodeParameters&) or (const std::string&).");
122 static_assert(!(param_constructable && !has_static_required_parameters),
123 "[registerBuilder]: you MUST implement the static method: " 124 " const NodeParameters& requiredNodeParameters();\n");
126 static_assert(!(has_static_required_parameters && !param_constructable),
127 "[registerBuilder]: since you have a static method requiredNodeParameters(), " 128 "you MUST add a constructor sign signature (const std::string&, const " 129 "NodeParameters&)\n");
131 registerNodeTypeImpl<T>(ID);
135 const std::map<std::string, NodeBuilder>& builders()
const;
138 const std::vector<TreeNodeManifest>& manifests()
const;
140 const std::set<std::string>& builtinNodes()
const;
150 template <
typename T>
153 template <
typename T>
156 template <
typename T,
typename =
void>
159 template <
typename T>
161 typename
std::enable_if<std::is_same<decltype(T::requiredNodeParameters()), const NodeParameters&>::value>
::type>
164 template <
typename T>
169 getRequiredParamsImpl<T>() };
170 registerBuilder(manifest, builder);
173 template <
typename T>
178 return std::unique_ptr<TreeNode>(
new T(name));
182 template <
typename T>
185 return [
this](
const std::string& name,
const NodeParameters& params)
190 return std::unique_ptr<TreeNode>(
new T(name));
192 return std::unique_ptr<TreeNode>(
new T(name, params));
196 template <
typename T>
201 return std::unique_ptr<TreeNode>(
new T(name, params));
205 template <
typename T>
208 return T::requiredNodeParameters();
211 template <
typename T>
218 void sortTreeNodeManifests();
223 #endif // BT_FACTORY_H NodeBuilder getBuilderImpl(typename std::enable_if< !has_params_constructor< T >::value >::type *=nullptr)
NodeBuilder getBuilderImpl(typename std::enable_if< has_default_constructor< T >::value &&has_params_constructor< T >::value >::type *=nullptr)
std::map< std::string, NodeBuilder > builders_
std::vector< TreeNodeManifest > manifests_
void registerNodeType(const std::string &ID)
std::function< NodeStatus(NodeStatus, TreeNode &)> TickFunctor
NodeBuilder getBuilderImpl(typename std::enable_if<!has_default_constructor< T >::value &&has_params_constructor< T >::value >::type *=nullptr)
void registerNodeTypeImpl(const std::string &ID)
NodeParameters getRequiredParamsImpl(typename std::enable_if< has_static_method_requiredParams< T >::value >::type *=nullptr)
std::set< std::string > builtin_IDs_
typename std::is_constructible< T, const std::string &, const NodeParameters & > has_params_constructor
std::shared_ptr< Blackboard > Ptr
This information is used mostly by the XMLParser.
NodeParameters getRequiredParamsImpl(typename std::enable_if< !has_static_method_requiredParams< T >::value >::type *=nullptr)
std::unordered_map< std::string, std::string > NodeParameters
typename std::is_constructible< T, const std::string & > has_default_constructor
std::string registration_ID
const char PLUGIN_SYMBOL[]
std::function< NodeStatus(TreeNode &)> TickFunctor
std::function< std::unique_ptr< TreeNode >const std::string &, const NodeParameters &)> NodeBuilder
The term "Builder" refers to the Builder Pattern (https://en.wikipedia.org/wiki/Builder_pattern) ...
NodeParameters required_parameters
std::function< NodeStatus(TreeNode &)> TickFunctor