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

Namespaces

namespace  pybind11_utils
 

Classes

class  Blackboard
 A thread-safe storage for key-value pairs of varying types. More...
 
class  BlackboardPyWrapper
 A wrapper around the C++ Blackboard that stores Python objects and native types. More...
 
class  CbState
 Represents a state that executes a callback function. More...
 
class  Concurrence
 Runs a series of states in parallel. More...
 
class  PyState
 Trampoline class to enable Python classes to inherit from C++ State. More...
 
class  State
 Represents a state in a state machine. More...
 
class  StateMachine
 A class that implements a state machine with a set of states, transitions, and callback mechanisms for state changes. More...
 

Typedefs

typedef void(* LogFunction) (LogLevel level, const char *file, const char *function, int line, const char *text)
 Type definition for a logging function.
 
using StringSet = std::set<std::string>
 Set of strings.
 
using StringMap = std::unordered_map<std::string, std::string>
 Map from string to string.
 
using Outcomes = StringSet
 Set of possible outcomes for states.
 
using StateOutcomeMap = StringMap
 Map of state names to their outcomes.
 
using OutcomeMap = std::unordered_map<std::string, StateOutcomeMap>
 Map of outcomes to state outcome maps.
 
using Transitions = StringMap
 Map of transitions (string to string)
 
using TransitionsMap = std::unordered_map<std::string, Transitions>
 Map of state names to transitions.
 
using Remappings = StringMap
 Map of remappings (string to string)
 
using RemappingsMap = std::unordered_map<std::string, Remappings>
 Map of keys to remappings.
 
using TypeRegistry = StringMap
 Registry for type information.
 
using BlackboardPtr = std::shared_ptr<Blackboard>
 Shared pointer to Blackboard.
 
using StatePtr = std::shared_ptr<State>
 Shared pointer to State.
 
using StateMachinePtr = std::shared_ptr<StateMachine>
 Shared pointer to StateMachine.
 
using ConcurrencePtr = std::shared_ptr<Concurrence>
 Shared pointer to Concurrence.
 
using StateMap = std::unordered_map<std::string, std::shared_ptr<State>>
 Map of state names to state pointers.
 
using CbStateCallback = std::function<std::string(std::shared_ptr<Blackboard>)>
 Callback function type for CbState.
 

Enumerations

enum  LogLevel { ERROR = 0 , WARN , INFO , DEBUG }
 Enum representing different log levels for controlling log verbosity. More...
 
enum class  StateStatus { IDLE , RUNNING , CANCELED , COMPLETED }
 Enumeration representing the current status of a state. More...
 

Functions

std::string demangle_type (const std::string &mangled_name)
 Demangle a C++ type name to a human-readable format.
 
void default_log_message (LogLevel level, const char *file, const char *function, int line, const char *text)
 Default logging function.
 
void set_log_level (LogLevel new_log_level)
 Sets the log level for the logs.
 
const char * log_level_to_name (LogLevel level)
 Parse LogLevel to string.
 
template<yasmin::LogLevel LEVEL>
void log_helper (const char *file, const char *function, int line, const char *text,...)
 Variadic template function to log messages at different levels.
 
const char * extract_filename (const char *path)
 Extracts the filename from a given file path.
 
void set_loggers (LogFunction log_message)
 Sets custom logging functions for different log levels.
 
void set_default_loggers ()
 Sets the default logging function for all log levels.
 

Variables

LogLevel log_level = INFO
 The current log level for the application.
 
LogFunction log_message = default_log_message
 Pointer to the logging function.
 

Typedef Documentation

◆ BlackboardPtr

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

Shared pointer to Blackboard.

◆ CbStateCallback

using yasmin::CbStateCallback = std::function<std::string(std::shared_ptr<Blackboard>)>

Callback function type for CbState.

◆ ConcurrencePtr

using yasmin::ConcurrencePtr = std::shared_ptr<Concurrence>

Shared pointer to Concurrence.

◆ LogFunction

typedef void(* yasmin::LogFunction) (LogLevel level, const char *file, const char *function, int line, const char *text)

Type definition for a logging function.

This type represents a function pointer that takes a file name, function name, line number, log message, and a variable number of additional arguments for formatting the log message.

Parameters
levelThe log level of the message
fileThe name of the source file where the log function is called.
functionThe name of the function where the log function is called.
lineThe line number in the source file where the log function is called.
textThe format string for the log message, similar to printf.
...Additional arguments for the format string.

◆ OutcomeMap

using yasmin::OutcomeMap = std::unordered_map<std::string, StateOutcomeMap>

Map of outcomes to state outcome maps.

◆ Outcomes

Set of possible outcomes for states.

◆ Remappings

Map of remappings (string to string)

◆ RemappingsMap

using yasmin::RemappingsMap = std::unordered_map<std::string, Remappings>

Map of keys to remappings.

◆ StateMachinePtr

using yasmin::StateMachinePtr = std::shared_ptr<StateMachine>

Shared pointer to StateMachine.

◆ StateMap

using yasmin::StateMap = std::unordered_map<std::string, std::shared_ptr<State>>

Map of state names to state pointers.

◆ StateOutcomeMap

Map of state names to their outcomes.

◆ StatePtr

using yasmin::StatePtr = std::shared_ptr<State>

Shared pointer to State.

◆ StringMap

using yasmin::StringMap = std::unordered_map<std::string, std::string>

Map from string to string.

◆ StringSet

using yasmin::StringSet = std::set<std::string>

Set of strings.

◆ Transitions

Map of transitions (string to string)

◆ TransitionsMap

using yasmin::TransitionsMap = std::unordered_map<std::string, Transitions>

Map of state names to transitions.

◆ TypeRegistry

Registry for type information.

Enumeration Type Documentation

◆ LogLevel

Enum representing different log levels for controlling log verbosity.

This enum defines the severity levels of logs that can be used to control which log messages should be displayed. The levels are ordered from most severe to least severe. Only logs at or above the current log level will be shown.

Enumerator
ERROR 

Log level for error messages. Only critical errors should be logged.

WARN 

Log level for warning messages. Indicate potential issues that are not critical.

INFO 

Log level for informational messages. General runtime information about the system's state.

DEBUG 

Log level for debug messages. Used for detailed information, mainly for developers.

◆ StateStatus

enum class yasmin::StateStatus
strong

Enumeration representing the current status of a state.

Enumerator
IDLE 

State is idle and ready to execute.

RUNNING 

State is currently executing.

CANCELED 

State execution has been canceled.

COMPLETED 

State execution has completed successfully.

Function Documentation

◆ default_log_message()

void yasmin::default_log_message ( LogLevel level,
const char * file,
const char * function,
int line,
const char * text )

Default logging function.

Parameters
levelThe log level as a string (e.g., "ERROR", "WARN", "INFO", "DEBUG").
fileThe source file where the log function is called.
functionThe function where the log function is called.
lineThe line number in the source file.
textThe format string for the log message.

◆ demangle_type()

std::string yasmin::demangle_type ( const std::string & mangled_name)
inline

Demangle a C++ type name to a human-readable format.

Parameters
mangled_nameThe mangled type name.
Returns
The demangled type name.

◆ extract_filename()

const char * yasmin::extract_filename ( const char * path)
inline

Extracts the filename from a given file path.

This function takes a full path to a file and returns just the file name.

Parameters
pathThe full path to the file.
Returns
A pointer to the extracted filename.

◆ log_helper()

template<yasmin::LogLevel LEVEL>
void yasmin::log_helper ( const char * file,
const char * function,
int line,
const char * text,
... )

Variadic template function to log messages at different levels.

This function wraps log_message and allows logging messages with different log levels while reducing redundant code. It provides a consistent logging format across all levels.

Template Parameters
LEVELThe log level LogLevel (e.g., 0 -> "ERROR", 1 -> "WARN", 2 -> "INFO", 3 -> "DEBUG").
Parameters
fileThe source file where the log function is called.
functionThe function where the log function is called.
lineThe line number in the source file.
textThe format string for the log message.
...Additional arguments for the format string.

◆ log_level_to_name()

const char * yasmin::log_level_to_name ( LogLevel level)

Parse LogLevel to string.

This function returns the name of a given log level.

Parameters
levelLog level.

◆ set_default_loggers()

void yasmin::set_default_loggers ( )

Sets the default logging function for all log levels.

This function initializes the logging function to the default implementations.

◆ set_log_level()

void yasmin::set_log_level ( LogLevel new_log_level)

Sets the log level for the logs.

This function allows the user to specify the log level error, warning, info, or debug.

Parameters
new_log_levelLog level.

◆ set_loggers()

void yasmin::set_loggers ( LogFunction log_message)

Sets custom logging functions for different log levels.

This function allows the user to specify custom logging functions for error, warning, info, and debug logs. If a null function is provided for any log level, the default logging function will be used instead.

Parameters
errorPointer to the custom error logging function.
warnPointer to the custom warning logging function.
infoPointer to the custom info logging function.
debugPointer to the custom debug logging function.

Variable Documentation

◆ log_level

LogLevel yasmin::log_level = INFO

The current log level for the application.

This global variable holds the current log level, which determines the verbosity of the logs. Logs at or above this level will be displayed. The default level is set to INFO.

◆ log_message

LogFunction yasmin::log_message = default_log_message

Pointer to the logging function.