16#ifndef YASMIN__BLACKBOARD__BLACKBOARD_HPP
17#define YASMIN__BLACKBOARD__BLACKBOARD_HPP
46 std::map<std::string, BlackboardValueInterface *>
values;
56 const std::string &
remap(
const std::string &key);
76 template <
class T>
void set(
const std::string &name, T value) {
80 std::lock_guard<std::recursive_mutex> lk(this->mutex);
85 std::string key = this->
remap(name);
88 if (this->type_registry.find(key) != this->type_registry.end()) {
89 this->values.erase(key);
90 this->type_registry.erase(key);
95 this->values.insert({key, b_value});
96 this->type_registry.insert({key, b_value->
get_type()});
101 this->type_registry[key] = b_value->
get_type();
112 template <
class T> T
get(
const std::string &key) {
116 std::lock_guard<std::recursive_mutex> lk(this->mutex);
119 throw std::runtime_error(
"Element '" + key +
120 "' does not exist in the blackboard");
125 return b_value->
get();
132 void remove(
const std::string &key);
139 bool contains(
const std::string &key);
153 std::string
get_type(
const std::string &key);
A template class that wraps a value of type T.
Definition blackboard_value.hpp:41
void set(T value)
Set a new value.
Definition blackboard_value.hpp:62
std::string get_type()
Get the type of the stored value as a string.
Definition blackboard_value.hpp:71
T get()
Retrieve the stored value.
Definition blackboard_value.hpp:56
const std::map< std::string, std::string > & get_remappings()
Get the remappings of the blackboard.
Definition blackboard.cpp:103
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:90
void set(const std::string &name, T value)
Set a value in the blackboard.
Definition blackboard.hpp:76
T get(const std::string &key)
Retrieve a value from the blackboard.
Definition blackboard.hpp:112
std::map< std::string, std::string > type_registry
Storage for type information for each key.
Definition blackboard.hpp:48
std::map< std::string, std::string > remappings
Storage for key remappings.
Definition blackboard.hpp:50
std::map< std::string, BlackboardValueInterface * > values
Storage for key-value pairs.
Definition blackboard.hpp:46
int size()
Get the number of key-value pairs in the blackboard.
Definition blackboard.cpp:58
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:63
void set_remappings(const std::map< std::string, std::string > &remappings)
Set the remappings of the blackboard.
Definition blackboard.cpp:98
void remove(const std::string &key)
Remove a value from the blackboard.
Definition blackboard.cpp:39
virtual ~Blackboard()
Virtual destructor for Blackboard.
Definition blackboard.cpp:32
bool contains(const std::string &key)
Check if a key exists in the blackboard.
Definition blackboard.cpp:49
std::recursive_mutex mutex
Mutex for thread safety.
Definition blackboard.hpp:44
std::string to_string()
Convert the contents of the blackboard to a string.
Definition blackboard.cpp:77
#define YASMIN_LOG_DEBUG(text,...)
Definition logs.hpp:174
Definition blackboard.hpp:30
Definition blackboard.hpp:29