Skip to content
This repository was archived by the owner on Nov 16, 2025. It is now read-only.

FiniteStateMachine isInState()

ged edited this page Sep 9, 2024 · 5 revisions

Definition

Checks if the state machine is currently in the specified state.

template<class TContext>
bool isInState(FiniteStateMachine<TContext>::State& state) const

Type Parameters

  • TContext: The type of the context, which holds data or behavior relevant to the state machine.

Parameters

  • state: The state to be compared.

Returns

true if the state is the current state, otherwise false.

Remarks

This function allows querying whether the current state matches the provided state.
Useful for controlling flow based on the state machine's active state.

Usage

auto ctx = static_cast<int>(5);
auto fsm = FiniteStateMachine<int>(&ctx);

auto state1 = FiniteStateMachine<int>::State(state1_enter, state1_update, state1_exit);
auto state2 = FiniteStateMachine<int>::State(state2_enter, state2_update, nullptr);
...

if (fsm.isInState(state1))
{
    /* do something */
}
else if (fsm.isInState(state2))
{
    /* do something */
}

Clone this wiki locally