Go to the documentation of this file.
8 #include <unordered_map>
25 typedef std::shared_ptr<Blackboard>
Ptr;
38 return std::shared_ptr<Blackboard>(
new Blackboard(parent));
51 const Any*
getAny(
const std::string& key)
const;
64 bool get(
const std::string& key, T& value)
const
69 value = val->
cast<T>();
78 T
get(
const std::string& key)
const
83 return val->
cast<T>();
87 throw RuntimeError(
"Blackboard::get() error. Missing key [", key,
"]");
93 void set(
const std::string& key,
const T& value)
96 std::unique_lock<std::mutex> lock(
mutex_);
100 std::shared_ptr<Entry> entry;
107 Any new_value(value);
108 std::shared_ptr<Blackboard::Entry> entry;
110 if(std::is_constructible<std::string, T>::value)
117 entry->value = new_value;
121 const PortInfo& port_info = entry->port_info;
122 auto& previous_any = entry->value;
123 const auto previous_type = port_info.
type();
125 Any new_value(value);
127 if (previous_type && *previous_type !=
typeid(T) &&
128 *previous_type != new_value.
type())
130 bool mismatching =
true;
131 if (std::is_constructible<StringView, T>::value)
134 if (any_from_string.
empty() ==
false)
137 new_value = std::move(any_from_string);
145 throw LogicError(
"Blackboard::set() failed: once declared, the type of a port "
146 "shall not change. Declared type [",
151 previous_any = std::move(new_value);
160 std::vector<StringView>
getKeys()
const;
164 std::unique_lock<std::mutex> lock(
mutex_);
194 std::shared_ptr<Entry>
getEntry(
const std::string& key)
const
197 return it ==
storage_.end() ? std::shared_ptr<Entry>() : it->second;
206 std::unordered_map<std::string, std::shared_ptr<Entry>>
storage_;
215 #endif // BLACKBOARD_H
Entry(const PortInfo &info)
void set(const std::string &key, const T &value)
Update the entry with the given key.
std::weak_ptr< Blackboard > parent_bb_
std::string demangle(char const *name)
const std::type_info * type() const
static pthread_mutex_t mutex
bool get(const std::string &key, T &value) const
void createEntry(const std::string &key, const PortInfo &info)
std::mutex & entryMutex()
std::unordered_map< std::string, std::shared_ptr< Entry > > storage_
std::vector< StringView > getKeys() const
const Any * getAny(const std::string &key) const
The method getAny allow the user to access directly the type erased value.
Blackboard(Blackboard::Ptr parent)
void debugMessage() const
std::shared_ptr< Entry > getEntry(const std::string &key) const
T get(const std::string &key) const
void enableAutoRemapping(bool remapping)
virtual ~Blackboard()=default
bool empty() const noexcept
void addSubtreeRemapping(StringView internal, StringView external)
Any parseString(const char *str) const
std::shared_ptr< Entry > createEntryImpl(const std::string &key, const PortInfo &info)
The Blackboard is the mechanism used by BehaviorTrees to exchange typed data.
static Blackboard::Ptr create(Blackboard::Ptr parent={})
Entry(Any &&other_any, const PortInfo &info)
const PortInfo * portInfo(const std::string &key)
Any * getAny(const std::string &key)
std::unordered_map< std::string, std::string > internal_to_external_
const std::type_info & type() const noexcept
std::shared_ptr< Blackboard > Ptr
nonstd::string_view StringView
behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Wed Jun 26 2024 02:51:19