@@ -134,7 +134,13 @@ class TreeNode
134
134
*/
135
135
TreeNode (std::string name, NodeConfig config);
136
136
137
- virtual ~TreeNode () = default ;
137
+ TreeNode (const TreeNode& other) = delete ;
138
+ TreeNode& operator =(const TreeNode& other) = delete ;
139
+
140
+ TreeNode (TreeNode&& other);
141
+ TreeNode& operator =(TreeNode&& other);
142
+
143
+ virtual ~TreeNode ();
138
144
139
145
// / The method that should be used to invoke tick() and setStatus();
140
146
virtual BT::NodeStatus executeTick ();
@@ -314,7 +320,7 @@ class TreeNode
314
320
else if constexpr (hasNodeNameCtor<DerivedT>())
315
321
{
316
322
auto node_ptr = new DerivedT (name, args...);
317
- node_ptr->config_ = config;
323
+ node_ptr->config () = config;
318
324
return std::unique_ptr<DerivedT>(node_ptr);
319
325
}
320
326
}
@@ -325,6 +331,8 @@ class TreeNode
325
331
friend class ControlNode ;
326
332
friend class Tree ;
327
333
334
+ [[nodiscard]] NodeConfig& config ();
335
+
328
336
// / Method to be implemented by the user
329
337
virtual BT::NodeStatus tick () = 0;
330
338
@@ -345,31 +353,16 @@ class TreeNode
345
353
*/
346
354
void setStatus (NodeStatus new_status);
347
355
348
- private:
349
- const std::string name_;
350
-
351
- NodeStatus status_;
352
-
353
- std::condition_variable state_condition_variable_;
354
-
355
- mutable std::mutex state_mutex_;
356
+ using PreScripts = std::array<ScriptFunction, size_t (PreCond::COUNT_)>;
357
+ using PostScripts = std::array<ScriptFunction, size_t (PostCond::COUNT_)>;
356
358
357
- StatusChangeSignal state_change_signal_;
359
+ PreScripts& preConditionsScripts ();
360
+ PostScripts& postConditionsScripts ();
358
361
359
- NodeConfig config_;
360
-
361
- std::string registration_ID_;
362
-
363
- PreTickCallback substitution_callback_;
364
-
365
- PostTickCallback post_condition_callback_;
366
-
367
- std::mutex callback_injection_mutex_;
368
-
369
- std::shared_ptr<WakeUpSignal> wake_up_;
362
+ private:
370
363
371
- std::array<ScriptFunction, size_t (PreCond::COUNT_)> pre_parsed_ ;
372
- std::array<ScriptFunction, size_t (PostCond::COUNT_)> post_parsed_ ;
364
+ struct PImpl ;
365
+ PImpl* p = nullptr ;
373
366
374
367
Expected<NodeStatus> checkPreConditions ();
375
368
void checkPostConditions (NodeStatus status);
@@ -388,9 +381,9 @@ inline Result TreeNode::getInput(const std::string& key, T& destination) const
388
381
{
389
382
if constexpr (std::is_enum_v<T> && !std::is_same_v<T, NodeStatus>)
390
383
{
391
- auto it = config_ .enums ->find (str);
384
+ auto it = config () .enums ->find (str);
392
385
// conversion available
393
- if ( it != config_ .enums ->end () )
386
+ if ( it != config () .enums ->end () )
394
387
{
395
388
return static_cast <T>(it->second );
396
389
}
@@ -404,8 +397,8 @@ inline Result TreeNode::getInput(const std::string& key, T& destination) const
404
397
}
405
398
};
406
399
407
- auto remap_it = config_ .input_ports .find (key);
408
- if (remap_it == config_ .input_ports .end ())
400
+ auto remap_it = config () .input_ports .find (key);
401
+ if (remap_it == config () .input_ports .end ())
409
402
{
410
403
return nonstd::make_unexpected (StrCat (" getInput() failed because "
411
404
" NodeConfig::input_ports "
@@ -418,9 +411,9 @@ inline Result TreeNode::getInput(const std::string& key, T& destination) const
418
411
// BUT, it the port type is a string, then an empty string might be
419
412
// a valid value
420
413
const std::string& port_value_str = remap_it->second ;
421
- if (port_value_str.empty () && config_ .manifest )
414
+ if (port_value_str.empty () && config () .manifest )
422
415
{
423
- const auto & port_manifest = config_ .manifest ->ports .at (key);
416
+ const auto & port_manifest = config () .manifest ->ports .at (key);
424
417
const auto & default_value = port_manifest.defaultValue ();
425
418
if (!default_value.empty () && !default_value.isString ())
426
419
{
@@ -440,12 +433,12 @@ inline Result TreeNode::getInput(const std::string& key, T& destination) const
440
433
}
441
434
const auto & remapped_key = remapped_res.value ();
442
435
443
- if (!config_ .blackboard )
436
+ if (!config () .blackboard )
444
437
{
445
438
return nonstd::make_unexpected (" getInput(): trying to access an invalid Blackboard" );
446
439
}
447
440
448
- if (auto any_ref = config_ .blackboard ->getAnyLocked (std::string (remapped_key)))
441
+ if (auto any_ref = config () .blackboard ->getAnyLocked (std::string (remapped_key)))
449
442
{
450
443
auto val = any_ref.get ();
451
444
if (!val->empty ())
@@ -476,14 +469,14 @@ inline Result TreeNode::getInput(const std::string& key, T& destination) const
476
469
template <typename T>
477
470
inline Result TreeNode::setOutput (const std::string& key, const T& value)
478
471
{
479
- if (!config_ .blackboard )
472
+ if (!config () .blackboard )
480
473
{
481
474
return nonstd::make_unexpected (" setOutput() failed: trying to access a "
482
475
" Blackboard(BB) entry, but BB is invalid" );
483
476
}
484
477
485
- auto remap_it = config_ .output_ports .find (key);
486
- if (remap_it == config_ .output_ports .end ())
478
+ auto remap_it = config () .output_ports .find (key);
479
+ if (remap_it == config () .output_ports .end ())
487
480
{
488
481
return nonstd::make_unexpected (StrCat (" setOutput() failed: "
489
482
" NodeConfig::output_ports "
@@ -499,7 +492,7 @@ inline Result TreeNode::setOutput(const std::string& key, const T& value)
499
492
{
500
493
remapped_key = stripBlackboardPointer (remapped_key);
501
494
}
502
- config_ .blackboard ->set (static_cast <std::string>(remapped_key), value);
495
+ config () .blackboard ->set (static_cast <std::string>(remapped_key), value);
503
496
504
497
return {};
505
498
}
0 commit comments