A very small (<~200 NLOC), generic FSM implementation in C++.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jens Finkhaeuser 6385a8cf43
Clarify 'lines' in description
1 year ago
docs PlantUML generated "logo" 3 years ago
include/microfsm Allow setting of state; this is not usually a good idea so is being warned about 1 year ago
subprojects Update gtest.wrap 2 years ago
test Add logging functionality 1 year ago
.gitignore Skeleton 3 years ago
.gitlab-ci.yml Need only artifacts from one of the builds 3 years ago
LICENSE.txt Add license 3 years ago
README.md Clarify 'lines' in description 1 year ago
appveyor.yml Fix appveyor? 2 years ago
meson.build Add new flag to the FSM that allows a transition function to not 2 years ago
microfsm.wrap Bump version 3 years ago



A very small (<~200 nloc), generic FSM implementation in C++



  • A C++11 compiler.
  • Maybe meson, for building tests, etc.


  • Any (less-than comparable) type as a state type.
  • Any callable as a transition function.
  • Enforces valid end states at run-time.
  • The FSM design is non-deterministic.


enum state { START, MIDDLE, END };

// Create an instance specifying:
// - potential argument types for the progress and transition
//   functions
// - a start state
// - one or more end states
microfsm<state, arg_type1, ...> fsm{ START, { END }};

// Add transition functions:
// - from a start state
// - with possible end states
    [](state, arg_type1) -> state {
      // Depending on argument, return MIDDLE or END
    { MIDDLE, END }

// Progress from the current state, passing any specified
// arguments.
arg_type1 arg1;
fsm.progress(arg1, ...);

// Read the FSM state or meta state:
auto res = fsm.meta_state(); // one of RUNNING, ENDED, ERRORED
auto s = fsm.current_state(); // one of START, MIDDLE, END
auto e = fsm.error(); // if res == ERRORED

Logging (v0.2.5+)

If you want to know what the FSM does, and especially for logging exceptions that might occur in transition functions, add a log function. Log functions take a message string.

fsm.set_log_function([](std::string const & msg) -> void
      std::cerr << msg << std::endl;


Licensed under MIT +no-false-attribs License