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!