File tree Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,11 @@ class Blackboard
135
135
136
136
Blackboard::Ptr parent ();
137
137
138
+ // recursively look for parent Blackboard, until you find the root
139
+ Blackboard* rootBlackboard ();
140
+
141
+ const Blackboard* rootBlackboard () const ;
142
+
138
143
private:
139
144
mutable std::mutex mutex_;
140
145
mutable std::recursive_mutex entry_mutex_;
@@ -197,6 +202,11 @@ inline void Blackboard::unset(const std::string& key)
197
202
template <typename T>
198
203
inline void Blackboard::set (const std::string& key, const T& value)
199
204
{
205
+ if (StartWith (key, ' @' ))
206
+ {
207
+ rootBlackboard ()->set (key.substr (1 , key.size () - 1 ), value);
208
+ return ;
209
+ }
200
210
std::unique_lock lock (mutex_);
201
211
202
212
// check local storage
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ using SimpleString = SafeAny::SimpleString;
28
28
using expr_ptr = std::shared_ptr<struct ExprBase >;
29
29
30
30
// extended strin to number that consider enums and booleans
31
- double StringToDouble (const Any& value, const Environment& env)
31
+ inline double StringToDouble (const Any& value, const Environment& env)
32
32
{
33
33
const auto str = value.cast <std::string>();
34
34
if (str == " true" )
Original file line number Diff line number Diff line change @@ -49,14 +49,7 @@ Blackboard::getEntry(const std::string& key) const
49
49
// special syntax: "@" will always refer to the root BB
50
50
if (StartWith (key, ' @' ))
51
51
{
52
- if (auto parent = parent_bb_.lock ())
53
- {
54
- return parent->getEntry (key);
55
- }
56
- else
57
- {
58
- return getEntry (key.substr (1 , key.size () - 1 ));
59
- }
52
+ return rootBlackboard ()->getEntry (key.substr (1 , key.size () - 1 ));
60
53
}
61
54
62
55
std::unique_lock<std::mutex> lock (mutex_);
@@ -318,4 +311,22 @@ Blackboard::Entry& Blackboard::Entry::operator=(const Entry& other)
318
311
return *this ;
319
312
}
320
313
314
+ Blackboard* BT::Blackboard::rootBlackboard ()
315
+ {
316
+ auto bb = static_cast <const Blackboard&>(*this ).rootBlackboard ();
317
+ return const_cast <Blackboard*>(bb);
318
+ }
319
+
320
+ const Blackboard* BT::Blackboard::rootBlackboard () const
321
+ {
322
+ const Blackboard* bb = this ;
323
+ Blackboard::Ptr prev = parent_bb_.lock ();
324
+ while (prev)
325
+ {
326
+ bb = prev.get ();
327
+ prev = bb->parent_bb_ .lock ();
328
+ }
329
+ return bb;
330
+ }
331
+
321
332
} // namespace BT
You can’t perform that action at this time.
0 commit comments