{"id":13732266,"url":"https://github.com/eglimi/cppfsm","last_synced_at":"2026-01-16T20:36:02.634Z","repository":{"id":24763927,"uuid":"28177083","full_name":"eglimi/cppfsm","owner":"eglimi","description":"A simple, generic, header-only state machine implementation for C++.","archived":false,"fork":false,"pushed_at":"2022-01-29T18:25:30.000Z","size":267,"stargazers_count":58,"open_issues_count":1,"forks_count":16,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-05-02T20:13:53.233Z","etag":null,"topics":["c-plus-plus","state-machine"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eglimi.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":"2014-12-18T09:33:47.000Z","updated_at":"2024-04-09T00:17:26.000Z","dependencies_parsed_at":"2022-07-25T14:22:04.252Z","dependency_job_id":null,"html_url":"https://github.com/eglimi/cppfsm","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/eglimi%2Fcppfsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eglimi%2Fcppfsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eglimi%2Fcppfsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eglimi%2Fcppfsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eglimi","download_url":"https://codeload.github.com/eglimi/cppfsm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213757427,"owners_count":15634177,"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":["c-plus-plus","state-machine"],"created_at":"2024-08-03T02:01:51.022Z","updated_at":"2026-01-16T20:36:02.612Z","avatar_url":"https://github.com/eglimi.png","language":"C++","readme":"Finite State Machine for C++\n============================\n\nA simple, generic, header-only state machine implementation for C++.\n\nDocumentation\n-------------\n\nPlease see the documentation in [fsm.h](./fsm.h) for detailed documentation\nabout the implemented features and semantics.\n\nSome more information about this component can also be found on our website. See [article 1] for the motivation, and [article 2] for the implementation.\n\n[article 1]: http://wisol.ch/w/articles/2015-01-04-state-machine-intro/\n[article 2]: http://wisol.ch/w/articles/2015-03-27-state-machine-impl/\n\nUsage\n-----\n\nThe implementation is contained in a single header file, `fsm.h`. Simply copy\nthe file to a convenient place in your project and include it.\n\nExample\n-------\n\nAs an example, consider the state machine below. It starts in state `A`. When\nit receives the `exec` trigger, it checks that the `count` variable is `1`,\nincrements it, and changes to state `B`.\n\n~~~\n       +------+  Exec[count=1] / count++    +------+\n  o---\u003e|  A   |----------------------------\u003e|  B   |\n       +------+                             +------+\n~~~\n\nThe implementation of this state machine is done in a declarative way.\n\n~~~\nint count = 1;\nenum class States { A, B };\nenum class Triggers { Exec };\nFSM::Fsm\u003cStates, States::A, Triggers\u003e fsm;\nfsm.add_transitions({\n//  from state ,to state  ,triggers        ,guard                    ,action\n  { States::A  ,States::B ,Triggers::Exec  ,[\u0026]{return count == 1;}  ,[\u0026]{count++;} },\n});\nfsm.execute(Triggers::Exec);\nassert(count == 2);\nassert(fsm.state() == States::B);\n~~~\n\nSee the tests for more examples.\n\n\nStability\n---------\n\nThe implementation is already in use in different commercial applications. We\nhave not found any issues so far. Please report any problems you find.\n\nTests\n-----\n\nTests can be run with\n\n~~~\ncd tests\ng++ -std=c++11 -Wall -o tests fsm_test.cpp\n./tests\n~~~\n\nContributions\n-------------\n\nContributions are welcome. Please use the Github issue tracker.\n","funding_links":[],"categories":["GameProgramming"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feglimi%2Fcppfsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feglimi%2Fcppfsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feglimi%2Fcppfsm/lists"}