- Notifications
You must be signed in to change notification settings - Fork25
C++14 Finite State Machine library
License
zmij/afsm
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
afsm is a finite state machine C++14 library designed for usage in multithreaded asynchronous environment.
Theafsm library was inspired by::boost::msm library and implemented so that the migration from::boost::msm was a bunch of search and replace operations. The main motivation was to create a thread-safe FSM library and to achieve decent compile times for large and complex state machines not sacrificing performance. A state machine defined withafms library compiles several times faster than same library defined with::boost::msm and has similar (or better) performance. You can find some benchmark resultshere.
- Statechart features
- Hierarchical states
- Entry and exit actions
- Internal transitions
- Transition actions
- Transition guards (conditions)
- State history
- Event deferring
- Orthogonal regions
- Statechart extensions
- Optionalevent priority
- Optionalcommon base for states and easy definition of dispatching common interface calls to current state
- Pushdown automaton
- Compile-time checks
- Thread safety
- Exception safety
- No vtables (unless common base feature is used)
- Header only
- Relatively fast compile time
- No external dependencies except STL
- State machine persistense
Here is a UML diagram of a trivial state machine and source code that it is mapped to.
#include<afsm/fsm.hpp>// Eventsstructstart {};structstop {};// State machine definitionstructminimal_def : ::afsm::def::state_machine<minimal_def> {//@{/** @name States*/structinitial : state<initial> {};structrunning : state<running> {};structterminated : terminal_state<terminated> {};//@}using initial_state = initial;using transitions = transition_table</* State Event Next*/ tr< initial, start, running >, tr< running, stop, terminated > >;};// State machine objectusing minimal = ::afsm::state_machine<minimal_def>;voiduse(){ mimimal fsm; fsm.process_event(start{}); fsm.process_event(stop{});}
You can find a tutorial covering most of basic featureshere.
Please seeproject wiki for documentation.TODO doxygen generated documentation.
The library is header only and doesn't requre build or installation. Just add theafsm/include andlib/meta/include directories under the root of this repository to your include paths.
You can add the library to your project as a subtree, e.g.lib/afsm, and in your rootCMakeLists.txt file just do the following:
add_subdirectory(lib/afsm)include_directories(${AFSM_INCLUDE_DIRS})
TODO write docs on gitrc subtree commands and link to the repository
git clone git@github.com:zmij/afsm.gitmkdir afsm/buildcd afsm/buildcmake ..sudo make installfind_package(AFSM REQUIRED)# Will set AFSM_INCLUDE_DIRS variable
About
C++14 Finite State Machine library
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.