-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathdispatch_table.cpp
More file actions
56 lines (47 loc) · 1.1 KB
/
dispatch_table.cpp
File metadata and controls
56 lines (47 loc) · 1.1 KB
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
46
47
48
49
50
51
52
53
54
55
56
//
// Copyright (c) 2016-2020 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/utility/dispatch_table.hpp"
#include <boost/sml.hpp>
#include <cassert>
namespace sml = boost::sml;
namespace {
struct runtime_event {
int id = 0;
};
struct event1 {
static constexpr auto id = 1;
event1(const runtime_event &) {}
};
struct event2 {
static constexpr auto id = 2;
};
struct dispatch_table {
auto operator()() noexcept {
using namespace sml;
// clang-format off
return make_transition_table(
*"idle"_s + event<event1> = "s1"_s
, "s1"_s + event<event2> = X
);
// clang-format on
}
};
} // namespace
int main() {
sml::sm<dispatch_table> sm;
auto dispatch_event = sml::utility::make_dispatch_table<runtime_event, 1 /*min*/, 5 /*max*/>(sm);
{
runtime_event event{1};
dispatch_event(event, event.id);
}
{
runtime_event event{2};
dispatch_event(event, event.id);
}
assert(sm.is(sml::X));
}