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

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

#include <blackboard.hpp>

Collaboration diagram for yasmin::Blackboard:

Public Types

using SharedPtr = std::shared_ptr<Blackboard>
 Shared pointer type for Blackboard.
 
using ConstSharedPtr = std::shared_ptr<const Blackboard>
 
using UniquePtr = std::unique_ptr<Blackboard>
 Unique pointer type for Blackboard.
 
using WeakPtr = std::weak_ptr<Blackboard>
 Weak pointer type for Blackboard.
 
using ConstWeakPtr = std::weak_ptr<const Blackboard>
 

Public Member Functions

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

Static Public Member Functions

template<typename... Args>
static std::shared_ptr< Blackboardmake_shared (Args &&...args)
 
template<typename... Args>
static std::unique_ptr< Blackboardmake_unique (Args &&...args)
 

Private Member Functions

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.
 

Private Attributes

std::recursive_mutex mutex
 Mutex for thread safety.
 
std::unordered_map< std::string, std::shared_ptr< void > > values
 Storage for key-value pairs.
 
TypeRegistry type_registry
 Storage for type information for each key.
 
Remappings remappings
 Storage for key remappings.
 

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.

Member Typedef Documentation

◆ ConstSharedPtr

using yasmin::Blackboard::ConstSharedPtr = std::shared_ptr<const Blackboard>

◆ ConstWeakPtr

using yasmin::Blackboard::ConstWeakPtr = std::weak_ptr<const Blackboard>

◆ SharedPtr

using yasmin::Blackboard::SharedPtr = std::shared_ptr<Blackboard>

Shared pointer type for Blackboard.

◆ UniquePtr

using yasmin::Blackboard::UniquePtr = std::unique_ptr<Blackboard>

Unique pointer type for Blackboard.

◆ WeakPtr

using yasmin::Blackboard::WeakPtr = std::weak_ptr<Blackboard>

Weak pointer type for Blackboard.

Constructor & Destructor Documentation

◆ Blackboard() [1/2]

Blackboard::Blackboard ( )
default

Default constructor for Blackboard.

◆ Blackboard() [2/2]

Blackboard::Blackboard ( const Blackboard & other)

Copy constructor for Blackboard.

Parameters
otherThe instance to copy from.

Member Function Documentation

◆ contains()

bool Blackboard::contains ( const std::string & key) const

Check if a key exists in the blackboard.

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

◆ get()

template<class T>
T yasmin::Blackboard::get ( const std::string & key) const
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.

◆ get_remappings()

const Remappings & Blackboard::get_remappings ( ) const
noexcept

Get the remappings of the blackboard.

Returns
The remappings of the blackboard.

◆ get_type()

std::string Blackboard::get_type ( const std::string & key) const

Get the type of a value stored in the blackboard.

Parameters
keyThe key associated with the value.
Returns
A string representation of the type.
Exceptions
std::runtime_errorif the key does not exist.

◆ make_shared()

template<typename... Args>
static std::shared_ptr< Blackboard > yasmin::Blackboard::make_shared ( Args &&... args)
inlinestatic

◆ make_unique()

template<typename... Args>
static std::unique_ptr< Blackboard > yasmin::Blackboard::make_unique ( Args &&... args)
inlinestatic

◆ remap()

const std::string & Blackboard::remap ( const std::string & key) const
private

Internal method that acquires the maped key. In the case the key is not remaped, retruns the arg key.

Parameters
otherThe instance to copy from.

◆ remove()

void Blackboard::remove ( const std::string & key)

Remove a value from the blackboard.

Parameters
keyThe key associated with the value to remove.

◆ set()

template<class T>
void yasmin::Blackboard::set ( const 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.

◆ set_remappings()

void Blackboard::set_remappings ( const Remappings & remappings)

Set the remappings of the blackboard.

Parameters
remappingsThe remappings to set.

◆ size()

int Blackboard::size ( ) const

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

Returns
The size of the blackboard.

◆ to_string()

std::string Blackboard::to_string ( ) const

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::mutex
mutableprivate

Mutex for thread safety.

◆ remappings

Remappings yasmin::Blackboard::remappings
private

Storage for key remappings.

◆ type_registry

TypeRegistry yasmin::Blackboard::type_registry
private

Storage for type information for each key.

◆ values

std::unordered_map<std::string, std::shared_ptr<void> > yasmin::Blackboard::values
private

Storage for key-value pairs.


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