Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <cassert>
  2. #include <cstdio>
  3.  
  4. #include <boost/sml.hpp>
  5.  
  6. namespace sml = boost::sml;
  7.  
  8. // events
  9. struct change_state {};
  10. struct do_a {};
  11. struct do_b {};
  12.  
  13. // actions
  14. const auto action_a = [] {
  15. printf("doing action a...\n");
  16. };
  17. const auto entry_action_a = [] {
  18. printf("-> active state: a...\n");
  19. };
  20.  
  21. const auto action_b = [] {
  22. printf("doing action b...\n");
  23. };
  24. const auto entry_action_b = [] {
  25. printf("-> active state: b...\n");
  26. };
  27.  
  28. struct hello_world {
  29. auto operator()() const {
  30. using namespace sml;
  31. // clang-format off
  32. return make_transition_table(
  33. *"first state"_s + event<change_state> = "second state"_s,
  34. "first state"_s + on_entry<_> / entry_action_a,
  35. "first state"_s + event<do_a> / action_a = "first state"_s,
  36.  
  37. "second state"_s + event<change_state> = "first state"_s,
  38. "second state"_s + on_entry<_> / entry_action_b,
  39. "second state"_s + event<do_b> / action_b
  40. );
  41. // clang-format on
  42. }
  43. };
  44.  
  45. int main() {
  46. using namespace sml;
  47.  
  48. sm<hello_world> sm;
  49. static_assert(1 == sizeof(sm), "sizeof(sm) != 1b");
  50.  
  51. sm.process_event(do_a{});
  52. sm.process_event(do_a{});
  53. sm.process_event(do_a{});
  54.  
  55. sm.process_event(change_state{});
  56.  
  57. sm.process_event(do_b{});
  58. sm.process_event(do_b{});
  59. sm.process_event(do_b{});
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement