// Copyright 2024 Christophe Henry // henry UNDERSCORE christophe AT hotmail DOT com // This is an extended version of the state machine available in the boost::mpl library // Distributed under the same license as the original. // Copyright for the original version: // Copyright 2005 David Abrahams and Aleksey Gurtovoy. 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 using namespace boost::msm::front; using namespace boost::msm::front::puml; namespace boost::msm::front::puml { // events template<> struct Event { int cpt_ = 0; }; template<> struct Event { int cpt_ = 0; }; template<> struct Event {}; template<> struct Event {}; template<> struct Event {}; template<> struct Event {}; template<> struct Event {}; // A "complicated" event type that carries some data. enum DiskTypeEnum { DISK_CD = 0, DISK_DVD = 1 }; template<> struct Event { Event(std::string name, DiskTypeEnum diskType= DISK_CD) : name(name), disc_type(diskType) {} std::string name; DiskTypeEnum disc_type; }; // The list of FSM states template<> struct State : public msm::front::state<> { template void on_entry(Event const&, FSM&) { ++entry_counter; } template void on_exit(Event const&, FSM&) { ++exit_counter; } int entry_counter = 0; int exit_counter = 0; unsigned int empty_internal_guard_counter = 0; unsigned int empty_internal_action_counter = 0; }; template<> struct State : public msm::front::state<> { template void on_entry(Event const&, FSM&) { ++entry_counter; } template void on_exit(Event const&, FSM&) { ++exit_counter; } int entry_counter = 0; int exit_counter = 0; }; template<> struct State : public msm::front::state<> { template void on_entry(Event const&, FSM&) { ++entry_counter; } template void on_exit(Event const&, FSM&) { ++exit_counter; } int entry_counter = 0; int exit_counter = 0; }; template<> struct State : public msm::front::state<> { template void on_entry(Event const&, FSM&) { ++entry_counter; } template void on_exit(Event const&, FSM&) { ++exit_counter; } int entry_counter = 0; int exit_counter = 0; }; template<> struct State : public msm::front::state<> { template void on_entry(Event const&, FSM&) { ++entry_counter; } template void on_exit(Event const&, FSM&) { ++exit_counter; } int entry_counter = 0; int exit_counter = 0; }; template<> struct State : public msm::front::state<> { template void on_entry(Event const& e, FSM&) { ++entry_counter; event_counter = e.cpt_; } template void on_exit(Event const&, FSM&) { ++exit_counter; } int entry_counter = 0; int exit_counter = 0; int event_counter = 0; }; //actions template<> struct Action { template void operator()(EVT const&, FSM&, SourceState&, TargetState&) { } }; template<> struct Action { template void operator()(EVT const&, FSM&, SourceState&, TargetState&) { } }; template<> struct Action { template void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&) { ++fsm.start_playback_counter; } }; template<> struct Action { template void operator()(EVT const&, FSM&, SourceState&, TargetState&) { } }; template<> struct Action { template void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&) { fsm.process_event(Event{}); } }; template<> struct Action { template void operator()(EVT const&, FSM&, SourceState&, TargetState&) { } }; template<> struct Action { template void operator()(EVT const&, FSM&, SourceState&, TargetState&) { } }; template<> struct Action { template void operator()(EVT&, FSM&, SourceState&, TargetState&) { } }; template<> struct Action { template void operator()(EVT const& e, FSM&, SourceState&, TargetState&) { ++(*const_cast(&e)).cpt_; } }; template<> struct Action { template void operator()(EVT const&, FSM&, SourceState&, TargetState&) { } }; template<> struct Action { template void operator()(EVT const&, FSM&, SourceState&, TargetState&) { } }; template<> struct Action { template void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&) { ++fsm.internal_action_counter; } }; template<> struct Action { template void operator()(EVT const&, FSM&, SourceState& src, TargetState&) { ++src.empty_internal_action_counter; } }; template<> struct Action { template void operator()(EVT const& e, FSM& fsm, SourceState&, TargetState&) { ++(*const_cast(&e)).cpt_; ++fsm.test_fct_counter; } }; template<> struct Action { template void operator()(EVT&, FSM& fsm, SourceState&, TargetState&) { ++fsm.entry_counter; } }; template<> struct Action { template void operator()(EVT&, FSM& fsm, SourceState&, TargetState&) { ++fsm.exit_counter; } }; // guard conditions template<> struct Guard { template bool operator()(EVT& evt, FSM&, SourceState&, TargetState&) { // to test a guard condition, let's say we understand only CDs, not DVD if (evt.disc_type != DISK_CD) { return false; } return true; } }; template<> struct Guard { template bool operator()(EVT const&, FSM& fsm, SourceState&, TargetState&) { ++fsm.can_close_drawer_counter; return true; } }; template<> struct Guard { template bool operator()(EVT const&, FSM& fsm, SourceState&, TargetState&) { ++fsm.internal_guard_counter; return false; } }; template<> struct Guard { template bool operator()(EVT const&, FSM&, SourceState& src, TargetState&) { ++src.empty_internal_guard_counter; return false; } }; template<> struct Guard { template bool operator()(EVT const&, FSM& fsm, SourceState&, TargetState&) { ++fsm.internal_guard_counter; return true; } }; template<> struct Guard { template bool operator()(EVT const&, FSM&, SourceState&, TargetState&) { return true; } }; template<> struct Guard { template bool operator()(EVT const&, FSM&, SourceState&, TargetState&) { return true; } }; }