Public Member Functions | |
StateMachine (StateBaseType const &initState, StorageType const &storage=StorageType()) noexcept | |
template<typename EventType > | |
void | handle (EventType const &event) |
StorageType & | storage () noexcept |
StorageType const & | storage () const noexcept |
Detailed Description
template<typename StateBaseType, typename StorageType = std::nullptr_t>
class rili::StateMachine< StateBaseType, StorageType >
This implementation assume, that in every state any possible input event should be somehow handled (even by thrown exception), so to define all possible input events and "default" handlers for them StateBaseType is used.
Other states must derive from it and define custom behaviours of handlers. In one moment in state machine is only one state. So to define whole behaviours of given state polimorphism is strongly used. From usage point of view state is just set of handlers for some events with inheritance chain for handling all other.
Example State:
- Note
- All 'handle' members in state should be const - non const will not be choosen. This is to force correct usage of State.
Constructor & Destructor Documentation
|
inlineexplicitnoexcept |
initialize instance of StateMachine using StateBaseType instance(or inherited) and StorageType storage
- Parameters
-
initState is used as first state to handle events storage is used to initialize internal StateMachine storage (is copied)
Member Function Documentation
|
inline |
is used as sink for all events which should be handled by StateMachine.
It will choose and call one handler in current State, which can handle given event. After handling, it will set state to that, returned by handle method of state for particular event.
- Parameters
-
event
|
inlinenoexcept |
give access to StateMachine storage
- Returns
- storage object reference
|
inlinenoexcept |
give access to StateMachine storage
- Returns
- storage object reference
The documentation for this class was generated from the following file:
- rili/StateMachine.hpp