@@ -40,8 +40,7 @@ inline NodeBuilder CreateBuilder(Args... args)
40
40
}
41
41
42
42
template <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)
45
44
{
46
45
return {getType<T>(), ID, portlist, {}};
47
46
}
@@ -300,40 +299,53 @@ class BehaviorTreeFactory
300
299
const std::string& ID,
301
300
const NodeConfig& config) const ;
302
301
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
+ */
308
305
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)
310
307
{
311
308
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,
315
312
" [registerNode]: accepts only classed derived from either "
316
313
" ActionNodeBase, "
317
314
" DecoratorNode, ControlNode or ConditionNode" );
318
315
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
-
324
316
constexpr bool default_constructable =
325
317
std::is_constructible<T, const std::string&>::value;
326
318
constexpr bool param_constructable =
327
319
std::is_constructible<T, const std::string&, const NodeConfig&,
328
320
ExtraArgs...>::value;
329
- constexpr bool has_static_ports_list = has_static_method_providedPorts<T>::value;
330
321
331
322
// 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
+
332
327
static_assert (default_constructable || param_constructable,
333
328
" [registerNode]: the registered class must have at least one of these two constructors:\n "
334
329
" (const std::string&, const NodeConfig&) or (const std::string&)\n "
335
330
" 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;
336
347
348
+ // clang-format off
337
349
static_assert (!(param_constructable && !has_static_ports_list),
338
350
" [registerNode]: you MUST implement the static method:\n "
339
351
" PortsList providedPorts();\n " );
@@ -343,52 +355,7 @@ class BehaviorTreeFactory
343
355
" you MUST add a constructor with signature:\n "
344
356
" (const std::string&, const NodeParameters&)\n " );
345
357
// 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...);
392
359
}
393
360
394
361
// / All the builders. Made available mostly for debug purposes.
0 commit comments