2 #include <unordered_set>
10 return str.size() >= 1 && str.data()[0] ==
'_';
46 const std::shared_ptr<Blackboard::Entry>
55 std::unique_lock<std::mutex> lock(
mutex_);
67 auto const& new_key = remap_it->second;
68 return parent->getEntry(new_key);
72 return parent->getEntry(key);
86 return (!entry) ? nullptr : &(entry->info);
92 {
static_cast<std::string
>(
internal),
static_cast<std::string
>(external) });
97 for(
const auto& [key, entry] :
storage_)
99 auto port_type = entry->info.type();
100 if(port_type ==
typeid(
void))
102 port_type = entry->value.type();
105 std::cout << key <<
" (" <<
BT::demangle(port_type) <<
")" << std::endl;
110 std::cout <<
"[" << from <<
"] remapped to port of parent tree [" << to <<
"]"
122 std::vector<StringView> out;
124 for(
const auto& entry_it :
storage_)
126 out.push_back(entry_it.first);
133 std::unique_lock<std::mutex> lock(
mutex_);
146 if(key.find(
'@', 1) != std::string::npos)
148 throw LogicError(
"Character '@' used multiple times in the key");
160 std::unique_lock lk1(
mutex_);
161 std::unique_lock lk2(dst.
mutex_);
164 std::unordered_set<std::string> keys_to_remove;
166 for(
const auto& [key,
_] : dst_storage)
168 keys_to_remove.insert(key);
172 for(
const auto& [src_key, src_entry] :
storage_)
174 keys_to_remove.erase(src_key);
176 auto it = dst_storage.find(src_key);
177 if(it != dst_storage.end())
180 auto& dst_entry = it->second;
181 dst_entry->string_converter = src_entry->string_converter;
182 dst_entry->value = src_entry->value;
183 dst_entry->info = src_entry->info;
184 dst_entry->sequence_id++;
185 dst_entry->stamp = std::chrono::steady_clock::now().time_since_epoch();
190 auto new_entry = std::make_shared<Entry>(src_entry->info);
191 new_entry->value = src_entry->value;
192 new_entry->string_converter = src_entry->string_converter;
193 dst_storage.insert({ src_key, new_entry });
197 for(
const auto& key : keys_to_remove)
199 dst_storage.erase(key);
215 std::unique_lock<std::mutex> lock(
mutex_);
220 auto storage_it =
storage_.find(key);
223 const auto& prev_info = storage_it->second->info;
224 if(prev_info.type() != info.type() && prev_info.isStronglyTyped() &&
225 info.isStronglyTyped())
227 auto msg =
StrCat(
"Blackboard entry [", key,
228 "]: once declared, the type of a port"
229 " shall not change. Previously declared type [",
235 return storage_it->second;
242 const auto& remapped_key = remapping_it->second;
245 return parent->createEntryImpl(remapped_key, info);
254 return parent->createEntryImpl(key, info);
260 auto entry = std::make_shared<Entry>(info);
262 entry->value =
Any(info.type());
270 for(
auto entry_name : blackboard.
getKeys())
272 std::string name(entry_name);
286 for(
auto it =
json.begin(); it !=
json.end(); ++it)
290 auto entry = blackboard.
getEntry(it.key());
294 entry = blackboard.
getEntry(it.key());
296 entry->value = res->first;