@@ -40,8 +40,7 @@ inline NodeBuilder CreateBuilder(Args... args)
4040}
4141
4242template <typename T>
43- inline TreeNodeManifest CreateManifest (const std::string& ID,
44- PortsList portlist = getProvidedPorts<T>())
43+ inline TreeNodeManifest CreateManifest (const std::string& ID, PortsList portlist)
4544{
4645 return {getType<T>(), ID, portlist, {}};
4746}
@@ -300,40 +299,53 @@ class BehaviorTreeFactory
300299 const std::string& ID,
301300 const NodeConfig& config) const ;
302301
303- /* * registerNodeType is the method to use to register your custom TreeNode.
304- *
305- * It accepts only classed derived from either ActionNodeBase, DecoratorNode,
306- * ControlNode or ConditionNode.
307- */
302+ /* * registerNodeType where you explicitly pass the list of ports.
303+ * Doesn't require the implementation of static method providedPorts()
304+ */
308305 template <typename T, typename ... ExtraArgs>
309- void registerNodeType (const std::string& ID, ExtraArgs... args)
306+ void registerNodeType (const std::string& ID, const PortsList& ports, ExtraArgs... args)
310307 {
311308 static_assert (std::is_base_of<ActionNodeBase, T>::value ||
312- std::is_base_of<ControlNode, T>::value ||
313- std::is_base_of<DecoratorNode, T>::value ||
314- std::is_base_of<ConditionNode, T>::value,
309+ std::is_base_of<ControlNode, T>::value ||
310+ std::is_base_of<DecoratorNode, T>::value ||
311+ std::is_base_of<ConditionNode, T>::value,
315312 " [registerNode]: accepts only classed derived from either "
316313 " ActionNodeBase, "
317314 " DecoratorNode, ControlNode or ConditionNode" );
318315
319- static_assert (!std::is_abstract<T>::value, " [registerNode]: Some methods are pure "
320- " virtual. "
321- " Did you override the methods tick() and "
322- " halt()?" );
323-
324316 constexpr bool default_constructable =
325317 std::is_constructible<T, const std::string&>::value;
326318 constexpr bool param_constructable =
327319 std::is_constructible<T, const std::string&, const NodeConfig&,
328320 ExtraArgs...>::value;
329- constexpr bool has_static_ports_list = has_static_method_providedPorts<T>::value;
330321
331322 // clang-format off
323+ static_assert (!std::is_abstract<T>::value,
324+ " [registerNode]: Some methods are pure virtual. "
325+ " Did you override the methods tick() and halt()?" );
326+
332327 static_assert (default_constructable || param_constructable,
333328 " [registerNode]: the registered class must have at least one of these two constructors:\n "
334329 " (const std::string&, const NodeConfig&) or (const std::string&)\n "
335330 " Check also if the constructor is public!)" );
331+ // clang-format on
332+
333+ registerBuilder (CreateManifest<T>(ID, ports), CreateBuilder<T>(args...));
334+ }
335+
336+ /* * registerNodeType is the method to use to register your custom TreeNode.
337+ *
338+ * It accepts only classed derived from either ActionNodeBase, DecoratorNode,
339+ * ControlNode or ConditionNode.
340+ */
341+ template <typename T, typename ... ExtraArgs>
342+ void registerNodeType (const std::string& ID, ExtraArgs... args)
343+ {
344+ constexpr bool param_constructable =
345+ std::is_constructible<T, const std::string&, const NodeConfig&, ExtraArgs...>::value;
346+ constexpr bool has_static_ports_list = has_static_method_providedPorts<T>::value;
336347
348+ // clang-format off
337349 static_assert (!(param_constructable && !has_static_ports_list),
338350 " [registerNode]: you MUST implement the static method:\n "
339351 " PortsList providedPorts();\n " );
@@ -343,52 +355,7 @@ class BehaviorTreeFactory
343355 " you MUST add a constructor with signature:\n "
344356 " (const std::string&, const NodeParameters&)\n " );
345357 // clang-format on
346-
347- registerBuilder (CreateManifest<T>(ID), CreateBuilder<T>(args...));
348- }
349-
350- template <typename T>
351- void registerNodeType (const std::string& ID, PortsList ports)
352- {
353- static_assert (std::is_base_of<ActionNodeBase, T>::value ||
354- std::is_base_of<ControlNode, T>::value ||
355- std::is_base_of<DecoratorNode, T>::value ||
356- std::is_base_of<ConditionNode, T>::value,
357- " [registerNode]: accepts only classed derived from either "
358- " ActionNodeBase, "
359- " DecoratorNode, ControlNode or ConditionNode" );
360-
361- static_assert (!std::is_abstract<T>::value, " [registerNode]: Some methods are pure "
362- " virtual. "
363- " Did you override the methods tick() and "
364- " halt()?" );
365-
366- constexpr bool default_constructable =
367- std::is_constructible<T, const std::string&>::value;
368- constexpr bool param_constructable =
369- std::is_constructible<T, const std::string&, const NodeConfig&>::value;
370- constexpr bool has_static_ports_list = has_static_method_providedPorts<T>::value;
371-
372- static_assert (default_constructable || param_constructable, " [registerNode]: the "
373- " registered class must "
374- " have at "
375- " least one of these two "
376- " constructors: (const "
377- " std::string&, const "
378- " NodeConfig&) or (const "
379- " std::string&)." );
380-
381- static_assert (!has_static_ports_list, " [registerNode]: ports are passed to this node "
382- " explicitly. The static method"
383- " providedPorts() should be removed to avoid "
384- " ambiguities\n " );
385-
386- static_assert (param_constructable, " [registerNode]: since this node has ports, "
387- " you MUST add a constructor sign signature (const "
388- " std::string&, const "
389- " NodeParameters&)\n " );
390-
391- registerBuilder (CreateManifest<T>(ID, ports), CreateBuilder<T>());
358+ registerNodeType<T>(ID, getProvidedPorts<T>(), args...);
392359 }
393360
394361 // / All the builders. Made available mostly for debug purposes.
0 commit comments