All Projects → eglimi → cppfsm

eglimi / cppfsm

Licence: MIT License
A simple, generic, header-only state machine implementation for C++.

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to cppfsm

animation-system
An experiment on creating an animation system similar to Unreal Engine 4 from scratch.
Stars: ✭ 24 (-48.94%)
Mutual labels:  state-machine
spring-statemachine-learning
spring-statemachine 学习记录
Stars: ✭ 84 (+78.72%)
Mutual labels:  state-machine
qm
QM model-based design tool and code generator based on UML state machines
Stars: ✭ 54 (+14.89%)
Mutual labels:  state-machine
statemachine-go
🚦 Declarative Finite-State Machines in Go
Stars: ✭ 47 (+0%)
Mutual labels:  state-machine
typed-machine
A strict Finite State Machine, written in TS
Stars: ✭ 21 (-55.32%)
Mutual labels:  state-machine
golib
Open version of common golang libraries useful to many projects.
Stars: ✭ 47 (+0%)
Mutual labels:  state-machine
pyrfidhid
Python library to control Chinese USB HID 125Khz RFID Reader/Writer
Stars: ✭ 104 (+121.28%)
Mutual labels:  state-machine
fea state machines
A Buffet Of C++17 State Machines
Stars: ✭ 19 (-59.57%)
Mutual labels:  state-machine
xstate-cpp-generator
C++ State Machine generator for Xstate
Stars: ✭ 33 (-29.79%)
Mutual labels:  state-machine
free-category
Free categories, free arrows and free categories with monadic actions
Stars: ✭ 21 (-55.32%)
Mutual labels:  state-machine
ember-fsm
[Maintenance Mode] A promise-aware finite state machine implementation for Ember
Stars: ✭ 37 (-21.28%)
Mutual labels:  state-machine
xstate-catalogue
Professionally designed, interactive state machines
Stars: ✭ 616 (+1210.64%)
Mutual labels:  state-machine
state machines-graphviz
Graphviz module for state machines
Stars: ✭ 27 (-42.55%)
Mutual labels:  state-machine
useStateMachine
The <1 kb state machine hook for React
Stars: ✭ 2,231 (+4646.81%)
Mutual labels:  state-machine
SimpleStateMachineLibrary
📚 A simple library for realization state machines in C# code
Stars: ✭ 30 (-36.17%)
Mutual labels:  state-machine
aerial autonomy
Easily extendable package for interacting with and defining state machines for autonomous aerial systems
Stars: ✭ 22 (-53.19%)
Mutual labels:  state-machine
examples
YAKINDU Statechart Tools examples
Stars: ✭ 20 (-57.45%)
Mutual labels:  state-machine
aper
A Rust data structure library built on state machines.
Stars: ✭ 100 (+112.77%)
Mutual labels:  state-machine
react-gizmo
🦎 React Gizmo - UI Finite State Machine for React
Stars: ✭ 39 (-17.02%)
Mutual labels:  state-machine
statebot
Write more robust and understandable programs. Statebot hopes to make Finite State Machines a little more accessible.
Stars: ✭ 24 (-48.94%)
Mutual labels:  state-machine

Finite State Machine for C++

A simple, generic, header-only state machine implementation for C++.

Documentation

Please see the documentation in fsm.h for detailed documentation about the implemented features and semantics.

Some more information about this component can also be found on our website. See article 1 for the motivation, and article 2 for the implementation.

Usage

The implementation is contained in a single header file, fsm.h. Simply copy the file to a convenient place in your project and include it.

Example

As an example, consider the state machine below. It starts in state A. When it receives the exec trigger, it checks that the count variable is 1, increments it, and changes to state B.

       +------+  Exec[count=1] / count++    +------+
  o--->|  A   |---------------------------->|  B   |
       +------+                             +------+

The implementation of this state machine is done in a declarative way.

int count = 1;
enum class States { A, B };
enum class Triggers { Exec };
FSM::Fsm<States, States::A, Triggers> fsm;
fsm.add_transitions({
//  from state ,to state  ,triggers        ,guard                    ,action
  { States::A  ,States::B ,Triggers::Exec  ,[&]{return count == 1;}  ,[&]{count++;} },
});
fsm.execute(Triggers::Exec);
assert(count == 2);
assert(fsm.state() == States::B);

See the tests for more examples.

Stability

The implementation is already in use in different commercial applications. We have not found any issues so far. Please report any problems you find.

Tests

Tests can be run with

cd tests
g++ -std=c++11 -Wall -o tests fsm_test.cpp
./tests

Contributions

Contributions are welcome. Please use the Github issue tracker.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].