{"id":13757197,"url":"https://github.com/zmij/afsm","last_synced_at":"2025-05-10T05:31:50.291Z","repository":{"id":57876733,"uuid":"59731854","full_name":"zmij/afsm","owner":"zmij","description":"C++14 Finite State Machine library","archived":false,"fork":false,"pushed_at":"2020-11-25T08:03:11.000Z","size":6210,"stargazers_count":171,"open_issues_count":6,"forks_count":24,"subscribers_count":12,"default_branch":"develop","last_synced_at":"2024-11-16T13:34:55.645Z","etag":null,"topics":["afsm","cpp","cpp14","cpp14-library","finite-state-machine","fsm","fsm-library","pushdown-automata","pushdown-automaton","state-machine"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zmij.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-26T08:05:45.000Z","updated_at":"2024-11-14T10:36:09.000Z","dependencies_parsed_at":"2022-09-11T02:24:02.256Z","dependency_job_id":null,"html_url":"https://github.com/zmij/afsm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmij%2Fafsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmij%2Fafsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmij%2Fafsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmij%2Fafsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zmij","download_url":"https://codeload.github.com/zmij/afsm/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253371072,"owners_count":21897998,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["afsm","cpp","cpp14","cpp14-library","finite-state-machine","fsm","fsm-library","pushdown-automata","pushdown-automaton","state-machine"],"created_at":"2024-08-03T12:00:28.851Z","updated_at":"2025-05-10T05:31:49.973Z","avatar_url":"https://github.com/zmij.png","language":"C++","readme":"# Another Finite State Machine\n\n`afsm` is a finite state machine C++14 library designed for usage in multithreaded asynchronous environment.\n\n## Inspiration and Motivation\n\nThe `afsm` library was inspired by [`::boost::msm`](http://www.boost.org/doc/libs/1_62_0/libs/msm/doc/HTML/index.html) 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 with `afms` library compiles several times faster than same library defined with `::boost::msm` and has similar (or better) performance. You can find some benchmark results [here](https://github.com/zmij/afsm/wiki/Performance-Benchmarks).\n\n## Features\n\n* Statechart features\n  * Hierarchical states\n  * [Entry and exit actions](https://github.com/zmij/afsm/wiki/Entry-and-Exit-Actions)\n  * Internal transitions\n  * [Transition actions](https://github.com/zmij/afsm/wiki/Transition-Actions)\n  * [Transition guards (conditions)](https://github.com/zmij/afsm/wiki/Transition-Guards)\n  * [State history](https://github.com/zmij/afsm/wiki/History)\n  * [Event deferring](https://github.com/zmij/afsm/wiki/Event-Deferring)\n  * [Orthogonal regions](https://github.com/zmij/afsm/wiki/Orthogonal-Regions)\n* Statechart extensions\n  * Optional [event priority](https://github.com/zmij/afsm/wiki/Event-Priority)\n  * Optional [common base](https://github.com/zmij/afsm/wiki/Common-Base) for states and easy definition of dispatching common interface calls to current state\n  * [Pushdown automaton](https://github.com/zmij/afsm/wiki/Pushdown-Automaton)\n* Compile-time checks\n* [Thread safety](https://github.com/zmij/afsm/wiki/Thread-Safety)\n* Exception safety\n* No vtables (unless common base feature is used)\n* Header only\n* Relatively fast compile time\n* No external dependencies except STL\n\n### Planned features\n\n* State machine persistense\n\n## Synopsis\n\nHere is a UML diagram of a trivial state machine and source code that it is mapped to.\n![minimal](https://cloud.githubusercontent.com/assets/2694027/20274791/f352998c-aaa6-11e6-99ec-fc63300766d7.png)\n\n```c++\n#include \u003cafsm/fsm.hpp\u003e\n// Events\nstruct start {};\nstruct stop {};\n\n// State machine definition\nstruct minimal_def : ::afsm::def::state_machine\u003cminimal_def\u003e {\n    //@{\n    /** @name States */\n    struct initial      : state\u003cinitial\u003e {};\n    struct running      : state\u003crunning\u003e {};\n    struct terminated   : terminal_state\u003cterminated\u003e {};\n    //@}\n\n    using initial_state = initial;\n    using transitions   = transition_table\u003c\n        /*  State       Event       Next        */\n        tr\u003c initial,    start,      running     \u003e,\n        tr\u003c running,    stop,       terminated  \u003e\n    \u003e;\n};\n\n// State machine object\nusing minimal = ::afsm::state_machine\u003cminimal_def\u003e;\n\nvoid use()\n{\n    mimimal fsm;\n    fsm.process_event(start{});\n    fsm.process_event(stop{});\n}\n```\n\nYou can find a tutorial covering most of basic features [here](https://github.com/zmij/afsm/wiki/Tutorial:-Vending-machine-FSM).\n\n## Documentation\n\nPlease see [project wiki](https://github.com/zmij/afsm/wiki) for documentation. *TODO* doxygen generated documentation.\n\n## Installation\n\nThe library is header only and doesn't requre build or installation. Just add the `afsm/include` and `lib/meta/include` directories under the root of this repository to your include paths.\n\n### CMake subproject\n\nYou can add the library to your project as a subtree, e.g. `lib/afsm`, and in your root `CMakeLists.txt` file just do the following:\n\n```cmake\nadd_subdirectory(lib/afsm)\ninclude_directories(${AFSM_INCLUDE_DIRS})\n```\n\nTODO write docs on gitrc subtree commands and link to the repository\n\n### Installation to System Directories\n\n```bash\ngit clone git@github.com:zmij/afsm.git\nmkdir afsm/build\ncd afsm/build\ncmake ..\nsudo make install\n```\n\n### Finding the AFSM Package\n\n```cmake\nfind_package(AFSM REQUIRED) # Will set AFSM_INCLUDE_DIRS variable\n```\n\n## License\n\n[The Artistic License 2.0](https://github.com/zmij/afsm/blob/develop/LICENSE)\n","funding_links":[],"categories":["Objects - Entity, Actor"],"sub_categories":["Finite State Machine"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmij%2Fafsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzmij%2Fafsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmij%2Fafsm/lists"}