Robot Devastation
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
rd::StateMachineBuilder Class Reference

Class that helps with the creation of FiniteStateMachine.

#include <StateMachineBuilder.hpp>

Public Member Functions

bool setDirectorType (const std::string &type)
 Select the type of StateDirector to be used. More...
 
bool setInitialState (int initial_state_id)
 Configure the initial state of the FiniteStateMachine.
 
int addState (State *state)
 Adds a State to the FiniteStateMachine. More...
 
bool addTransition (int origin_id, int destination_id, int condition)
 Adds a transition from one state to other one depending on a condition. More...
 
FiniteStateMachinebuildStateMachine ()
 Creates a FiniteStateMachine. More...
 

Protected Member Functions

StateDirectorcreateStateDirector (const std::string &type, State *state)
 Factory method to create a StateDirector from the type string. More...
 

Private Attributes

std::vector< State * > states
 
std::vector< StateDirector * > stateDirectors
 
std::map< int, std::vector< std::pair< int, int > > > transition_table
 Stores the transitions of the fsm. More...
 
std::string type
 
int initial_state_id
 

Member Function Documentation

◆ addState()

int rd::StateMachineBuilder::addState ( State state)
Parameters
stateState to be added
Returns
Id Id assigned to the State added

◆ addTransition()

bool rd::StateMachineBuilder::addTransition ( int  origin_id,
int  destination_id,
int  condition 
)
Parameters
origin_idId of the origin state
destination_idId of the destination state
conditionCondition to trigger this transition

◆ buildStateMachine()

rd::FiniteStateMachine * rd::StateMachineBuilder::buildStateMachine ( )

Once the FiniteStateMachine has been configured, this function has to be called to obtain the FiniteStateMachine.start()

The returned FiniteStateMachine has to be deleted with the delete operator to released the dynamically allocated memory.

Returns
The created FiniteStateMachine

◆ createStateDirector()

rd::StateDirector * rd::StateMachineBuilder::createStateDirector ( const std::string &  type,
State state 
)
protected

This factory method could be extracted to a factory class to allow new StateDirector without recompiling the StateMachineLib

◆ setDirectorType()

bool rd::StateMachineBuilder::setDirectorType ( const std::string &  type)

The default StateDirector is the YarpStateDirector

Member Data Documentation

◆ transition_table

std::map< int, std::vector<std::pair<int, int> > > rd::StateMachineBuilder::transition_table
private

The format is the following: { origin_state:[(destination_state, condition)]}


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