Skip to content

ZigRazor/CXXStateTree

CXXStateTree Logo

CXXStateTree

Modern Hierarchical State Machine for C++20

πŸš€ Features

  • πŸ”§ Fluent builder API with lambda-based DSL
  • ⚑ Fast runtime performance with zero heap allocation
  • πŸ›‘οΈ Optional guards and actions for transitions
  • πŸ”„ Event-based state transitions
  • πŸ§ͺ Google Test integration
  • πŸ“ˆ Code coverage with Codecov
  • 🌳 Designed for extensibility: nested states, DOT export coming soon
  • πŸ”§ Deployed as Shared Library and as Single Header-Only library

πŸ› οΈ Quick Example

#include <iostream> #include "CXXStateTree/StateTree.hpp" using namespace CXXStateTree; int main() { auto machine = StateTree::Builder() .initial("Idle") .state("Idle", [](State& s) { s.on("Start", "Running", nullptr, []() { std::cout << "Idle -> Running" << std::endl; }); }) .state("Running", [](State& s) { s.on("Stop", "Idle", nullptr, []() { std::cout << "Running -> Idle" << std::endl; }); }) .build(); machine.send("Start"); machine.send("Stop"); }

πŸ› οΈ Building Shared Library

cmake -S . -B build cmake --build build

After these command the Shared Library can be found in build directory

Please Note: in future release cmake will have the ability to install the library automatically, for now it is necessary to do it manually


πŸ› οΈ Building Single Header-Only Library

cmake -S . -B build -DENABLE_SINGLE_HEADER=ON cmake --build build

After these command the Single Header-Only Library can be found in single_include directory with the name CXXStateTree.hpp

Please Note: in future release cmake will have the ability to install the library automatically, for now it is necessary to do it manually


πŸ§ͺ Running Tests

cmake -S . -B build -DENABLE_TEST=ON -DENABLE_COVERAGE=ON cmake --build build cd build && ctest

πŸ“¦ Dependencies

  • C++20 compiler (GCC >= 10, Clang >= 11, MSVC >= 2019)
  • GoogleTest (auto-downloaded via CMake)

πŸ“ˆ Code Coverage

codecov


πŸ“‚ Directory Structure

CXXStateTree/ β”œβ”€β”€ include/CXXStateTree/ # Public header-only API β”œβ”€β”€ examples/ # Usage examples β”œβ”€β”€ tests/ # Google Test suite β”œβ”€β”€ CMakeLists.txt # Project build └── .github/workflows/ci.yml # GitHub Actions CI 

πŸ“‹ License

MPL2.0 License β€” see LICENSE for details.


🌟 Coming Soon

  • Nested (hierarchical) state support
  • DOT/Graphviz state diagram export
  • Transitions with context/parameters
Completed Milestone Features
βœ”οΈ v0.1.0 Basic state machine with send(), transitions, and state tracking
βœ”οΈ v0.2.0 Guards and actions
βœ”οΈ v0.3.0 Nested (hierarchical) states
βœ”οΈ v0.4.0 Graphviz export
πŸ“ v0.5.0 Coroutine/async support (optional)
πŸ“ v1.0.0 Full unit test coverage, benchmarks, and docs

πŸ‘‹ Contributions Welcome

Issues, feature suggestions, and PRs are welcome!

About

A C++ Header-Only Hierarchical State Tree Library

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •