diff --git a/cxx/mcc_fsm.h b/cxx/mcc_fsm.h index d455221..cd7873a 100644 --- a/cxx/mcc_fsm.h +++ b/cxx/mcc_fsm.h @@ -165,9 +165,9 @@ namespace traits template concept fsm_trans_table_c = requires { - // [](std::type_identity>) { - // }(std::type_identity()); - requires true; + [](std::type_identity>) { + }(std::type_identity()); + // requires true; }; @@ -195,7 +195,7 @@ public: // initFromInitial(typeid(ST)); // } - MccFiniteStateMachine() {} + MccFiniteStateMachine() : _currentStateID(InitStateT::ID), _currentStateVariant(&std::get(_states)) {} template void dispatchEvent(EvT event) @@ -325,34 +325,52 @@ protected: template struct variant_maker_t> { - // using variant_t = std::variant; - using variant_t = std::variant...>; + using variant_t = std::variant; }; - template - struct collect_states_t; + + // template > + // struct deduce_states_t; + + // template + // struct deduce_states_t, OutTplT> { + // using curr_collection_t = + // merge_tuples_res_t, typename StTs::transition_t::unique_states_t...>; + + // using states_t = std::conditional_t< + // std::tuple_size_v == std::tuple_size_v, + // curr_collection_t, + // merge_tuples_res_t>::curr_collection_t>>; + // }; - template - struct collect_states_t, TplTs...> { - using states_t = - merge_tuples_res_t, - typename collect_states_t::states_t, - TplTs...>; + template + struct deduce_states_t; + + template + struct deduce_states_t { + using states_t = ResTplT; }; - template - struct collect_states_t, TplTs...> { - using states_t = - merge_tuples_res_t, - typename collect_states_t::states_t, - TplTs...>; + template + struct deduce_states_t, InTplTs...> { + using curr_collection_t = + merge_tuples_res_t, typename StTs::transition_t::unique_states_t...>; + + using states_t = typename deduce_states_t == std::tuple_size_v, + curr_collection_t, + typename StTs::transition_t::unique_states_t...>::states_t; }; - using states_t = typename collect_states_t>::states_t; +public: + // using states_t = typename deduce_states_t>::states_t; + using states_t = typename deduce_states_t, std::tuple>::states_t; +protected: states_t _states; typename variant_maker_t::variant_t _currentStateVariant; }; diff --git a/cxx/tests/fsm_test.cpp b/cxx/tests/fsm_test.cpp index 82a907b..7d8eaf1 100644 --- a/cxx/tests/fsm_test.cpp +++ b/cxx/tests/fsm_test.cpp @@ -23,15 +23,26 @@ struct EV2 { static constexpr std::string_view ID = "EV2"; }; +struct EV3 { + static constexpr std::string_view ID = "EV3"; +}; + +struct ST1; +struct ST2; struct STN : fsm::MccFsmAbstractState { static constexpr std::string_view ID = "STN"; - using transition_t = trans_table_t, std::pair>; + 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>; + using transition_t = trans_table_t, std::pair>; }; struct ST1 : fsm::MccFsmAbstractState { @@ -43,7 +54,7 @@ struct ST1 : fsm::MccFsmAbstractState { // static_assert(fsm::traits::fsm_trans_table_c, "!!!!!!!!!!!!!"); -// fsm::MccFiniteStateMachine fsm; +fsm::MccFiniteStateMachine fsm; int main() { @@ -87,5 +98,8 @@ int main() free(aa); free(uu); + aa = abi::__cxa_demangle(typeid(fsm::MccFiniteStateMachine::states_t).name(), NULL, NULL, &status); + std::cout << "states = " << aa << "\n"; + return 0; }