Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cassert>
- #include <cstdio>
- #include <boost/sml.hpp>
- namespace sml = boost::sml;
- // events
- struct change_state {};
- struct do_a {};
- struct do_b {};
- // actions
- const auto action_a = [] {
- printf("doing action a...\n");
- };
- const auto entry_action_a = [] {
- printf("-> active state: a...\n");
- };
- const auto action_b = [] {
- printf("doing action b...\n");
- };
- const auto entry_action_b = [] {
- printf("-> active state: b...\n");
- };
- struct hello_world {
- auto operator()() const {
- using namespace sml;
- // clang-format off
- return make_transition_table(
- *"first state"_s + event<change_state> = "second state"_s,
- "first state"_s + on_entry<_> / entry_action_a,
- "first state"_s + event<do_a> / action_a = "first state"_s,
- "second state"_s + event<change_state> = "first state"_s,
- "second state"_s + on_entry<_> / entry_action_b,
- "second state"_s + event<do_b> / action_b
- );
- // clang-format on
- }
- };
- int main() {
- using namespace sml;
- sm<hello_world> sm;
- static_assert(1 == sizeof(sm), "sizeof(sm) != 1b");
- sm.process_event(do_a{});
- sm.process_event(do_a{});
- sm.process_event(do_a{});
- sm.process_event(change_state{});
- sm.process_event(do_b{});
- sm.process_event(do_b{});
- sm.process_event(do_b{});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement