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
135135
136136 Blackboard::Ptr parent ();
137137
138+ // recursively look for parent Blackboard, until you find the root
139+ Blackboard* rootBlackboard ();
140+
141+ const Blackboard* rootBlackboard () const ;
142+
138143private:
139144 mutable std::mutex mutex_;
140145 mutable std::recursive_mutex entry_mutex_;
@@ -197,6 +202,11 @@ inline void Blackboard::unset(const std::string& key)
197202template <typename T>
198203inline void Blackboard::set (const std::string& key, const T& value)
199204{
205+ if (StartWith (key, ' @' ))
206+ {
207+ rootBlackboard ()->set (key.substr (1 , key.size () - 1 ), value);
208+ return ;
209+ }
200210 std::unique_lock lock (mutex_);
201211
202212 // check local storage
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ using SimpleString = SafeAny::SimpleString;
2828using expr_ptr = std::shared_ptr<struct ExprBase >;
2929
3030// 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)
3232{
3333 const auto str = value.cast <std::string>();
3434 if (str == " true" )
Original file line number Diff line number Diff line change @@ -49,14 +49,7 @@ Blackboard::getEntry(const std::string& key) const
4949 // special syntax: "@" will always refer to the root BB
5050 if (StartWith (key, ' @' ))
5151 {
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 ));
6053 }
6154
6255 std::unique_lock<std::mutex> lock (mutex_);
@@ -318,4 +311,22 @@ Blackboard::Entry& Blackboard::Entry::operator=(const Entry& other)
318311 return *this ;
319312}
320313
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+
321332} // namespace BT
You can’t perform that action at this time.
0 commit comments