MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / createEntryImpl

Method createEntryImpl

src/blackboard.cpp:282–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282std::shared_ptr<Blackboard::Entry> Blackboard::createEntryImpl(const std::string& key,
283 const TypeInfo& info)
284{
285 const std::unique_lock storage_lock(storage_mutex_);
286 // This function might be called recursively, when we do remapping, because we move
287 // to the top scope to find already existing entries
288
289 // search if exists already
290 auto storage_it = storage_.find(key);
291 if(storage_it != storage_.end())
292 {
293 const auto& prev_info = storage_it->second->info;
294 if(prev_info.type() != info.type() && prev_info.isStronglyTyped() &&
295 info.isStronglyTyped())
296 {
297 auto msg = StrCat("Blackboard entry [", key,
298 "]: once declared, the type of a port"
299 " shall not change. Previously declared type [",
300 BT::demangle(prev_info.type()), "], current type [",
301 BT::demangle(info.type()), "]");
302
303 throw LogicError(msg);
304 }
305 return storage_it->second;
306 }
307
308 // manual remapping first
309 auto remapping_it = internal_to_external_.find(key);
310 if(remapping_it != internal_to_external_.end())
311 {
312 const auto& remapped_key = remapping_it->second;
313 if(auto parent = parent_bb_.lock())
314 {
315 return parent->createEntryImpl(remapped_key, info);
316 }
317 throw RuntimeError("Missing parent blackboard");
318 }
319 // autoremapping second (excluding private keys)
320 if(autoremapping_ && !IsPrivateKey(key))
321 {
322 if(auto parent = parent_bb_.lock())
323 {
324 return parent->createEntryImpl(key, info);
325 }
326 throw RuntimeError("Missing parent blackboard");
327 }
328 // not remapped, not found. Create locally.
329
330 auto entry = std::make_shared<Entry>(info);
331 // even if empty, let's assign to it a default type
332 entry->value = Any(info.type());
333 storage_.insert({ key, entry });
334 return entry;
335}
336
337nlohmann::json ExportBlackboardToJSON(const Blackboard& blackboard)
338{

Callers 1

createEntryMethod · 0.80

Calls 10

StrCatFunction · 0.85
demangleFunction · 0.85
LogicErrorClass · 0.85
RuntimeErrorClass · 0.85
IsPrivateKeyFunction · 0.85
AnyClass · 0.85
isStronglyTypedMethod · 0.80
lockMethod · 0.80
endMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected