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

Runs a series of states in parallel. More...

#include <concurrence.hpp>

Inheritance diagram for yasmin::Concurrence:
Collaboration diagram for yasmin::Concurrence:

Public Types

typedef std::map< std::string, std::string > StateOutcomeMap
 
typedef std::map< std::string, StateOutcomeMapOutcomeMap
 

Public Member Functions

 Concurrence (const std::map< std::string, std::shared_ptr< State > > &states, const std::string &default_outcome, const OutcomeMap &outcome_map)
 Constructs a State with a set of possible outcomes.
 
std::string execute (std::shared_ptr< blackboard::Blackboard > blackboard) override
 Executes the state's specific logic.
 
void cancel_state () override
 Cancels the current state execution.
 
const std::map< std::string, std::shared_ptr< State > > & get_states () const
 Returns the map of states managed by this concurrence state.
 
const OutcomeMapget_outcome_map () const
 Returns the outcome map for this concurrence state.
 
const std::string & get_default_outcome () const
 Returns the default outcome for this concurrence state.
 
std::string to_string () override
 Converts the state to a string representation.
 
- Public Member Functions inherited from yasmin::State
 State (const std::set< std::string > &outcomes)
 Constructs a State with a set of possible outcomes.
 
StateStatus get_status () const
 Gets the current status of the state.
 
bool is_idle () const
 Checks if the state is idle.
 
bool is_running () const
 Checks if the state is currently running.
 
bool is_canceled () const
 Checks if the state has been canceled.
 
bool is_completed () const
 Checks if the state has completed execution.
 
std::string operator() (std::shared_ptr< blackboard::Blackboard > blackboard)
 Executes the state and returns the outcome.
 
std::set< std::string > const & get_outcomes ()
 Gets the set of possible outcomes for this state.
 

Protected Attributes

const std::map< std::string, std::shared_ptr< State > > states
 The states to run concurrently (name -> state)
 
const std::string default_outcome
 Default outcome.
 
OutcomeMap outcome_map
 
std::map< std::string, std::shared_ptr< std::string > > intermediate_outcome_map
 Stores the intermediate outcomes of the concurrent states.
 
std::set< std::string > possible_outcomes
 The set of possible outcomes.
 
- Protected Attributes inherited from yasmin::State
std::set< std::string > outcomes
 The possible outcomes of this state.
 

Static Private Member Functions

static std::set< std::string > generate_possible_outcomes (const OutcomeMap &outcome_map, const std::string &default_outcome)
 Helper function to generate a set of possible outcomes from an outcome map.
 

Private Attributes

std::mutex intermediate_outcome_mutex
 Mutex for intermediate outcome map.
 

Detailed Description

Runs a series of states in parallel.

The Concurrence class runs a set of states concurrently, waiting for the termination of each, and then returns a single output according to a provided rule map, or a default outcome if no rule is satisfied.

Member Typedef Documentation

◆ OutcomeMap

typedef std::map<std::string, StateOutcomeMap> yasmin::Concurrence::OutcomeMap

◆ StateOutcomeMap

typedef std::map<std::string, std::string> yasmin::Concurrence::StateOutcomeMap

Constructor & Destructor Documentation

◆ Concurrence()

Concurrence::Concurrence ( const std::map< std::string, std::shared_ptr< State > > & states,
const std::string & default_outcome,
const OutcomeMap & outcome_map )

Constructs a State with a set of possible outcomes.

Parameters
statesA map of state names to states that will run concurrently.
default_outcomeThe default outcome to return if no outcome map rules are satisfied.
outcome_mapA map of outcome names to requirements for achieving that outcome.

Member Function Documentation

◆ cancel_state()

void Concurrence::cancel_state ( )
overridevirtual

Cancels the current state execution.

This method sets the canceled flag to true and logs the action.

Reimplemented from yasmin::State.

◆ execute()

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

Executes the state's specific logic.

Parameters
blackboardA shared pointer to the Blackboard to use during execution.
Returns
A string representing the outcome of the execution.

This method is intended to be overridden by derived classes to provide specific execution logic.

Reimplemented from yasmin::State.

◆ generate_possible_outcomes()

std::set< std::string > Concurrence::generate_possible_outcomes ( const OutcomeMap & outcome_map,
const std::string & default_outcome )
staticprivate

Helper function to generate a set of possible outcomes from an outcome map.

Parameters
outcome_map
default_outcome
Returns
The set of possible outcomes

◆ get_default_outcome()

const std::string & Concurrence::get_default_outcome ( ) const

Returns the default outcome for this concurrence state.

Returns
The default outcome as a string.

◆ get_outcome_map()

const Concurrence::OutcomeMap & Concurrence::get_outcome_map ( ) const

Returns the outcome map for this concurrence state.

Returns
A map of outcome names to their requirements.

◆ get_states()

const std::map< std::string, std::shared_ptr< State > > & Concurrence::get_states ( ) const

Returns the map of states managed by this concurrence state.

Returns
A map of state names to states.

◆ to_string()

std::string yasmin::Concurrence::to_string ( )
inlineoverridevirtual

Converts the state to a string representation.

Returns
A string representation of the state.

Reimplemented from yasmin::State.

Member Data Documentation

◆ default_outcome

const std::string yasmin::Concurrence::default_outcome
protected

Default outcome.

◆ intermediate_outcome_map

std::map<std::string, std::shared_ptr<std::string> > yasmin::Concurrence::intermediate_outcome_map
protected

Stores the intermediate outcomes of the concurrent states.

◆ intermediate_outcome_mutex

std::mutex yasmin::Concurrence::intermediate_outcome_mutex
private

Mutex for intermediate outcome map.

◆ outcome_map

OutcomeMap yasmin::Concurrence::outcome_map
protected

Specifies which combination of state outputs should produce a given overall output

◆ possible_outcomes

std::set<std::string> yasmin::Concurrence::possible_outcomes
protected

The set of possible outcomes.

◆ states

const std::map<std::string, std::shared_ptr<State> > yasmin::Concurrence::states
protected

The states to run concurrently (name -> state)


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