This class models a state machine. It keeps track of the current state and allows to invoke its associated state function. The return value of the state function determines the new state to transition into. Additionally, a context of type StateMachineContext can be assigned to the state machine. Contexts allow for replacing states with other states. This makes sense to write inner protocols BeginState -> StateA -> ... -> StateN -> EndState and to embed them into outer protocols. The outer protocol can transition into BeginState and take control back by replacing EndState with one of its own states by setting a respective context. All states (of type StateMachineState) have to be registered upon construction of the StateMachine instance.
More...
|
template<typename... StateMachineStateTs> |
| StateMachine (const StateType &InitialState, const StateMachineStateTs &... States) |
| Constructs a state machine assigning possible states to it. Automatically also adds InitialState , so don't include it into States . More...
|
|
const StateType * | GetCurrentState () const noexcept |
| Returns a pointer to the current state. More...
|
|
const ContextType * | GetContext () const noexcept |
| Returns a pointer to the current context. More...
|
|
void | SetCurrentState (StateEnumType NewState) |
| Sets the current state as identified by an element from StateEnumType . More...
|
|
void | SetContext (const ContextType *NewContext) |
| Sets the current state machine context. More...
|
|
void | ResetContext () |
| Removes the current state machine context. More...
|
|
template<typename... ArgTs> |
void | Invoke (instance_of_t< typename StateType::CallableType > &Instance, ArgTs &&... Args) |
| Invokes the state function associated with the current state machine state on an instance of the class the state functions are member functions of. Refer to class StateMachineState. Also sets the state machine's state to the return value of the state function. More...
|
|
template<typename StateMachineStateT>
class Util::StateMachine< StateMachineStateT >
This class models a state machine. It keeps track of the current state and allows to invoke its associated state function. The return value of the state function determines the new state to transition into. Additionally, a context of type StateMachineContext can be assigned to the state machine. Contexts allow for replacing states with other states. This makes sense to write inner protocols BeginState -> StateA -> ... -> StateN -> EndState and to embed them into outer protocols. The outer protocol can transition into BeginState and take control back by replacing EndState with one of its own states by setting a respective context. All states (of type StateMachineState) have to be registered upon construction of the StateMachine instance.
- Template Parameters
-
Definition at line 1434 of file Util.h.
◆ ContextType
template<typename StateMachineStateT >
◆ StateEnumType
template<typename StateMachineStateT >
◆ StateType
template<typename StateMachineStateT >
◆ StateMachine()
template<typename StateMachineStateT >
template<typename... StateMachineStateTs>
Constructs a state machine assigning possible states to it. Automatically also adds InitialState
, so don't include it into States
.
- Template Parameters
-
...StateMachineStateTs | Type of the States parameter pack |
- Parameters
-
InitialState | Initial state of the state machine. |
...States | Possible states the state machine can transition into. Pass states by reference to prevent from null pointers. |
Definition at line 1450 of file Util.h.
◆ GetContext()
template<typename StateMachineStateT >
Returns a pointer to the current context.
Definition at line 1456 of file Util.h.
◆ GetCurrentState()
template<typename StateMachineStateT >
Returns a pointer to the current state.
Definition at line 1455 of file Util.h.
◆ Invoke()
template<typename StateMachineStateT >
template<typename... ArgTs>
Invokes the state function associated with the current state machine state on an instance of the class the state functions are member functions of. Refer to class StateMachineState. Also sets the state machine's state to the return value of the state function.
- Template Parameters
-
...ArgTs | Type of the parameter pack to forward to the state function |
- Parameters
-
Instance | Instance to invoke the state function on |
...Args | Parameters to forward to the state function |
- Exceptions
-
Definition at line 1492 of file Util.h.
◆ ResetContext()
template<typename StateMachineStateT >
Removes the current state machine context.
Definition at line 1480 of file Util.h.
◆ SetContext()
template<typename StateMachineStateT >
Sets the current state machine context.
- Parameters
-
Definition at line 1475 of file Util.h.
◆ SetCurrentState()
template<typename StateMachineStateT >
Sets the current state as identified by an element from StateEnumType
.
- Parameters
-
NewState | Identifier of the new state machine state |
- Exceptions
-
throw | std::out_of_range is thrown if NewState does not exist in StatesList . |
Definition at line 1463 of file Util.h.
◆ CurrentContext
template<typename StateMachineStateT >
◆ CurrentState
template<typename StateMachineStateT >
◆ StatesList
template<typename StateMachineStateT >
Map of possible states. All states are uniquely identified by an element from StateEnumType
. Refer to StateMachineState.
Definition at line 1508 of file Util.h.
The documentation for this class was generated from the following file: