// // 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 #include #include #include namespace sml = boost::sml; namespace { struct my_logger { template void log_process_event(const TEvent&) { printf("[%s][process_event] %s\n", sml::aux::get_type_name(), sml::aux::get_type_name()); } template void log_guard(const TGuard&, const TEvent&, bool result) { printf("[%s][guard] %s %s %s\n", sml::aux::get_type_name(), sml::aux::get_type_name(), sml::aux::get_type_name(), (result ? "[OK]" : "[Reject]")); } template void log_action(const TAction&, const TEvent&) { printf("[%s][action] %s %s\n", sml::aux::get_type_name(), sml::aux::get_type_name(), sml::aux::get_type_name()); } template void log_state_change(const TSrcState& src, const TDstState& dst) { printf("[%s][transition] %s -> %s\n", sml::aux::get_type_name(), 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 [ guard && guard ] / action = "s1"_s ); // clang-format on } }; } // namespace int main() { my_logger logger; sml::sm> sm{logger}; sm.process_event(e1{}); sm.process_event(e2{}); }