C++14 header-only library for implementing Finite-State Machines.
The library provides the following three interfaces for building a state
machine: State
, Event
and the StateMachine
itself.
-
State
s represent the possible configurations of aStateMachine
. -
Event
s represent the possible transitions betweenState
s. -
Each
Event
defines the destinationState
that theStateMachine
reaches if theEvent
itself is triggered. -
Event
s can beControllable
andNonControllable
:-
Controllable
events are executed by the user; -
NonControllable
events are events that are not under the direct control of the user (for instance failures or timeouts).
-
-
Each
State
declares theControllableEvent
s that are available using theState::attach<ControllableEvent>()
method, and defines the logic for triggeringNonControllableEvents
in theState::update()
method.
Use a modern C++ compiler with support of the C++14 standard.
Code was developed using g++ 6.3.0 20170406
.
Run in the project folder:
mkdir -p build && (cd build && cmake .. && make -j$(nproc))
In order to validate and demonstrate the usage of the library, three examples have been developed: a simple On/Off switch, an On/Off switch with an automatic reset timer, and a Moka coffee brewer.
Unit tests for these examples are executed automatically at the end of the build.
Controllable events and states are showed in black, while NonControllable events and states are shown in red.