From dc0427804fa4036b7127abe26c00bb5702e402f6 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Tue, 31 Mar 2020 13:00:51 +0100 Subject: [PATCH] clean up comments and add some util functions --- lib/include/srslte/common/fsm.h | 19 ++++++++++++++----- lib/test/common/fsm_test.cc | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/include/srslte/common/fsm.h b/lib/include/srslte/common/fsm.h index c415825b1..50ef90f2c 100644 --- a/lib/include/srslte/common/fsm.h +++ b/lib/include/srslte/common/fsm.h @@ -82,7 +82,7 @@ struct fsm_helper { { // do nothing } - //! TargetState is type-erased. Apply its stored type to the fsm current state + //! TargetState is type-erased (a choice). Apply its stored type to the fsm current state template static void handle_state_change(FSM* f, choice_t* s, PrevState* p) { @@ -164,10 +164,11 @@ public: virtual void exit() {} }; +//! CRTP Class for all non-nested FSMs template class fsm_t : public state_t { -public: +protected: // get access to derived protected members from the base class derived_view : public Derived { @@ -175,6 +176,8 @@ public: using Derived::react; using Derived::states; }; + +public: static const bool is_nested = false; // Push Events to FSM @@ -204,6 +207,13 @@ public: return visitor.name; } + //! Static method to check if State belongs to the list of possible states + template + constexpr static bool can_hold_state() + { + return fsm_details::fsm_helper::get_fsm_state_list >::template can_hold_type(); + } + protected: friend struct fsm_details::fsm_helper; @@ -215,9 +225,8 @@ protected: template class nested_fsm_t : public fsm_t { - using base_t = fsm_t; - using parent_t = ParentFSM; - using parent_view = typename parent_t::derived_view; + using base_t = fsm_t; + using parent_t = ParentFSM; public: static const bool is_nested = true; diff --git a/lib/test/common/fsm_test.cc b/lib/test/common/fsm_test.cc index 7294bf013..407bb9f87 100644 --- a/lib/test/common/fsm_test.cc +++ b/lib/test/common/fsm_test.cc @@ -137,6 +137,7 @@ static_assert(std::is_same, "get state list failed\n"); static_assert(std::is_same, void>::value, "get state list failed\n"); +static_assert(fsm1::can_hold_state(), "can hold state method failed\n"); } // namespace fsm_details } // namespace srslte