C++ YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin::blackboard::Blackboard Class Reference

A thread-safe storage for key-value pairs of varying types. More...

#include <blackboard.hpp>

Collaboration diagram for yasmin::blackboard::Blackboard:

Public Member Functions

 Blackboard ()
 Default constructor for Blackboard.
 
 Blackboard (const Blackboard &other)
 Copy constructor for Blackboard.
 
 ~Blackboard ()
 Destructor for Blackboard.
 
template<class T >
get (std::string name)
 Retrieve a value from the blackboard.
 
template<class T >
void set (std::string name, T value)
 Set a value in the blackboard.
 
void remove (std::string name)
 Remove a value from the blackboard.
 
bool contains (std::string name)
 Check if a key exists in the blackboard.
 
int size ()
 Get the number of key-value pairs in the blackboard.
 
std::string to_string ()
 Convert the contents of the blackboard to a string.
 

Private Attributes

std::recursive_mutex mutex
 Mutex for thread safety.
 
std::map< std::string, BlackboardValueInterface * > values
 Storage for key-value pairs.
 

Detailed Description

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. Values are stored as pointers to BlackboardValueInterface instances.

Constructor & Destructor Documentation

◆ Blackboard() [1/2]

Blackboard::Blackboard ( )

Default constructor for Blackboard.

◆ Blackboard() [2/2]

Blackboard::Blackboard ( const Blackboard & other)

Copy constructor for Blackboard.

Parameters
otherThe instance to copy from.

◆ ~Blackboard()

Blackboard::~Blackboard ( )

Destructor for Blackboard.

Member Function Documentation

◆ contains()

bool Blackboard::contains ( std::string name)

Check if a key exists in the blackboard.

Parameters
nameThe key to check.
Returns
True if the key exists, false otherwise.

◆ get()

template<class T >
T yasmin::blackboard::Blackboard::get ( std::string name)
inline

Retrieve a value from the blackboard.

Template Parameters
TThe type of the value to retrieve.
Parameters
nameThe key associated with the value.
Returns
The value associated with the specified key.
Exceptions
std::runtime_errorif the key does not exist.

◆ remove()

void Blackboard::remove ( std::string name)

Remove a value from the blackboard.

Parameters
nameThe key associated with the value to remove.

◆ set()

template<class T >
void yasmin::blackboard::Blackboard::set ( std::string name,
T value )
inline

Set a value in the blackboard.

Template Parameters
TThe type of the value to store.
Parameters
nameThe key to associate with the value.
valueThe value to store.

◆ size()

int Blackboard::size ( )

Get the number of key-value pairs in the blackboard.

Returns
The size of the blackboard.

◆ to_string()

std::string Blackboard::to_string ( )

Convert the contents of the blackboard to a string.

Returns
A string representation of the blackboard.

Member Data Documentation

◆ mutex

std::recursive_mutex yasmin::blackboard::Blackboard::mutex
private

Mutex for thread safety.

◆ values

std::map<std::string, BlackboardValueInterface *> yasmin::blackboard::Blackboard::values
private

Storage for key-value pairs.


The documentation for this class was generated from the following files: