From 63142899d1e5233c431b5f4b766254701425e9e6 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Fri, 17 Apr 2020 11:02:32 +0100 Subject: [PATCH] simplified some of the fsm sfinae conditions --- lib/include/srslte/common/fsm.h | 33 +++++++++++++++++---------------- lib/test/common/fsm_test.cc | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/include/srslte/common/fsm.h b/lib/include/srslte/common/fsm.h index a6b0f5ada..02cf7e1f3 100644 --- a/lib/include/srslte/common/fsm.h +++ b/lib/include/srslte/common/fsm.h @@ -103,15 +103,19 @@ constexpr bool is_fsm() return std::is_base_of, FSM>::value; } template -constexpr typename std::enable_if(), bool>::type is_nested_fsm() +constexpr typename std::enable_if(), bool>::type is_subfsm() { - return is_fsm() and FSM::is_nested; + return FSM::is_nested; } template -constexpr typename std::enable_if(), bool>::type is_nested_fsm() +constexpr typename std::enable_if(), bool>::type is_subfsm() { return false; } +template +using enable_if_subfsm = typename std::enable_if()>::type; +template +using disable_if_subfsm = typename std::enable_if()>::type; struct fsm_helper { //! Metafunction to determine if FSM can hold given State type @@ -120,7 +124,7 @@ struct fsm_helper { //! Call FSM/State enter method template - static typename std::enable_if()>::type call_enter(FSM* f, State* s) + static enable_if_subfsm call_enter(FSM* f, State* s) { using init_type = typename fsm_state_list_type::init_state_t; // set default FSM type @@ -132,7 +136,7 @@ struct fsm_helper { srslte::visit(visitor, s->derived()->states); } template - static typename std::enable_if()>::type call_enter(FSM* f, State* s) + static disable_if_subfsm call_enter(FSM* f, State* s) { f->enter(*s); } @@ -189,23 +193,20 @@ struct fsm_helper { * Stores True in "result" if state changed. False otherwise */ template - void operator()(CurrentState& s) + disable_if_subfsm operator()(CurrentState& s) + { + result = call_react(s); + } + template + enable_if_subfsm operator()(CurrentState& s) { - result = call_trigger(&s); + // Enter here for SubFSMs + result = s.trigger(std::forward(ev)); if (not result) { result = call_react(s); } } - //! In case it is a NestedFSM, call the trigger method - template - typename std::enable_if(), bool>::type call_trigger(State* s) - { - return s->trigger(std::forward(ev)); - } - //! In case a "trigger(Event)" method is not found - bool call_trigger(...) { return false; } - template using enable_if_react = decltype(std::declval().react(std::declval(), std::declval()), bool()); diff --git a/lib/test/common/fsm_test.cc b/lib/test/common/fsm_test.cc index 132853988..e7072e52b 100644 --- a/lib/test/common/fsm_test.cc +++ b/lib/test/common/fsm_test.cc @@ -148,7 +148,7 @@ namespace srslte { namespace fsm_details { static_assert(is_fsm(), "invalid metafunction\n"); -static_assert(is_nested_fsm(), "invalid metafunction\n"); +static_assert(is_subfsm(), "invalid metafunction\n"); static_assert(std::is_same, fsm1::state_list >::value, "get state list failed\n");