DUNE: Uniform Navigational Environment
2019.02.1
|
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) |
typedef void(Class::* DUNE::Utils::StateMachine< Class, Data >::OnStateChange) (STATE old_s, STATE new_s, Data &data) |
typedef STATE(Class::* DUNE::Utils::StateMachine< Class, Data >::STATE_) (Data &data) |
|
inline |
Constructor.
initial | initial state. |
osc | optional state change handler. |
|
inline |
Get current state.
|
inline |
Reset to given state.
s | state to set. |
|
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.
obj | object handle. |
data | data handle. |