diff --git a/include/etl/fsm.h b/include/etl/fsm.h index d06e2f6e..bb4d21f9 100644 --- a/include/etl/fsm.h +++ b/include/etl/fsm.h @@ -504,17 +504,17 @@ namespace etl bool have_changed_state(etl::fsm_state_id_t next_state_id) const { return (next_state_id != p_state->get_state_id()) && - (next_state_id != ifsm_state::No_State_Change); + (next_state_id != ifsm_state::No_State_Change); } - etl::ifsm_state* p_state; ///< A pointer to the current state. - etl::ifsm_state** state_list; ///< The list of added states. + etl::ifsm_state* p_state; ///< A pointer to the current state. + etl::ifsm_state** state_list; ///< The list of added states. etl::fsm_state_id_t number_of_states; ///< The number of states. }; -//************************************************************************************************* -// For C++17 and above. -//************************************************************************************************* + //************************************************************************************************* + // For C++17 and above. + //************************************************************************************************* #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above //*************************************************************************** // The definition for all types. @@ -524,12 +524,7 @@ namespace etl { public: - public: - - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -586,6 +581,11 @@ namespace etl } } }; + + /// Definition of STATE_ID + template + ETL_CONSTANT etl::fsm_state_id_t fsm_state::STATE_ID; + #else //************************************************************************************************* // For C++14 and below. @@ -602,10 +602,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -667,10 +664,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -731,10 +725,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -794,10 +785,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -855,10 +843,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -915,10 +900,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -974,10 +956,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1032,10 +1011,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1088,10 +1064,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1143,10 +1116,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1197,10 +1167,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1250,10 +1217,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1301,10 +1265,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1351,10 +1312,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1400,10 +1358,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1448,10 +1403,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1494,10 +1446,7 @@ namespace etl { public: - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -1521,6 +1470,13 @@ namespace etl return p_parent ? p_parent->process_event(message) : static_cast(this)->on_event_unknown(message); } }; + + template + ETL_CONSTANT etl::fsm_state_id_t fsm_state::STATE_ID; #endif } diff --git a/include/etl/generators/fsm_generator.h b/include/etl/generators/fsm_generator.h index 6d5e945a..7a8f054a 100644 --- a/include/etl/generators/fsm_generator.h +++ b/include/etl/generators/fsm_generator.h @@ -93,12 +93,12 @@ namespace etl typedef typename etl::larger_type::type fsm_internal_id_t; #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above - template + template class fsm_state; #else /*[[[cog import cog - cog.outl("template ::No_State_Change; + using private_fsm::ifsm_state_helper<>::Pass_To_Parent; + #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above - template + template friend class fsm_state; #else /*[[[cog import cog - cog.outl(" template get_state_id()) && - (next_state_id != ifsm_state::No_State_Change); + (next_state_id != ifsm_state::No_State_Change); } - etl::ifsm_state* p_state; ///< A pointer to the current state. - etl::ifsm_state** state_list; ///< The list of added states. + etl::ifsm_state* p_state; ///< A pointer to the current state. + etl::ifsm_state** state_list; ///< The list of added states. etl::fsm_state_id_t number_of_states; ///< The number of states. }; -//************************************************************************************************* -// For C++17 and above. -//************************************************************************************************* + //************************************************************************************************* + // For C++17 and above. + //************************************************************************************************* #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above //*************************************************************************** // The definition for all types. //*************************************************************************** - template + template class fsm_state : public ifsm_state { public: - public: - - enum - { - STATE_ID = STATE_ID_ - }; + static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_; fsm_state() : ifsm_state(STATE_ID) @@ -612,6 +607,11 @@ namespace etl } } }; + + /// Definition of STATE_ID + template + ETL_CONSTANT etl::fsm_state_id_t fsm_state::STATE_ID; + #else //************************************************************************************************* // For C++14 and below. @@ -624,7 +624,7 @@ namespace etl cog.outl("//***************************************************************************") cog.outl("// The definition for all %s message types." % Handlers) cog.outl("//***************************************************************************") - cog.outl("template ") + cog.outl("template ") cog.out("class fsm_stateprocess_event(message) : static_cast(this)->on_event_unknown(message);") cog.outl(" }") cog.outl("};") + + cog.outl("") + cog.outl("template " % Handlers) + cog.out("ETL_CONSTANT etl::fsm_state_id_t fsm_state::STATE_ID;" % Handlers) ]]]*/ /*[[[end]]]*/ #endif