16#ifndef YASMIN__BLACKBOARD_HPP_
17#define YASMIN__BLACKBOARD_HPP_
26#include <unordered_map>
40 std::string name = mangled_name;
46 abi::__cxa_demangle(name.c_str(),
nullptr,
nullptr, &status);
67 mutable std::recursive_mutex
mutex;
69 std::unordered_map<std::string, std::shared_ptr<void>>
values;
79 const std::string &
remap(
const std::string &key)
const;
104 template <class T>
void set(const std::
string &name, T value) {
108 std::lock_guard<std::recursive_mutex> lk(this->mutex);
111 std::string key = this->
remap(name);
114 if (this->type_registry.find(key) != this->type_registry.end()) {
115 this->values.erase(key);
116 this->type_registry.erase(key);
121 this->values[key] = std::make_shared<T>(value);
126 if (this->type_registry.at(key) !=
demangle_type(
typeid(T).name())) {
127 this->values[key] = std::make_shared<T>(value);
131 *(std::static_pointer_cast<T>(this->values.at(key))) = value;
143 template <
class T> T
get(
const std::string &key)
const {
147 std::lock_guard<std::recursive_mutex> lk(this->mutex);
151 throw std::runtime_error(
"Element '" + key +
152 "' does not exist in the blackboard");
156 return *(std::static_pointer_cast<T>(this->values.at(this->remap(key))));
163 void remove(
const std::string &key);
170 bool contains(
const std::string &key)
const;
184 std::string
get_type(
const std::string &key)
const;
Remappings remappings
Storage for key remappings.
Definition blackboard.hpp:73
std::unordered_map< std::string, std::shared_ptr< void > > values
Storage for key-value pairs.
Definition blackboard.hpp:69
std::recursive_mutex mutex
Mutex for thread safety.
Definition blackboard.hpp:67
std::string to_string() const
Convert the contents of the blackboard to a string.
Definition blackboard.cpp:68
void set(const std::string &name, T value)
Set a value in the blackboard.
Definition blackboard.hpp:104
TypeRegistry type_registry
Storage for type information for each key.
Definition blackboard.hpp:71
Blackboard()
Default constructor for Blackboard.
const Remappings & get_remappings() const noexcept
Get the remappings of the blackboard.
Definition blackboard.cpp:96
bool contains(const std::string &key) const
Check if a key exists in the blackboard.
Definition blackboard.cpp:40
std::string get_type(const std::string &key) const
Get the type of a value stored in the blackboard.
Definition blackboard.cpp:53
void set_remappings(const Remappings &remappings)
Set the remappings of the blackboard.
Definition blackboard.cpp:92
const std::string & remap(const std::string &key) const
Internal method that acquires the maped key. In the case the key is not remaped, retruns the arg key.
Definition blackboard.cpp:82
void remove(const std::string &key)
Remove a value from the blackboard.
Definition blackboard.cpp:31
int size() const
Get the number of key-value pairs in the blackboard.
Definition blackboard.cpp:48
T get(const std::string &key) const
Retrieve a value from the blackboard.
Definition blackboard.hpp:143
#define YASMIN_LOG_DEBUG(text,...)
Definition logs.hpp:174
Definition blackboard.hpp:31
std::string demangle_type(const std::string &mangled_name)
Demangle a C++ type name to a human-readable format.
Definition blackboard.hpp:38
StringMap Remappings
Map of remappings (string to string)
Definition types.hpp:88
StringMap TypeRegistry
Registry for type information.
Definition types.hpp:92
#define YASMIN_PTR_ALIASES(ClassName)
Macro to define all pointer aliases for a class.
Definition types.hpp:52