From be5a33f9b744827b228aa418fa87daf4b5c29496 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Sun, 29 Mar 2020 21:08:29 +0100 Subject: [PATCH] deleted unused fsm methods --- lib/include/srslte/common/fsm.h | 60 +++++++++++++-------------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/lib/include/srslte/common/fsm.h b/lib/include/srslte/common/fsm.h index eb210935e..8f65691ca 100644 --- a/lib/include/srslte/common/fsm.h +++ b/lib/include/srslte/common/fsm.h @@ -66,30 +66,30 @@ struct variant_convert { struct fsm_helper { //! Stayed in same state template - static void handle_state_transition(FSM* f, same_state s, PrevState* p) + static void handle_state_change(FSM* f, same_state* s, PrevState* p) { // do nothing } //! TargetState is type-erased. Apply its stored type to the fsm current state template - static void handle_state_transition(FSM* f, choice_t& s, PrevState* p) + static void handle_state_change(FSM* f, choice_t* s, PrevState* p) { fsm_details::variant_convertstates), PrevState> visitor{.v = &f->states, .p = p}; - s.visit(visitor); + s->visit(visitor); } //! Simple state transition in FSM template - static auto handle_state_transition(FSM* f, State& s, PrevState* p) -> decltype(f->states = s, void()) + static auto handle_state_change(FSM* f, State* s, PrevState* p) -> decltype(f->states = std::move(*s), void()) { static_assert(not std::is_same::value, "State cannot transition to itself.\n"); - f->states = s; + f->states = std::move(*s); } //! State not present in current FSM. Attempt state transition in parent FSM in the case of NestedFSM template - static void handle_state_transition(FSM* f, Args&&... args) + static void handle_state_change(FSM* f, Args&&... args) { static_assert(FSM::is_nested, "State is not present in the FSM list of valid states"); - handle_state_transition(f->parent_fsm()->derived(), args...); + handle_state_change(f->parent_fsm()->derived(), args...); } //! Trigger Event, that will result in a state transition @@ -97,34 +97,35 @@ struct fsm_helper { struct trigger_visitor { trigger_visitor(FSM* f_, Event&& ev_) : f(f_), ev(std::forward(ev_)) {} - template - void operator()(State& s) + //! Trigger visitor callback for the current state + template + void operator()(CurrentState& s) { - call_trigger(s); + call_trigger(&s); } + //! Compute next state type template using NextState = decltype(std::declval().react(std::declval(), std::declval())); + //! In case a react(CurrentState&, Event) method is found template - auto call_trigger(State& s) -> NextState + auto call_trigger(State* current_state) -> NextState { using next_state = NextState; static_assert(not std::is_same::value, "State cannot transition to itself.\n"); - auto target_state = f->react(s, std::move(ev)); - fsm_helper::handle_state_transition(f, target_state, &s); + auto target_state = f->react(*current_state, std::move(ev)); + fsm_helper::handle_state_change(f, &target_state, current_state); return target_state; } + //! In case a react(CurrentState&, Event) method is not found, but we are in a NestedFSM with a trigger method template - auto call_trigger(State& s) -> decltype(std::declval().trigger(std::declval())) + auto call_trigger(State* s) -> decltype(std::declval().trigger(std::declval())) { - s.trigger(std::move(ev)); - } - same_state call_trigger(...) - { - // do nothing if no react was found - return same_state{}; + s->trigger(std::move(ev)); } + //! No trigger or react method found. Do nothing + void call_trigger(...) {} FSM* f; Event ev; @@ -158,7 +159,6 @@ public: using Derived::react; using Derived::states; }; - static const bool is_nested = false; virtual const char* name() const = 0; @@ -167,7 +167,8 @@ public: template void trigger(Ev&& e) { - fwd_trigger(std::forward(e)); + fsm_details::fsm_helper::trigger_visitor visitor{derived(), std::forward(e)}; + derived()->states.visit(visitor); } template @@ -192,20 +193,6 @@ public: protected: friend struct fsm_details::fsm_helper; - // Forward an event to FSM states and handle transition return - template - void fwd_trigger(Ev&& e) - { - fsm_details::fsm_helper::trigger_visitor visitor{derived(), std::forward(e)}; - derived()->states.visit(visitor); - } - - template - void change_state(State& s) - { - derived()->states = std::move(s); - } - // Access to CRTP derived class derived_view* derived() { return static_cast(this); } const derived_view* derived() const { return static_cast(this); } @@ -228,7 +215,6 @@ public: parent_t* parent_fsm() { return fsm_ptr; } protected: - friend struct fsm_details::fsm_helper; using parent_fsm_t = ParentFSM; ParentFSM* fsm_ptr = nullptr;