8 #include <unordered_map> 26 typedef std::shared_ptr<Blackboard>
Ptr;
40 return std::shared_ptr<Blackboard>(
new Blackboard(parent) );
53 std::unique_lock<std::mutex> lock(
mutex_);
60 return parent->getAny( remapping_it->second );
64 return ( it ==
storage_.end()) ?
nullptr : &(it->second.value);
69 std::unique_lock<std::mutex> lock(
mutex_);
76 return parent->getAny( remapping_it->second );
80 return ( it ==
storage_.end()) ?
nullptr : &(it->second.value);
87 bool get(
const std::string& key, T& value)
const 92 value = val->
cast<T>();
100 template <
typename T>
101 T
get(
const std::string& key)
const 106 return val->
cast<T>();
110 throw RuntimeError(
"Blackboard::get() error. Missing key [", key,
"]");
116 template <
typename T>
117 void set(
const std::string& key,
const T& value)
119 std::unique_lock<std::mutex> lock(
mutex_);
127 const auto& remapped_key = remapping_it->second;
130 auto parent_info = parent->portInfo(remapped_key);
139 parent->set( remapped_key, value );
146 const PortInfo& port_info = it->second.port_info;
147 auto& previous_any = it->second.value;
148 const auto locked_type = port_info.
type();
152 if( locked_type && locked_type != &
typeid(T) && locked_type != &temp.
type() )
154 bool mismatching =
true;
155 if( std::is_constructible<StringView, T>::value )
158 if( any_from_string.
empty() ==
false)
161 temp = std::move( any_from_string );
169 throw LogicError(
"Blackboard::set() failed: once declared, the type of a port shall not change. " 170 "Declared type [",
demangle( locked_type ),
171 "] != current type [",
demangle(
typeid(T) ),
"]" );
174 previous_any = std::move(temp);
201 value(
std::move(other_any)),
216 #endif // BLACKBOARD_H
virtual ~Blackboard()=default
static Blackboard::Ptr create(Blackboard::Ptr parent={})
const std::type_info & type() const noexcept
void debugMessage() const
const PortInfo * portInfo(const std::string &key)
static pthread_mutex_t mutex
std::shared_ptr< Blackboard > Ptr
Any * getAny(const std::string &key)
The Blackboard is the mechanism used by BehaviorTrees to exchange typed data.
const std::type_info * type() const
Any parseString(const char *str) const
std::string demangle(char const *name)
const Any * getAny(const std::string &key) const
The method getAny allow the user to access directly the type erased value.
bool empty() const noexcept
std::weak_ptr< Blackboard > parent_bb_
void addSubtreeRemapping(std::string internal, std::string external)
Entry(Any &&other_any, const PortInfo &info)
std::unordered_map< std::string, Entry > storage_
Entry(const PortInfo &info)
void setPortInfo(std::string key, const PortInfo &info)
Blackboard(Blackboard::Ptr parent)
std::unordered_map< std::string, std::string > internal_to_external_