fsmlite API Reference

template <class Derived, class State = int>
class fsm

Finite state machine (FSM) base class template.

Template Parameters
  • Derived: the derived state machine class
  • State: the FSM’s state type, defaults to int

Public Types

typedef State state_type

The FSM’s state type.

Public Functions

fsm(state_type init_state = state_type())

Create a state machine with an optional initial state.

Parameters
  • init_state: the FSM’s initial state

template <class Event>
void process_event(const Event &event)

Process an event.

Warning
This member function must not be called recursively, e.g. from another fsm instance.
Template Parameters
  • Event: the event type
Parameters
  • event: the event instance
Exceptions
  • std::logic_error: if a recursive invocation is detected

state_type current_state() const

Return the state machine’s current state.

Protected Types

template<>
using table = detail::list<Rows...>

Transition table variadic class template.

Each derived state machine class must define a nested non-template type transition_table that’s either derived from or a type alias of table.

Protected Functions

template <class Event>
state_type no_transition(const Event&)

Called when no transition can be found for the given event in the current state.

Derived state machines may override this to throw an exception, or change to some other (error) state. The default is to return the current state, so no state change occurs.

Return
the FSM’s new state
Template Parameters
  • Event: the event type
Parameters
  • event: the event instance

template <State start, class Event, State target, class Action = std::nullptr_t, Action action = nullptr, class Guard = std::nullptr_t, Guard guard = nullptr>
struct basic_row : public fsmlite::fsm<start, Event, target>::row_base

Basic transition class template.

Template Parameters
  • start: the start state of the transition
  • Event: the event type triggering the transition
  • target: the target state of the transition
  • Action: an action function type, or std::nullptr_t
  • action: a static Action instance
  • Guard: a guard function type, or std::nullptr_t
  • guard: a static Guard instance

template <State start, class Event, State target, void(Derived::*)(const Event &) action = nullptr, bool(Derived::*)(const Event &) const guard = nullptr>
struct mem_fn_row : public fsmlite::fsm<start, Event, target>::row_base

Member function transition class template.

Template Parameters
  • start: the start state of the transition
  • Event: the event type triggering the transition
  • target: the target state of the transition
  • action: an action member function, or nullptr
  • guard: a guard member function, or nullptr

template <State start, class Event, State target, auto action = nullptr, auto guard = nullptr>
struct row : public fsmlite::fsm<start, Event, target>::row_base

Generic transition class template (requires C++17).

Template Parameters
  • start: the start state of the transition
  • Event: the event type triggering the transition
  • target: the target state of the transition
  • action: a static action function pointer, or nullptr
  • guard: a static guard function pointer, or nullptr