-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathlogging.cpp
More file actions
68 lines (58 loc) · 1.85 KB
/
Copy pathlogging.cpp
File metadata and controls
68 lines (58 loc) · 1.85 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
57
58
59
60
61
62
63
64
65
66
67
68
//
// 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.hpp>
#include <cassert>
#include <cstdio>
#include <iostream>
namespace sml = boost::sml;
namespace {
struct my_logger {
template <class SM, class TEvent>
void log_process_event(const TEvent&) {
printf("[%s][process_event] %s\n", sml::aux::get_type_name<SM>(), sml::aux::get_type_name<TEvent>());
}
template <class SM, class TGuard, class TEvent>
void log_guard(const TGuard&, const TEvent&, bool result) {
printf("[%s][guard] %s %s %s\n", sml::aux::get_type_name<SM>(), sml::aux::get_type_name<TGuard>(),
sml::aux::get_type_name<TEvent>(), (result ? "[OK]" : "[Reject]"));
}
template <class SM, class TAction, class TEvent>
void log_action(const TAction&, const TEvent&) {
printf("[%s][action] %s %s\n", sml::aux::get_type_name<SM>(), sml::aux::get_type_name<TAction>(),
sml::aux::get_type_name<TEvent>());
}
template <class SM, class TSrcState, class TDstState>
void log_state_change(const TSrcState& src, const TDstState& dst) {
printf("[%s][transition] %s -> %s\n", sml::aux::get_type_name<SM>(), src.c_str(), dst.c_str());
}
};
struct e1 {};
struct e2 {};
struct guard {
bool operator()() const { return true; }
} guard;
struct action {
void operator()() {}
} action;
struct logging {
auto operator()() const noexcept {
using namespace sml;
// clang-format off
return make_transition_table(
*"idle"_s + event<e1> [ guard && guard ] / action = "s1"_s
);
// clang-format on
}
};
} // namespace
int main() {
my_logger logger;
sml::sm<logging, sml::logger<my_logger>> sm{logger};
sm.process_event(e1{});
sm.process_event(e2{});
}