clean up comments and add some util functions

This commit is contained in:
Francisco Paisana 2020-03-31 13:00:51 +01:00 committed by Francisco Paisana
parent 7dc1489ea7
commit dc0427804f
2 changed files with 15 additions and 5 deletions

View File

@ -82,7 +82,7 @@ struct fsm_helper {
{ {
// do nothing // 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 <typename FSM, typename... Args, typename PrevState> template <typename FSM, typename... Args, typename PrevState>
static void handle_state_change(FSM* f, choice_t<Args...>* s, PrevState* p) static void handle_state_change(FSM* f, choice_t<Args...>* s, PrevState* p)
{ {
@ -164,10 +164,11 @@ public:
virtual void exit() {} virtual void exit() {}
}; };
//! CRTP Class for all non-nested FSMs
template <typename Derived> template <typename Derived>
class fsm_t : public state_t class fsm_t : public state_t
{ {
public: protected:
// get access to derived protected members from the base // get access to derived protected members from the base
class derived_view : public Derived class derived_view : public Derived
{ {
@ -175,6 +176,8 @@ public:
using Derived::react; using Derived::react;
using Derived::states; using Derived::states;
}; };
public:
static const bool is_nested = false; static const bool is_nested = false;
// Push Events to FSM // Push Events to FSM
@ -204,6 +207,13 @@ public:
return visitor.name; return visitor.name;
} }
//! Static method to check if State belongs to the list of possible states
template <typename State>
constexpr static bool can_hold_state()
{
return fsm_details::fsm_helper::get_fsm_state_list<fsm_t<Derived> >::template can_hold_type<State>();
}
protected: protected:
friend struct fsm_details::fsm_helper; friend struct fsm_details::fsm_helper;
@ -217,7 +227,6 @@ class nested_fsm_t : public fsm_t<Derived>
{ {
using base_t = fsm_t<Derived>; using base_t = fsm_t<Derived>;
using parent_t = ParentFSM; using parent_t = ParentFSM;
using parent_view = typename parent_t::derived_view;
public: public:
static const bool is_nested = true; static const bool is_nested = true;

View File

@ -137,6 +137,7 @@ static_assert(std::is_same<fsm_helper::enable_if_fsm_state<fsm1, fsm1::idle_st>,
"get state list failed\n"); "get state list failed\n");
static_assert(std::is_same<fsm_helper::disable_if_fsm_state<fsm1, fsm1::fsm2::state_inner>, void>::value, static_assert(std::is_same<fsm_helper::disable_if_fsm_state<fsm1, fsm1::fsm2::state_inner>, void>::value,
"get state list failed\n"); "get state list failed\n");
static_assert(fsm1::can_hold_state<fsm1::state1>(), "can hold state method failed\n");
} // namespace fsm_details } // namespace fsm_details
} // namespace srslte } // namespace srslte