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

Represents a state that executes a callback function. More...

#include <cb_state.hpp>

Inheritance diagram for yasmin::CbState:
Collaboration diagram for yasmin::CbState:

Public Member Functions

 CbState (std::set< std::string > outcomes, std::string(*callback)(std::shared_ptr< blackboard::Blackboard > blackboard))
 Constructs a CbState object.
 
std::string execute (std::shared_ptr< blackboard::Blackboard > blackboard) override
 Executes the callback function.
 
- Public Member Functions inherited from yasmin::State
 State (std::set< std::string > outcomes)
 Constructs a State with a set of possible outcomes.
 
std::string operator() (std::shared_ptr< blackboard::Blackboard > blackboard)
 Executes the state and returns the outcome.
 
virtual void cancel_state ()
 Cancels the current state execution.
 
bool is_canceled () const
 Checks if the state has been canceled.
 
bool is_running () const
 Checks if the state is currently running.
 
std::set< std::string > const & get_outcomes ()
 Gets the set of possible outcomes for this state.
 
virtual std::string to_string ()
 Converts the state to a string representation.
 

Private Attributes

std::string(* callback )(std::shared_ptr< blackboard::Blackboard > blackboard)
 Pointer to the callback function to be executed.
 

Additional Inherited Members

- Protected Attributes inherited from yasmin::State
std::set< std::string > outcomes
 The possible outcomes of this state.
 

Detailed Description

Represents a state that executes a callback function.

The CbState class inherits from the State class and is designed to execute a user-defined callback function, utilizing a shared pointer to a Blackboard object to obtain necessary data.

Constructor & Destructor Documentation

◆ CbState()

yasmin::CbState::CbState ( std::set< std::string > outcomes,
std::string(* callback )(std::shared_ptr< blackboard::Blackboard > blackboard) )

Constructs a CbState object.

Parameters
outcomesA set of possible outcomes for this state.
callbackA function pointer to the callback function that will be executed when this state is activated.
Exceptions
std::invalid_argumentIf the outcomes set is empty.

Member Function Documentation

◆ execute()

std::string yasmin::CbState::execute ( std::shared_ptr< blackboard::Blackboard > blackboard)
overridevirtual

Executes the callback function.

This function is called to execute the callback and retrieve the result. It may use the provided Blackboard for additional data.

Parameters
blackboardA shared pointer to the Blackboard object used during execution.
Returns
The result of the callback function execution as a string.
Exceptions
std::runtime_errorIf the callback execution fails.

Reimplemented from yasmin::State.

Member Data Documentation

◆ callback

std::string(* yasmin::CbState::callback) (std::shared_ptr< blackboard::Blackboard > blackboard)
private

Pointer to the callback function to be executed.


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