A generic, type-safe, thread-safe blackboard to hold runtime state.
More...
#include <NavState.hpp>
|
| using | AnyPrinter = std::function<std::string(std::shared_ptr<void>)> |
| | Type alias for a generic printer functor used by debug_string().
|
| |
|
| std::string | debug_string () const |
| | Generates a human-readable dump of all stored keys and values.
|
| |
| template<typename T> |
| const T & | get (const std::string &key) const |
| | Retrieves a const reference to the stored value of type T for key.
|
| |
| template<typename T> |
| const std::shared_ptr< T > | get_ptr (const std::string &key) const |
| | Retrieves the shared_ptr to the stored value of type T for key.
|
| |
| bool | has (const std::string &key) const |
| | Checks whether key exists in the state.
|
| |
| | NavState () |
| | Constructs an empty NavState and registers basic type printers.
|
| |
| template<typename T> |
| void | set (const std::string &key, const std::shared_ptr< T > value_ptr) |
| | Stores a value of type T associated with key (by shared pointer).
|
| |
| template<typename T> |
| void | set (const std::string &key, const T &value) |
| | Stores a value of type T associated with key (by copy).
|
| |
| virtual | ~NavState ()=default |
| | Destructor.
|
| |
A generic, type-safe, thread-safe blackboard to hold runtime state.
NavState provides:
- Type-erased storage using
std::shared_ptr<void>.
- Runtime type verification and safe casting via
typeid.
- Support for value-based and shared-pointer-based insertion.
- Debug utilities including stack trace and introspection.
- Note
- Thread-safety is enforced with an internal
std::mutex.
◆ AnyPrinter
| using AnyPrinter = std::function<std::string(std::shared_ptr<void>)> |
Type alias for a generic printer functor used by debug_string().
The functor receives the stored value as a std::shared_ptr<void> and returns a string representation.
◆ NavState()
Constructs an empty NavState and registers basic type printers.
◆ ~NavState()
◆ debug_string()
| std::string debug_string |
( |
| ) |
const |
Generates a human-readable dump of all stored keys and values.
For types with registered printers, their printer is used; otherwise, the raw pointer address and type hash are shown.
- Returns
- Multi-line string with one entry per key.
◆ get()
template<typename T>
| const T & get |
( |
const std::string & | key | ) |
const |
Retrieves a const reference to the stored value of type T for key.
The reference refers to the object managed by the internal std::shared_ptr<T>.
- Template Parameters
-
- Parameters
-
- Returns
- Const reference to the stored
T.
- Exceptions
-
| std::runtime_error | If key is missing or the stored type does not match T. |
◆ get_ptr()
template<typename T>
| const std::shared_ptr< T > get_ptr |
( |
const std::string & | key | ) |
const |
Retrieves the shared_ptr to the stored value of type T for key.
The pointer refers to the object managed by the internal std::shared_ptr<T>.
- Template Parameters
-
- Parameters
-
- Returns
- shared_ptr to the stored
T.
- Exceptions
-
| std::runtime_error | If key is missing or the stored type does not match T. |
◆ has()
| bool has |
( |
const std::string & | key | ) |
const |
Checks whether key exists in the state.
- Parameters
-
- Returns
true if present, otherwise false.
◆ print_stacktrace()
| static void print_stacktrace |
( |
| ) |
|
|
static |
Prints the current C++ stack trace to std::cerr.
- Note
- Intended for debugging in exception contexts.
◆ register_basic_printers()
| static void register_basic_printers |
( |
| ) |
|
|
static |
Registers default printers for common scalar types.
Registers printers for: int, float, double, std::string, bool, char.
◆ register_printer()
template<typename T>
| static void register_printer |
( |
std::function< std::string(const T &)> | printer | ) |
|
|
static |
Registers a pretty-printer for type T used by debug_string().
- Template Parameters
-
- Parameters
-
| printer | Functor that renders const T& to a string. |
◆ set() [1/2]
template<typename T>
| void set |
( |
const std::string & | key, |
|
|
const std::shared_ptr< T > | value_ptr ) |
Stores a value of type T associated with key (by shared pointer).
If key does not exist, value_ptr is stored directly. If key exists, the stored std::shared_ptr<T> is replaced by value_ptr.
- Template Parameters
-
- Parameters
-
| key | Key associated with the value. |
| value_ptr | Shared pointer to the value to store. |
- Exceptions
-
| std::runtime_error | If key exists with a different stored type; includes a stack trace. |
◆ set() [2/2]
template<typename T>
| void set |
( |
const std::string & | key, |
|
|
const T & | value ) |
Stores a value of type T associated with key (by copy).
If key does not exist, a new std::shared_ptr<T> is created and stored. If key exists, the stored value is overwritten in place.
- Template Parameters
-
| T | Value type. Must be copy-assignable. |
- Parameters
-
| key | Key associated with the value. |
| value | Value to store (copied into internal storage). |
- Exceptions
-
| std::runtime_error | If key exists with a different stored type; includes a stack trace. |
The documentation for this class was generated from the following file: