16#ifndef YASMIN__BLACKBOARD_HPP
17#define YASMIN__BLACKBOARD_HPP
38 std::string name = mangled_name;
44 abi::__cxa_demangle(name.c_str(),
nullptr,
nullptr, &status);
67 std::map<std::string, std::shared_ptr<void>>
values;
77 const std::string &
remap(
const std::string &key);
94 template <
class T>
void set(
const std::string &name, T value) {
98 std::lock_guard<std::recursive_mutex> lk(this->mutex);
101 std::string key = this->
remap(name);
104 if (this->type_registry.find(key) != this->type_registry.end()) {
105 this->values.erase(key);
106 this->type_registry.erase(key);
111 this->values[key] = std::make_shared<T>(value);
116 if (this->type_registry.at(key) !=
demangle_type(
typeid(T).name())) {
117 this->values[key] = std::make_shared<T>(value);
121 *(std::static_pointer_cast<T>(this->values.at(key))) = value;
133 template <
class T> T
get(
const std::string &key) {
137 std::lock_guard<std::recursive_mutex> lk(this->mutex);
141 throw std::runtime_error(
"Element '" + key +
142 "' does not exist in the blackboard");
146 return *(std::static_pointer_cast<T>(this->values.at(this->remap(key))));
153 void remove(
const std::string &key);
160 bool contains(
const std::string &key);
174 std::string
get_type(
const std::string &key);
const std::map< std::string, std::string > & get_remappings()
Get the remappings of the blackboard.
Definition blackboard.cpp:98
const std::string & remap(const std::string &key)
Internal method that acquires the maped key. In the case the key is not remaped, retruns the arg key.
Definition blackboard.cpp:83
std::map< std::string, std::string > type_registry
Storage for type information for each key.
Definition blackboard.hpp:69
std::map< std::string, std::string > remappings
Storage for key remappings.
Definition blackboard.hpp:71
std::recursive_mutex mutex
Mutex for thread safety.
Definition blackboard.hpp:65
void set(const std::string &name, T value)
Set a value in the blackboard.
Definition blackboard.hpp:94
int size()
Get the number of key-value pairs in the blackboard.
Definition blackboard.cpp:49
Blackboard()
Default constructor for Blackboard.
Definition blackboard.cpp:23
std::string get_type(const std::string &key)
Get the type of a value stored in the blackboard.
Definition blackboard.cpp:54
void set_remappings(const std::map< std::string, std::string > &remappings)
Set the remappings of the blackboard.
Definition blackboard.cpp:93
void remove(const std::string &key)
Remove a value from the blackboard.
Definition blackboard.cpp:32
std::map< std::string, std::shared_ptr< void > > values
Storage for key-value pairs.
Definition blackboard.hpp:67
bool contains(const std::string &key)
Check if a key exists in the blackboard.
Definition blackboard.cpp:41
T get(const std::string &key)
Retrieve a value from the blackboard.
Definition blackboard.hpp:133
std::string to_string()
Convert the contents of the blackboard to a string.
Definition blackboard.cpp:69
#define YASMIN_LOG_DEBUG(text,...)
Definition logs.hpp:174
Definition blackboard.hpp:29
std::string demangle_type(const std::string &mangled_name)
Demangle a C++ type name to a human-readable format.
Definition blackboard.hpp:36