{"id":17977952,"url":"https://github.com/coderyi/statemachine","last_synced_at":"2025-08-22T15:05:26.482Z","repository":{"id":90803720,"uuid":"148716826","full_name":"coderyi/statemachine","owner":"coderyi","description":"An C++ library for implementing state machines.","archived":false,"fork":false,"pushed_at":"2018-09-14T01:19:28.000Z","size":4,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T05:42:07.705Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/coderyi.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-14T01:08:09.000Z","updated_at":"2024-06-18T06:17:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"0dc0cd24-3aed-482e-b0ba-5ebb7f358d48","html_url":"https://github.com/coderyi/statemachine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/coderyi/statemachine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2Fstatemachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2Fstatemachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2Fstatemachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2Fstatemachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderyi","download_url":"https://codeload.github.com/coderyi/statemachine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2Fstatemachine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271657543,"owners_count":24797934,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-29T17:30:15.588Z","updated_at":"2025-08-22T15:05:26.424Z","avatar_url":"https://github.com/coderyi.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"一个有限状态机的C++实现\n\n状态机有几个特征\n\n- 状态（state）总数是有限的\n- 任意时刻，只处在一种状态之中\n- 某种条件下，会从一种状态转变（transition）到另一种状态\n\n\n状态机能够很好的管理复杂业务。适用于有一个明确 且复杂的状态流的场景。状态机能够很好的提高代码的可维护性和可测试性。\n\n\n示例\n\n```\nStateMachine stateMachine;\n\nstateMachine.setOnStartCallback([] () { std::cout \u003c\u003c \"state machine started\" \u003c\u003c std::endl; });\nstateMachine.setOnStopCallback([] () { std::cout \u003c\u003c \"state machine stopped\" \u003c\u003c std::endl; });\n\nState* state1 = new State();\nstate1-\u003esetOnEnterCallback([] (const Event*) { std::cout \u003c\u003c \"entering state1\" \u003c\u003c std::endl; });\nstate1-\u003esetOnExitCallback([] (const Event*) { std::cout \u003c\u003c \"exiting state1\" \u003c\u003c std::endl; });\n\nState* state2 = new State();\nstate2-\u003esetOnEnterCallback([] (const Event*) { std::cout \u003c\u003c \"entering state2\" \u003c\u003c std::endl; });\nstate2-\u003esetOnExitCallback([] (const Event*) { std::cout \u003c\u003c \"exiting state2\" \u003c\u003c std::endl; });\n\nState* state3 = new State();\nstate3-\u003esetOnEnterCallback([] (const Event*) { std::cout \u003c\u003c \"entering state3\" \u003c\u003c std::endl; });\nstate3-\u003esetOnExitCallback([] (const Event*) { std::cout \u003c\u003c \"exiting state3\" \u003c\u003c std::endl; });\n\nstateMachine.addTransition(12, state1, state2);\nstateMachine.addTransition(13, state1, state3);\nstateMachine.addTransition(23, state2, state3);\nstateMachine.addTransition(31, state3, state1);\nstateMachine.setInitialState(state1);\n\nstateMachine.start();\n\nstateMachine.postEvent(new Event(12));\nstateMachine.postEvent(new Event(23));\nstateMachine.postEvent(new Event(31));\nstateMachine.postEvent(new Event(13));\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderyi%2Fstatemachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderyi%2Fstatemachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderyi%2Fstatemachine/lists"}