FSMgine
High-performance finite state machine library for C++17 with single-threaded and multi-threaded variants
Loading...
Searching...
No Matches
fsmgine::FSMBuilder< TEvent > Class Template Reference

Main builder class for constructing FSMs with a fluent interface. More...

#include <FSMBuilder.hpp>

Public Types

using Action = typename FSM< TEvent >::Action
 Type alias for state actions.
 

Public Member Functions

 FSMBuilder (FSM< TEvent > &fsm)
 Constructs a builder for the given FSM.
 
 FSMBuilder (const FSMBuilder &)=delete
 
FSMBuilderoperator= (const FSMBuilder &)=delete
 
 FSMBuilder (FSMBuilder &&)=default
 Move constructor (defaulted)
 
FSMBuilderoperator= (FSMBuilder &&)=default
 Move assignment operator (defaulted)
 
TransitionBuilder< TEvent > from (const std::string &state)
 Starts building a transition from the specified state.
 
FSMBuilderonEnter (const std::string &state, Action action)
 Adds an action to execute when entering a state.
 
FSMBuilderonExit (const std::string &state, Action action)
 Adds an action to execute when exiting a state.
 

Detailed Description

template<typename TEvent>
class fsmgine::FSMBuilder< TEvent >

Main builder class for constructing FSMs with a fluent interface.

Template Parameters
TEventThe event type used for transitions

FSMBuilder provides a fluent API for constructing finite state machines. It supports:

  • Defining transitions between states
  • Adding on-enter and on-exit actions to states
  • Building complex state machines in a readable, declarative style
Example
fsm.get_builder()
// Define state actions
.onEnter("Idle", [](const MyEvent&) { std::cout << "Entering Idle\n"; })
.onExit("Idle", [](const MyEvent&) { std::cout << "Leaving Idle\n"; })
// Define transitions
.from("Idle")
.predicate([](const MyEvent& e) { return e.type == "start"; })
.to("Running")
.from("Running")
.predicate([](const MyEvent& e) { return e.type == "stop"; })
.to("Idle");
fsm.setInitialState("Idle");
FSMBuilder & onExit(const std::string &state, Action action)
Adds an action to execute when exiting a state.
Definition FSMBuilder.hpp:203
TransitionBuilder< TEvent > from(const std::string &state)
Starts building a transition from the specified state.
Definition FSMBuilder.hpp:186
A high-performance finite state machine implementation.
Definition FSM.hpp:94
Main namespace for the FSMgine library.
Definition FSM.hpp:23

Constructor & Destructor Documentation

◆ FSMBuilder()

template<typename TEvent >
fsmgine::FSMBuilder< TEvent >::FSMBuilder ( FSM< TEvent > &  fsm)
explicit

Constructs a builder for the given FSM.

Parameters
fsmThe FSM to build

Member Function Documentation

◆ from()

template<typename TEvent >
TransitionBuilder< TEvent > fsmgine::FSMBuilder< TEvent >::from ( const std::string &  state)

Starts building a transition from the specified state.

Parameters
stateThe source state for the transition
Returns
A TransitionBuilder for defining the transition details

◆ onEnter()

template<typename TEvent >
FSMBuilder< TEvent > & fsmgine::FSMBuilder< TEvent >::onEnter ( const std::string &  state,
Action  action 
)

Adds an action to execute when entering a state.

Parameters
stateThe state to add the action to
actionThe action to execute when entering the state
Returns
Reference to this builder for method chaining

◆ onExit()

template<typename TEvent >
FSMBuilder< TEvent > & fsmgine::FSMBuilder< TEvent >::onExit ( const std::string &  state,
Action  action 
)

Adds an action to execute when exiting a state.

Parameters
stateThe state to add the action to
actionThe action to execute when exiting the state
Returns
Reference to this builder for method chaining

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