Loading...
Searching...
No Matches
ml::MultiCustomStateManager< StateEnums > Class Template Reference

Aggregates state machines for multiple enum types into one class. More...

#include <MultiCustomStateManager.h>

Inheritance diagram for ml::MultiCustomStateManager< StateEnums >:

Public Member Functions

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

Detailed Description

template<typename... StateEnums>
class ml::MultiCustomStateManager< StateEnums >

Aggregates state machines for multiple enum types into one class.

MultiCustomStateManager<StateEnums...> inherits one SingleStateManager per enum in the pack and lifts all their methods into a single overload set. This allows a component to call a single setState, getState, or isState overloaded on enum type, without casting to a specific base.

It is instantiated by GatherStates, which collects all State enums from a component's manifest and from every trait mixed in via ComponentWith.

Example (automatic — no user action required)

struct MyManifest { enum class State { Normal, Selected }; };
// Draggable also has: enum class State { FREE, LOCK_X, LOCK_Y };
class MyWidget : public ml::ComponentWith<MyManifest, Draggable> {};
MyWidget w;
w.setState(MyManifest::State::Selected);
w.setState(ml::Draggable::State::LOCK_X);
w.onStateEnter([](MyManifest::State s) { /* react to MyWidget state changes *\/ });
*
Component< M, Traits... > ComponentWith
Alias for Component<M, Traits...>.
Definition Component.h:150
Template Parameters
StateEnumsZero or more enum class types, one per state machine. The empty specialization is used when no custom states are declared.
See also
SingleStateManager, GatherStates, ComponentCore

MultiCustomStateManager.

Definition at line 131 of file MultiCustomStateManager.h.

Member Function Documentation

◆ getState()

StateEnums ml::SingleStateManager< StateEnums >::getState ( ) const
inlineinherited

Return the current state value.

Returns
The active state.

Definition at line 57 of file MultiCustomStateManager.h.

◆ isState()

bool ml::SingleStateManager< StateEnums >::isState ( StateEnums state) const
inlineinherited

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()

void ml::SingleStateManager< StateEnums >::onStateEnter ( std::function< void(StateEnums)> cb)
inlineinherited

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()

void ml::SingleStateManager< StateEnums >::onStateExit ( std::function< void(StateEnums)> cb)
inlineinherited

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()

void ml::SingleStateManager< StateEnums >::setState ( StateEnums newState)
inlineinherited

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: