// // 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 namespace sml = boost::sml; namespace { // events struct release {}; struct ack {}; struct fin {}; struct timeout {}; // guards const auto is_ack_valid = [](const ack&) { return true; }; const auto is_fin_valid = [](const fin&) { return true; }; // actions const auto send_fin = [] {}; const auto send_ack = [] {}; #if !defined(_MSC_VER) struct hello_world { auto operator()() const { using namespace sml; // clang-format off return make_transition_table( *"established"_s + event / send_fin = "fin wait 1"_s, "fin wait 1"_s + event [ is_ack_valid ] = "fin wait 2"_s, "fin wait 2"_s + event [ is_fin_valid ] / send_ack = "timed wait"_s, "timed wait"_s + event / send_ack = X ); // clang-format on } }; } int main() { using namespace sml; sm sm; static_assert(1 == sizeof(sm), "sizeof(sm) != 1b"); assert(sm.is("established"_s)); sm.process_event(release{}); assert(sm.is("fin wait 1"_s)); sm.process_event(ack{}); assert(sm.is("fin wait 2"_s)); sm.process_event(fin{}); assert(sm.is("timed wait"_s)); sm.process_event(timeout{}); assert(sm.is(X)); // released } #else class established; class fin_wait_1; class fin_wait_2; class timed_wait; struct hello_world { auto operator()() const { using namespace sml; // clang-format off return make_transition_table( *state + event / send_fin = state, state + event [ is_ack_valid ] = state, state + event [ is_fin_valid ] / send_ack = state, state + event / send_ack = X ); // clang-format on } }; } int main() { using namespace sml; sm sm; assert(sm.is(state)); sm.process_event(release{}); assert(sm.is(state)); sm.process_event(ack{}); assert(sm.is(state)); sm.process_event(fin{}); assert(sm.is(state)); sm.process_event(timeout{}); assert(sm.is(X)); // released } #endif