#include #include #include #include "../mcc_finite_state_machine.h" // #include "../mcc_fsm.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 ST1; struct ST2; struct STN { static constexpr std::string_view ID = "STN"; using transition_t = fsm::fsm_transition_table_t, std::pair>; }; struct ST3 { static constexpr std::string_view ID = "ST3"; using transition_t = fsm::fsm_transition_table_t, std::pair>; }; struct ST2 { static constexpr std::string_view ID = "ST2"; using transition_t = fsm::fsm_transition_table_t, std::pair>; void enter(EV1& ev) { std::cout << "transit to " << 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 exit() { std::cout << "transit from " << ID << "-state\n"; } }; // struct STN : fsm::MccFsmAbstractState { // static constexpr std::string_view ID = "STN"; // using transition_t = trans_table_t, std::pair>; // }; // struct ST3 : fsm::MccFsmAbstractState { // static constexpr std::string_view ID = "ST3"; // using transition_t = trans_table_t, std::pair>; // }; // struct ST2 : fsm::MccFsmAbstractState { // static constexpr std::string_view ID = "ST2"; // using transition_t = trans_table_t, std::pair>; // }; // struct ST1 : fsm::MccFsmAbstractState { // static constexpr std::string_view ID = "ST1"; // using transition_t = trans_table_t, std::pair>; // }; // fsm::MccFiniteStateMachine fsm; int main() { /* typedef fsm::unique_tuple_t ut_t; std::cout << "type index: " << fsm::unique_tuple_type_index_t::index << " (double)\n"; std::cout << "type index: " << fsm::unique_tuple_type_index_t::index << " (int)\n"; std::cout << "type index: " << fsm::unique_tuple_type_index_t::index << " (long)\n"; // std::cout << "type index: " << fsm::unique_tuple_type_index_t::index << " (struct S)\n"; std::cout << typeid(ut_t::tuple_t).name() << "\n"; std::cout << typeid(ut_t::non_unique_t).name() << "\n"; typedef fsm::pair_holder_t, std::pair, std::pair> ph_t; // using s_t = fsm::pair_holder_find_t::result_t; using s_t = fsm::pair_holder_find_t::result_t; if constexpr (std::is_null_pointer_v) { std::cout << "second type: invalid input type!\n"; } else { std::cout << "second type: " << typeid(s_t).name() << "\n"; } using t1_t = fsm::pair_holder_first_t::first_t; std::cout << "first types: " << typeid(t1_t).name() << "\n"; using t2_t = fsm::pair_holder_second_t::second_t; std::cout << "second types: " << typeid(t2_t).name() << "\n"; using tp1_t = std::tuple; using tp2_t = std::tuple; int status; char* aa = abi::__cxa_demangle(typeid(STN::transition_t::states_t).name(), NULL, NULL, &status); std::cout << "aa = " << aa << "\n"; char* uu = abi::__cxa_demangle(typeid(STN::transition_t::unique_states_t).name(), NULL, NULL, &status); std::cout << "uu = " << uu << "\n"; free(aa); free(uu); aa = abi::__cxa_demangle(typeid(fsm::MccFiniteStateMachine::states_t).name(), NULL, NULL, &status); std::cout << "states = " << aa << "\n"; free(aa); */ 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(); // 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); return 0; }