From e069ed84f094694f109164738d9b262dacfc5041 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sun, 1 Jun 2025 23:41:18 +0300 Subject: [PATCH] MccFiniteStateMachine: compiled --- cxx/mcc_finite_state_machine.h | 72 +++++++++++++++++----------------- cxx/tests/fsm_test.cpp | 3 +- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/cxx/mcc_finite_state_machine.h b/cxx/mcc_finite_state_machine.h index 06419f3..dbe330f 100644 --- a/cxx/mcc_finite_state_machine.h +++ b/cxx/mcc_finite_state_machine.h @@ -63,7 +63,7 @@ template struct fsm_transition_table_t { using events_t = std::tuple; - using event_state_pair_t = PT; + using event_state_pair_t = std::tuple; using unique_states_t = std::tuple; @@ -76,7 +76,7 @@ struct fsm_transition_table_t { template struct fsm_transition_table_t { private: - static constexpr bool non_unique_event = (std::same_as || ...); + static constexpr bool non_unique_event = (std::same_as || ...); public: using events_t = @@ -171,11 +171,13 @@ protected: template struct deduce_states, InTplTs...> { + // using curr_collection_t = merge_tuples_t>; using curr_collection_t = merge_tuples_t, typename StTs::transition_t::unique_states_t...>; using states_t = typename deduce_states == std::tuple_size_v, curr_collection_t, + // merge_tuples_t, typename StTs::transition_t::unique_states_t..., InTplTs...>::states_t; }; @@ -185,40 +187,27 @@ protected: // deduce all unique events from the initial state transition table - template + + template struct deduce_events; - template - struct deduce_events { + template + struct deduce_events { using events_t = ResTplT; }; - template - struct deduce_events> { - using curr_collection_t = typename StT::transition_t::events_t; - using events_t = typename deduce_states::events_t; - }; + template + struct deduce_events> { + using curr_collection_t = merge_tuples_t; - template - struct deduce_events, InTplTs...> { - using curr_collection_t = merge_tuples_t; - - using events_t = typename deduce_states == std::tuple_size_v, - curr_collection_t, - typename StTs::transition_t::events_t..., - typename StTs::transition_t::unique_states_t...>::events_t; + using events_t = + typename deduce_events == std::tuple_size_v, + curr_collection_t, + merge_tuples_t>::events_t; }; template - using deduce_events_t = typename deduce_events::events_t; - // using deduce_events_t = typename deduce_events, std::tuple<>, - // std::tuple>::events_t; + using deduce_events_t = typename deduce_events, std::tuple>::events_t; template struct variant_from_tuple; @@ -261,21 +250,35 @@ public: int status; char* aa = abi::__cxa_demangle(typeid(states_t).name(), NULL, NULL, &status); - std::cout << "states_t = " << aa << '\n'; + std::cout << "deduced states_t = " << aa << '\n'; free(aa); - /* - aa = abi::__cxa_demangle(typeid(deduce_events_t).name(), NULL, NULL, &status); + aa = abi::__cxa_demangle(typeid(typename InitStateT::transition_t::event_state_pair_t).name(), NULL, NULL, + &status); + std::cout << "event_state_pair_t = " << aa << '\n'; + free(aa); + + aa = abi::__cxa_demangle(typeid(typename InitStateT::transition_t::events_t).name(), NULL, NULL, &status); std::cout << "events_t = " << aa << '\n'; free(aa); + aa = + abi::__cxa_demangle(typeid(typename InitStateT::transition_t::unique_states_t).name(), NULL, NULL, &status); + std::cout << "unique_states_t = " << aa << '\n'; + free(aa); + + aa = abi::__cxa_demangle(typeid(deduce_events_t).name(), NULL, NULL, &status); + std::cout << "deduced events_t = " << aa << '\n'; + free(aa); + + // setup dispatch event functions - for_each_event>([states, currentState, this](EvT) { - _dispatchEventFunc[this] = [states, currentState, this](EvT& event) { + for_each_event>([states, currentState, this](EvT) mutable { + _dispatchEventFunc[this] = [states, currentState, this](EvT& event) mutable { std::visit( [&event, states](curr_state_t*) { - using to_state_t = curr_state_t::trasition_table_t::template find_state_by_event_t; + using to_state_t = curr_state_t::transition_t::template find_state_by_event_t; if constexpr (std::is_void_v) { /// throw?!! return; @@ -310,10 +313,9 @@ public: std::get(states).enter(); } }, - currentState); + *currentState); }; }); - */ } diff --git a/cxx/tests/fsm_test.cpp b/cxx/tests/fsm_test.cpp index fded000..fb0a4e8 100644 --- a/cxx/tests/fsm_test.cpp +++ b/cxx/tests/fsm_test.cpp @@ -48,7 +48,8 @@ struct ST2 { struct ST1 { static constexpr std::string_view ID = "ST1"; - using transition_t = fsm::fsm_transition_table_t, std::pair>; + using transition_t = + fsm::fsm_transition_table_t, std::pair, std::pair, std::pair>; }; // struct STN : fsm::MccFsmAbstractState {