A template class to create a BaseStepable object with simple statemachine capabilities. More...
#include "murl_logic_state_machine.h"
Public Types | |
using | ValueType = StateType |
The template state parameter value type. | |
Public Member Functions | |
StateMachine () | |
The default constructor. | |
~StateMachine () override | |
The destructor. | |
template<class ObjectType > | |
Bool | Register (const StateType &state, ObjectType *objectInstance, typename StateMethods< ObjectType >::ObjectMethod onProcessTick, typename StateMethods< ObjectType >::ObjectMethod onEnterTick=0, typename StateMethods< ObjectType >::ObjectMethod onLeaveTick=0, typename StateMethods< ObjectType >::ObjectMethod onFinishTick=0) |
Register a state and the corresponding method calls. More... | |
Bool | Unregister (const StateType &state) |
Unregister a state and the corresponding method calls. More... | |
void | SetNextState (const StateType &nextState) |
Set the next state. More... | |
Bool | IsNextState () const |
Check if the next state is set. More... | |
const StateType & | GetNextState () const |
Get the next state. More... | |
const StateType & | GetPreviousState () const |
Get the previous state. More... | |
const StateType & | GetCurrentState () const |
Get the current state. More... | |
Public Member Functions inherited from Murl::Logic::BaseStepable | |
BaseStepable () | |
The default constructor. More... | |
~BaseStepable () override | |
The destructor. More... | |
operator IStepablePtr () | |
Conversion operator. More... | |
Public Member Functions inherited from Murl::Logic::Stepable | |
~Stepable () override | |
The destructor. | |
Bool | SetAppStepable (IAppStepablePtr appStepable) override |
Implementation of IStepable::SetAppStepable() method. More... | |
void | SetEnabled (Bool isEnabled) override |
Implementation of IStepable::SetEnabled() method. More... | |
Bool | IsEnabled () const override |
Implementation of IStepable::IsEnabled() method. More... | |
void | Reset () override |
Implementation of IStepable::Reset() method. | |
void | ProcessTick (const Logic::IState *state) override |
Implementation of IStepable::ProcessTick() method. More... | |
void | FinishTick (const Logic::IState *state) override |
Implementation of IStepable::FinishTick() method. More... | |
Protected Member Functions | |
void | OnReset () override |
Overwrite of the BaseStepable::OnReset() method. More... | |
void | OnProcessTick (const IState *state) override |
Overwrite of the BaseStepable::OnProcessTick() method. More... | |
void | OnFinishTick (const IState *state) override |
Overwrite of the BaseStepable::OnFinishTick() method. More... | |
Protected Member Functions inherited from Murl::Logic::BaseStepable | |
void | OnSetEnabled (Bool isEnabled) override |
Default implementation of IAppStepable::OnSetEnabled() method, this method is empty and can be overwritten. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from Murl::Logic::Stepable | |
static IStepablePtr | Create () |
Create a stepable object. More... | |
Detailed Description
template<class StateType, class HashFunc = StdHash<StateType>>
class Murl::Logic::StateMachine< StateType, HashFunc >
A template class to create a BaseStepable object with simple statemachine capabilities.
The statemachine can register any number of states, for each state a class method call can be registered for:
- OnEnterTick the state
- OnProcessTick the state
- OnLeaveTick the state
- OnFinishTick the state
Usage e.g. my_processor.h:
and e.g. my_processor.cpp:
To change the state simply call:
This execute at the next logic tick:
- OnLeaveTick of the current state and OnEnterTick of the next state.
- All following logic ticks execute OnProcessTick / OnFinishTick of the (new) current state.
If OnEnterTick is null OnProcessTick is called instead.
- Template Parameters
-
StateType The data type of the state. HashFunc The hash function of the state type.
Member Function Documentation
◆ Register()
|
inline |
Register a state and the corresponding method calls.
- Template Parameters
-
ObjectType The type of the class to call.
- Parameters
-
state The state to register. objectInstance The instance of the object to call. onProcessTick The method to call on process or null for no action. onEnterTick The method to call on enter or null for no action. onLeaveTick The method to call on leave or null for no action. onFinishTick The method to call on finish or null for no action.
- Returns
- true if the state was successfuly registered, false if the state is already registered.
◆ Unregister()
|
inline |
Unregister a state and the corresponding method calls.
- Parameters
-
state The state to unregister.
- Returns
- true if the state was successfuly unregistered.
◆ SetNextState()
|
inline |
Set the next state.
- Parameters
-
nextState The next state.
◆ IsNextState()
|
inline |
Check if the next state is set.
- Returns
- true if the next state is set.
◆ GetNextState()
|
inline |
Get the next state.
- Returns
- The next state.
◆ GetPreviousState()
|
inline |
Get the previous state.
- Returns
- The previous state.
◆ GetCurrentState()
|
inline |
Get the current state.
- Returns
- The current state.
◆ OnReset()
|
inlineoverrideprotectedvirtual |
Overwrite of the BaseStepable::OnReset() method.
Reset the states to the state's default constructor.
Reimplemented from Murl::Logic::BaseStepable.
◆ OnProcessTick()
|
inlineoverrideprotectedvirtual |
Overwrite of the BaseStepable::OnProcessTick() method.
Either execute OnProcessTick of the current state, or OnLeaveTick of the current state and OnEnterTick of the next state, if the next state was set. If OnEnterTick is null OnProcessTick is called instead.
- Parameters
-
state The IState object.
Reimplemented from Murl::Logic::BaseStepable.
◆ OnFinishTick()
|
inlineoverrideprotectedvirtual |
Overwrite of the BaseStepable::OnFinishTick() method.
Execute OnFinishTick of the current state.
- Parameters
-
state The IState object.
Reimplemented from Murl::Logic::BaseStepable.
The documentation for this class was generated from the following file:
- murl_logic_state_machine.h