Modern Hierarchical State Machine for C++20
- 🔧 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
#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");
}
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
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
cmake -S . -B build -DENABLE_TEST=ON -DENABLE_COVERAGE=ON
cmake --build build
cd build && ctest
- C++20 compiler (GCC >= 10, Clang >= 11, MSVC >= 2019)
- GoogleTest (auto-downloaded via CMake)
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
MPL2.0 License — see LICENSE for details.
- 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 |
Issues, feature suggestions, and PRs are welcome!