https://github.com/drorspei/mountel
A state charts library for C++
https://github.com/drorspei/mountel
Last synced: 8 months ago
JSON representation
A state charts library for C++
- Host: GitHub
- URL: https://github.com/drorspei/mountel
- Owner: drorspei
- License: mit
- Created: 2019-05-14T22:19:03.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T22:49:04.000Z (about 7 years ago)
- Last Synced: 2024-12-30T00:14:30.687Z (over 1 year ago)
- Language: C++
- Size: 18.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mountel
A state charts library for C++
Taking inspiration from and combining code of the libraries uscxml, [boost]::sml, nbdl, and relying on the boost::hana meta programming library, to offer a convenient way to construct and use state charts in modern C++ code. The goal is to have the following compile, work as expected (if you're familiar with state charts), and be fast (at least as fast as the transpiled uscxml outputs):
```C++
#include
int main() {
using namespace mountel;
struct done_init {
const int answer;
};
const auto statechart = State(
Name("root"_s),
States(
State(
Name("initializing"_s),
Transition(
Event,
Target("waiting_for_question"),
Guard([] (auto& sm, auto& e) { return e.answer > 10; }),
Action(
[] (auto& sm, auto& e) {
std::printf("...? %d\n", e.answer);
}
)
)
),
State(
Name("waiting_for_answer"),
OnEnter(
[] { std::puts("entered waiting_for_answer"); }
)
)
)
);
auto machine = Machine(statechart);
machine.process(done_init{42});
assert(machine.isin("waiting_for_answer"));
}
```
## Status of project:
No where near working.
The definition of state charts now compiles, and the guards/actions are saved and are callable.
Can compute the number of states and transitions during compile time.