FSM: working compile-time deducing states from initial one (i hope ...)
This commit is contained in:
@@ -165,9 +165,9 @@ namespace traits
|
||||
|
||||
template <typename T>
|
||||
concept fsm_trans_table_c = requires {
|
||||
// []<fsm_event_state_pair_c... PTs>(std::type_identity<mcc::fsm::MccFsmAbstractState::trans_table_t<PTs...>>) {
|
||||
// }(std::type_identity<T>());
|
||||
requires true;
|
||||
[]<fsm_event_state_pair_c... PTs>(std::type_identity<mcc::fsm::MccFsmAbstractState::trans_table_t<PTs...>>) {
|
||||
}(std::type_identity<T>());
|
||||
// requires true;
|
||||
};
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
// initFromInitial<ST::transition_t::evst_pairs_t>(typeid(ST));
|
||||
// }
|
||||
|
||||
MccFiniteStateMachine() {}
|
||||
MccFiniteStateMachine() : _currentStateID(InitStateT::ID), _currentStateVariant(&std::get<InitStateT>(_states)) {}
|
||||
|
||||
template <traits::fsm_event_c EvT>
|
||||
void dispatchEvent(EvT event)
|
||||
@@ -325,34 +325,52 @@ protected:
|
||||
|
||||
template <typename... Ts>
|
||||
struct variant_maker_t<std::tuple<Ts...>> {
|
||||
// using variant_t = std::variant<Ts*...>;
|
||||
using variant_t = std::variant<std::reference_wrapper<Ts>...>;
|
||||
using variant_t = std::variant<Ts*...>;
|
||||
};
|
||||
|
||||
|
||||
template <typename... TplTs>
|
||||
struct collect_states_t;
|
||||
|
||||
// template <typename InTplT, typename OutTplT = std::tuple<>>
|
||||
// struct deduce_states_t;
|
||||
|
||||
// template <traits::fsm_state_c... StTs, typename OutTplT>
|
||||
// struct deduce_states_t<std::tuple<StTs...>, OutTplT> {
|
||||
// using curr_collection_t =
|
||||
// merge_tuples_res_t<OutTplT, std::tuple<StTs...>, typename StTs::transition_t::unique_states_t...>;
|
||||
|
||||
// using states_t = std::conditional_t<
|
||||
// std::tuple_size_v<OutTplT> == std::tuple_size_v<curr_collection_t>,
|
||||
// curr_collection_t,
|
||||
// merge_tuples_res_t<curr_collection_t,
|
||||
// typename deduce_states_t<merge_tuples_res_t<
|
||||
// typename StTs::transition_t::unique_states_t...>>::curr_collection_t>>;
|
||||
// };
|
||||
|
||||
|
||||
template <traits::fsm_state_c StT, typename... TplTs>
|
||||
struct collect_states_t<std::tuple<StT>, TplTs...> {
|
||||
using states_t =
|
||||
merge_tuples_res_t<std::tuple<StT>,
|
||||
typename collect_states_t<typename StT::transition_t::unique_states_t>::states_t,
|
||||
TplTs...>;
|
||||
template <bool stop, typename ResTplT, typename... InTplTs>
|
||||
struct deduce_states_t;
|
||||
|
||||
template <typename ResTplT, typename... InTplTs>
|
||||
struct deduce_states_t<true, ResTplT, InTplTs...> {
|
||||
using states_t = ResTplT;
|
||||
};
|
||||
|
||||
template <traits::fsm_state_c... StTs, typename... TplTs>
|
||||
struct collect_states_t<std::tuple<StTs...>, TplTs...> {
|
||||
using states_t =
|
||||
merge_tuples_res_t<std::tuple<StTs...>,
|
||||
typename collect_states_t<typename StTs::transition_t::unique_states_t...>::states_t,
|
||||
TplTs...>;
|
||||
template <typename ResTplT, traits::fsm_state_c... StTs, typename... InTplTs>
|
||||
struct deduce_states_t<false, ResTplT, std::tuple<StTs...>, InTplTs...> {
|
||||
using curr_collection_t =
|
||||
merge_tuples_res_t<ResTplT, std::tuple<StTs...>, typename StTs::transition_t::unique_states_t...>;
|
||||
|
||||
using states_t = typename deduce_states_t<std::tuple_size_v<ResTplT> == std::tuple_size_v<curr_collection_t>,
|
||||
curr_collection_t,
|
||||
typename StTs::transition_t::unique_states_t...>::states_t;
|
||||
};
|
||||
|
||||
|
||||
using states_t = typename collect_states_t<std::tuple<InitStateT>>::states_t;
|
||||
public:
|
||||
// using states_t = typename deduce_states_t<std::tuple<InitStateT>>::states_t;
|
||||
using states_t = typename deduce_states_t<false, std::tuple<>, std::tuple<InitStateT>>::states_t;
|
||||
|
||||
protected:
|
||||
states_t _states;
|
||||
typename variant_maker_t<states_t>::variant_t _currentStateVariant;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user