MccFiniteStateMachine: compiled

This commit is contained in:
Timur A. Fatkhullin 2025-06-01 23:41:18 +03:00
parent f4bd1ceee1
commit e069ed84f0
2 changed files with 39 additions and 36 deletions

View File

@ -63,7 +63,7 @@ template <traits::fsm_pair_of_types_c PT>
struct fsm_transition_table_t<PT> {
using events_t = std::tuple<typename PT::first_type>;
using event_state_pair_t = PT;
using event_state_pair_t = std::tuple<PT>;
using unique_states_t = std::tuple<typename PT::second_type>;
@ -76,7 +76,7 @@ struct fsm_transition_table_t<PT> {
template <traits::fsm_pair_of_types_c PT, traits::fsm_pair_of_types_c... PTs>
struct fsm_transition_table_t<PT, PTs...> {
private:
static constexpr bool non_unique_event = (std::same_as<typename PTs::first_type, typename PTs::first_type> || ...);
static constexpr bool non_unique_event = (std::same_as<typename PT::first_type, typename PTs::first_type> || ...);
public:
using events_t =
@ -171,11 +171,13 @@ protected:
template <typename ResTplT, traits::fsm_state_c... StTs, typename... InTplTs>
struct deduce_states<false, ResTplT, std::tuple<StTs...>, InTplTs...> {
// using curr_collection_t = merge_tuples_t<ResTplT, std::tuple<StTs...>>;
using curr_collection_t =
merge_tuples_t<ResTplT, std::tuple<StTs...>, typename StTs::transition_t::unique_states_t...>;
using states_t = typename deduce_states<std::tuple_size_v<ResTplT> == std::tuple_size_v<curr_collection_t>,
curr_collection_t,
// merge_tuples_t<typename StTs::transition_t::unique_states_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 <bool stop, typename ResTplT, typename... InTplTs>
template <bool stop, typename ResTplT, typename InTplT>
struct deduce_events;
template <typename ResTplT, typename... InTplTs>
struct deduce_events<true, ResTplT, InTplTs...> {
template <typename ResTplT, typename InTplT>
struct deduce_events<true, ResTplT, InTplT> {
using events_t = ResTplT;
};
template <traits::fsm_state_c StT>
struct deduce_events<false, typename StT::transition_t::events_t, std::tuple<>> {
using curr_collection_t = typename StT::transition_t::events_t;
using events_t = typename deduce_states<false,
curr_collection_t,
typename StT::transition_t::events_t,
typename StT::transition_t::unique_states_t>::events_t;
};
template <traits::fsm_tuple_of_events_c ResTplT, traits::fsm_state_c... StTs>
struct deduce_events<false, ResTplT, std::tuple<StTs...>> {
using curr_collection_t = merge_tuples_t<ResTplT, typename StTs::transition_t::events_t...>;
template <traits::fsm_tuple_of_events_c ResTplT,
traits::fsm_tuple_of_events_c... EvTplTs,
traits::fsm_state_c... StTs,
typename... InTplTs>
struct deduce_events<false, ResTplT, EvTplTs..., std::tuple<StTs...>, InTplTs...> {
using curr_collection_t = merge_tuples_t<ResTplT, EvTplTs...>;
using events_t = typename deduce_states<std::tuple_size_v<ResTplT> == std::tuple_size_v<curr_collection_t>,
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<ResTplT> == std::tuple_size_v<curr_collection_t>,
curr_collection_t,
merge_tuples_t<typename StTs::transition_t::unique_states_t...>>::events_t;
};
template <traits::fsm_state_c InitStateT>
using deduce_events_t = typename deduce_events<false, InitStateT>::events_t;
// using deduce_events_t = typename deduce_events<false, std::tuple<>, std::tuple<>,
// std::tuple<InitStateT>>::events_t;
using deduce_events_t = typename deduce_events<false, std::tuple<>, std::tuple<InitStateT>>::events_t;
template <typename TplT>
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<InitStateT>).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<InitStateT>).name(), NULL, NULL, &status);
std::cout << "deduced events_t = " << aa << '\n';
free(aa);
// setup dispatch event functions
for_each_event<deduce_events_t<InitStateT>>([states, currentState, this]<traits::fsm_event_c EvT>(EvT) {
_dispatchEventFunc<EvT>[this] = [states, currentState, this](EvT& event) {
for_each_event<deduce_events_t<InitStateT>>([states, currentState, this]<traits::fsm_event_c EvT>(EvT) mutable {
_dispatchEventFunc<EvT>[this] = [states, currentState, this](EvT& event) mutable {
std::visit(
[&event, states]<traits::fsm_state_c curr_state_t>(curr_state_t*) {
using to_state_t = curr_state_t::trasition_table_t::template find_state_by_event_t<EvT>;
using to_state_t = curr_state_t::transition_t::template find_state_by_event_t<EvT>;
if constexpr (std::is_void_v<to_state_t>) {
/// throw?!!
return;
@ -310,10 +313,9 @@ public:
std::get<curr_state_t>(states).enter();
}
},
currentState);
*currentState);
};
});
*/
}

View File

@ -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<EV1, ST2>, std::pair<EV2, STN>>;
using transition_t =
fsm::fsm_transition_table_t<std::pair<EV1, ST2>, std::pair<EV2, STN>, std::pair<EV3, STN>, std::pair<EV3, STN>>;
};
// struct STN : fsm::MccFsmAbstractState {