ZI
ZigRazor/CXXStateTree
A C++ Header-Only Hierarchical State Tree Library
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 buildAfter 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 buildAfter 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
๐ 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!
On this page
Languages
C++77.1%CMake22.9%
Mozilla Public License 2.0
Created June 30, 2025
Updated February 17, 2026
