Class NavState
Defined in File NavState.hpp
Class Documentation
-
class NavState
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.Public Types
-
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.
Public Functions
-
virtual ~NavState() = default
Destructor.
-
template<typename T>
inline void set(const std::string &key, const T &value) Stores a value of type
Tassociated withkey(by copy).If
keydoes not exist, a newstd::shared_ptr<T>is created and stored. Ifkeyexists, 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).
- Throws:
std::runtime_error – If
keyexists with a different stored type; includes a stack trace.
-
template<typename T>
inline void set(const std::string &key, const std::shared_ptr<T> value_ptr) Stores a value of type
Tassociated withkey(by shared pointer).If
keydoes not exist,value_ptris stored directly. Ifkeyexists, the storedstd::shared_ptr<T>is replaced byvalue_ptr.- Template Parameters:
T – Value type.
- Parameters:
key – Key associated with the value.
value_ptr – Shared pointer to the value to store.
- Throws:
std::runtime_error – If
keyexists with a different stored type; includes a stack trace.
-
template<typename T>
inline const T &get(const std::string &key) const Retrieves a const reference to the stored value of type
Tforkey.The reference refers to the object managed by the internal
std::shared_ptr<T>.- Template Parameters:
T – Expected stored type.
- Parameters:
key – Key to retrieve.
- Throws:
std::runtime_error – If
keyis missing or the stored type does not matchT.- Returns:
Const reference to the stored
T.
-
template<typename T>
inline const std::shared_ptr<T> get_ptr(const std::string &key) const Retrieves the shared_ptr to the stored value of type
Tforkey.The pointer refers to the object managed by the internal
std::shared_ptr<T>.- Template Parameters:
T – Expected stored type.
- Parameters:
key – Key to retrieve.
- Throws:
std::runtime_error – If
keyis missing or the stored type does not matchT.- Returns:
shared_ptr to the stored
T.
-
inline bool has(const std::string &key) const
Checks whether
keyexists in the state.- Parameters:
key – Key to query.
- Returns:
trueif present, otherwisefalse.
-
inline 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.
Public Static Functions
-
template<typename T>
static inline void register_printer(std::function<std::string(const T&)> printer) Registers a pretty-printer for type
Tused by debug_string().- Template Parameters:
T – Type to register.
- Parameters:
printer – Functor that renders
constT& to a string.
-
static inline void print_stacktrace()
Prints the current C++ stack trace to
std::cerr.Note
Intended for debugging in exception contexts.
-
static inline void register_basic_printers()
Registers default printers for common scalar types.
Registers printers for:
int,float,double,std::string,bool,char.