Class Blackboard
Defined in File blackboard.hpp
Nested Relationships
Nested Types
Class Documentation
-
class Blackboard
A thread-safe storage for key-value pairs of varying types.
The Blackboard class allows storing, retrieving, and managing values associated with string keys in a thread-safe manner using a recursive mutex.
Public Functions
-
Blackboard()
Shared pointer type for Blackboard.
Default constructor for Blackboard.
-
Blackboard(const Blackboard &other)
Copy constructor for Blackboard.
The copied blackboard shares the underlying storage with
otherwhile keeping its own local remapping table.- Parameters:
other – The instance to copy from.
-
template<class T>
inline void set(const std::string &name, T value) Set a value in the blackboard.
- Template Parameters:
T – The type of the value to store.
- Parameters:
name – The key to associate with the value.
value – The value to store.
-
template<class T>
inline T get(const std::string &key) const Retrieve a value from the blackboard.
- Template Parameters:
T – The type of the value to retrieve.
- Parameters:
name – The key associated with the value.
- Throws:
std::runtime_error – if the key does not exist.
- Returns:
The value associated with the specified key.
-
void remove(const std::string &key)
Remove a value from the blackboard.
- Parameters:
key – The key associated with the value to remove.
-
bool contains(const std::string &key) const
Check if a key exists in the blackboard.
- Parameters:
key – The key to check.
- Returns:
True if the key exists, false otherwise.
-
void copy_value_from(const Blackboard &other, const std::string &source_key, const std::string &target_key)
Copy a value from another blackboard.
The stored value is forwarded using the existing type-erased storage so the type does not need to be known at compile time.
- Parameters:
other – The source blackboard.
source_key – The key to read from the source blackboard.
target_key – The key to write in this blackboard.
-
int size() const
Get the number of key-value pairs in the blackboard.
- Returns:
The size of the blackboard.
-
std::vector<std::string> keys() const
Get the keys visible in the current remapping scope.
If one or more remappings point to a stored key, the remapped names are returned instead of the underlying storage key. Multiple remapped names can therefore refer to the same stored value.
- Returns:
A sorted list of visible key names.
-
std::string get_type(const std::string &key) const
Get the type of a value stored in the blackboard.
- Parameters:
key – The key associated with the value.
- Throws:
std::runtime_error – if the key does not exist.
- Returns:
A string representation of the type.
-
std::string to_string() const
Convert the contents of the blackboard to a string.
- Returns:
A string representation of the blackboard.
-
void set_remappings(const Remappings &remappings)
Set the remappings of the blackboard.
- Parameters:
remappings – The remappings to set.
-
const Remappings &get_remappings() const noexcept
Get the remappings of the blackboard.
- Returns:
The remappings of the blackboard.
-
Blackboard()