forked from zamazan4ik/conan-sml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cpp
45 lines (39 loc) · 1.03 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Copyright (c) 2016-2019 Kris Jusiak (kris at jusiak dot net)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/sml.hpp>
#include <cassert>
#include <iostream>
namespace sml = boost::sml;
namespace {
struct e1 {};
struct e2 {};
struct e3 {};
struct states {
auto operator()() const noexcept {
using namespace sml;
const auto idle = state<class idle>;
// clang-format off
return make_transition_table(
*idle + event<e1> = "s1"_s
, "s1"_s + sml::on_entry<_> / [] { std::cout << "s1 on entry" << std::endl; }
, "s1"_s + sml::on_exit<_> / [] { std::cout << "s1 on exit" << std::endl; }
, "s1"_s + event<e2> = state<class s2>
, state<class s2> + event<e3> = X
);
// clang-format on
}
};
} // namespace
int main() {
sml::sm<states> sm;
sm.process_event(e1{});
sm.process_event(e2{});
sm.process_event(e3{});
assert(sm.is(sml::X));
return 0;
}