Loading...
Searching...
No Matches
ml::SingleStateManager< StateEnum > Class Template Reference

State machine for a single enum type. More...

#include <MultiCustomStateManager.h>

Public Member Functions

StateEnum getState () const
 Return the current state value.
bool isState (StateEnum state) const
 Return true if the current state equals state.
void onStateEnter (std::function< void(StateEnum)> cb)
 Register a callback invoked when any state is entered.
void onStateExit (std::function< void(StateEnum)> cb)
 Register a callback invoked when any state is exited.
void setState (StateEnum newState)
 Transition to a new state.

Detailed Description

template<typename StateEnum>
class ml::SingleStateManager< StateEnum >

State machine for a single enum type.

Stores one current state value of type StateEnum and fires optional enter/exit callbacks on every transition. One SingleStateManager base is inherited per distinct state enum.

Note
This class is an implementation detail of MultiCustomStateManager. User code accesses states through the component's unified API.
Template Parameters
StateEnumAn enum class type representing the possible states.
See also
MultiCustomStateManager, GatherStates

Definition at line 30 of file MultiCustomStateManager.h.

Member Function Documentation

◆ getState()

template<typename StateEnum>
StateEnum ml::SingleStateManager< StateEnum >::getState ( ) const
inline

Return the current state value.

Returns
The active state.

Definition at line 57 of file MultiCustomStateManager.h.

◆ isState()

template<typename StateEnum>
bool ml::SingleStateManager< StateEnum >::isState ( StateEnum state) const
inline

Return true if the current state equals state.

Parameters
stateState value to compare against.
Returns
true if currently in state.

Definition at line 64 of file MultiCustomStateManager.h.

◆ onStateEnter()

template<typename StateEnum>
void ml::SingleStateManager< StateEnum >::onStateEnter ( std::function< void(StateEnum)> cb)
inline

Register a callback invoked when any state is entered.

The callback receives the newly entered state as its argument. Only one enter callback is active at a time; calling this again replaces the previous one.

Parameters
cbCallback invoked with the new state after each transition.

Definition at line 75 of file MultiCustomStateManager.h.

◆ onStateExit()

template<typename StateEnum>
void ml::SingleStateManager< StateEnum >::onStateExit ( std::function< void(StateEnum)> cb)
inline

Register a callback invoked when any state is exited.

The callback receives the state being left as its argument. Only one exit callback is active at a time; calling this again replaces the previous one.

Parameters
cbCallback invoked with the old state before each transition.

Definition at line 86 of file MultiCustomStateManager.h.

◆ setState()

template<typename StateEnum>
void ml::SingleStateManager< StateEnum >::setState ( StateEnum newState)
inline

Transition to a new state.

If an exit callback is registered, it is called with the current state before the transition. If an enter callback is registered, it is called with the new state after the transition.

Parameters
newStateThe state to transition into.

Definition at line 46 of file MultiCustomStateManager.h.


The documentation for this class was generated from the following file: