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

Namespaces

namespace  blackboard
 

Classes

class  CbState
 Represents a state that executes a callback function. More...
 
class  Concurrence
 Runs a series of states in parallel. 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.
 

Enumerations

enum  LogLevel { ERROR = 0 , WARN , INFO , DEBUG }
 Enum representing different log levels for controlling log verbosity. More...
 

Functions

void set_log_level (LogLevel 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.
 
void default_log_message (LogLevel level, const char *file, const char *function, int line, const char *text)
 Default logging function.
 

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

◆ 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.

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.

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.
argsAdditional arguments for the format string.

◆ 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
log_messageFunction to create the logs
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 level)

Sets the log level for the logs.

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

Parameters
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.