DUNE: Uniform Navigational Environment  2016.09.0
DUNE::Utils::StateMachine< Class, Data > Class Template Reference

Detailed Description

template<typename Class, typename Data>
class DUNE::Utils::StateMachine< Class, Data >

State machine with very lightweight infrastructure, and requiring also very little for instantiation.

States are defined merely by instance methods of an object, that return pointers to other instance methods ie the state to execute in the next step.

See http://www.gotw.ca/gotw/057.htm for the motivation for this type of design. and programs/test/test_StateMachine.cpp for a mock example of use.

Classes

struct  STATE
 

Public Types

typedef STATE(Class::* STATE_ )(Data &data)
 
typedef void(Class::* OnStateChange )(STATE old_s, STATE new_s, Data &data)
 

Public Member Functions

 StateMachine (STATE initial, OnStateChange osc=0)
 
void step (Class &obj, Data &data)
 
STATE current (void)
 
void reset (STATE s)
 

Member Typedef Documentation

template<typename Class , typename Data >
typedef void(Class::* DUNE::Utils::StateMachine< Class, Data >::OnStateChange)(STATE old_s, STATE new_s, Data &data)
template<typename Class , typename Data >
typedef STATE(Class::* DUNE::Utils::StateMachine< Class, Data >::STATE_)(Data &data)

Constructor & Destructor Documentation

template<typename Class , typename Data >
DUNE::Utils::StateMachine< Class, Data >::StateMachine ( STATE  initial,
OnStateChange  osc = 0 
)
inline

Constructor.

Parameters
initialinitial state.
oscoptional state change handler.

Member Function Documentation

template<typename Class , typename Data >
STATE DUNE::Utils::StateMachine< Class, Data >::current ( void  )
inline

Get current state.

Returns
current state.
template<typename Class , typename Data >
void DUNE::Utils::StateMachine< Class, Data >::reset ( STATE  s)
inline

Reset to given state.

Parameters
sstate to set.
template<typename Class , typename Data >
void DUNE::Utils::StateMachine< Class, Data >::step ( Class &  obj,
Data &  data 
)
inline

Perform one step in the state machine.

It calls the current state handler. Then, if the state changes and the state-change handler is defined, the latter will be invoked.

Parameters
objobject handle.
datadata handle.
Collaboration diagram for DUNE::Utils::StateMachine< Class, Data >:
Collaboration graph