#include #include #include #include "../mcc_finite_state_machine.h" using namespace mcc; struct S { }; struct EV1 { static constexpr std::string_view ID = "EV1"; void onTransit() { // std::cout << "EV1::onTransit()\n"; } }; struct EV2 { static constexpr std::string_view ID = "EV2"; }; struct EV3 { static constexpr std::string_view ID = "EV3"; }; struct EVN { static constexpr std::string_view ID = "EVN"; }; struct ST1; struct ST2; struct STN { static constexpr std::string_view ID = "STN"; using transition_t = fsm::fsm_transition_table_t, std::pair>; void enter() { std::cout << "transit to " << ID << "-state\n"; } void exit() { std::cout << "transit from " << ID << "-state\n"; } }; struct ST3 { static constexpr std::string_view ID = "ST3"; using transition_t = fsm::fsm_transition_table_t, std::pair>; void enter(EV3& ev) { std::cout << "transit to " << ID << "-state\n"; } void exit() { std::cout << "transit from " << ID << "-state\n"; } }; struct ST2 { static constexpr std::string_view ID = "ST2"; using transition_t = fsm::fsm_transition_table_t, std::pair>; void enter(EV2& ev) { std::cout << "transit to " << ID << "-state\n"; } void exit() { std::cout << "transit from " << ID << "-state\n"; } }; struct ST1 { static constexpr std::string_view ID = "ST1"; using transition_t = fsm::fsm_transition_table_t, std::pair, std::pair, std::pair>; void enter() { std::cout << "transit to " << ID << "-state\n"; } void exit() { std::cout << "transit from " << ID << "-state\n"; } }; int tests_fsm(int, char**) { std::cout << "\n\n\n------- mcc_finite_state_machine.h -------\n"; fsm::MccFiniteStateMachine fsmach(ST1{}); std::cout << "STATES: "; for (auto& el : fsmach.stateIDs()) { std::cout << std::quoted(el) << " "; } std::cout << "\n"; std::cout << "EVENTS: "; for (auto& el : fsmach.eventIDs()) { std::cout << std::quoted(el) << " "; } std::cout << "\n"; fsmach.dispatchEvent(); fsmach.dispatchEvent(); fsmach.dispatchEvent(); // fsmach.dispatchEvent(); using tab_t = fsm::fsm_transition_table_t, std::pair>; using st_t = tab_t::find_state_by_event_t; int status; char* aa = abi::__cxa_demangle(typeid(st_t).name(), NULL, NULL, &status); std::cout << "aa = " << aa << "\n"; free(aa); std::cout << "\nAfter std::move\n"; auto fsmach1 = std::move(fsmach); std::cout << "STATES: "; for (auto& el : fsmach1.stateIDs()) { std::cout << std::quoted(el) << " "; } std::cout << "\n"; std::cout << "current state: " << std::quoted(fsmach1.currentStateID()) << "\n"; return 0; }