FSM statics update

This commit is contained in:
John Wellbelove 2023-04-30 18:08:53 +01:00
parent 9f4c5bbb94
commit 4d153b2a18
2 changed files with 76 additions and 115 deletions

View File

@ -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 <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_, typename... TMessageTypes>
ETL_CONSTANT etl::fsm_state_id_t fsm_state<TContext, TDerived, STATE_ID_, TMessageTypes...>::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<TDerived*>(this)->on_event_unknown(message);
}
};
template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_,
typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8,
typename T9, typename T10, typename T11, typename T12,
typename T13, typename T14, typename T15, typename T16>
ETL_CONSTANT etl::fsm_state_id_t fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::STATE_ID;
#endif
}

View File

@ -93,12 +93,12 @@ namespace etl
typedef typename etl::larger_type<etl::message_id_t>::type fsm_internal_id_t;
#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above
template <typename, typename, const etl::fsm_state_id_t, typename...>
template <typename, typename, etl::fsm_state_id_t, typename...>
class fsm_state;
#else
/*[[[cog
import cog
cog.outl("template <typename, typename, const etl::fsm_state_id_t,")
cog.outl("template <typename, typename, etl::fsm_state_id_t,")
cog.out(" ")
for n in range(1, int(Handlers)):
cog.out("typename, ")
@ -221,13 +221,16 @@ namespace etl
friend class etl::fsm;
friend class etl::hfsm;
using private_fsm::ifsm_state_helper<>::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 <typename, typename, const etl::fsm_state_id_t, typename...>
template <typename, typename, etl::fsm_state_id_t, typename...>
friend class fsm_state;
#else
/*[[[cog
import cog
cog.outl(" template <typename, typename, const etl::fsm_state_id_t,")
cog.outl(" template <typename, typename, etl::fsm_state_id_t,")
cog.out(" ")
for n in range(1, int(Handlers)):
cog.out("typename, ")
@ -341,9 +344,6 @@ namespace etl
ifsm_state& operator =(const ifsm_state&);
};
ETL_CONSTANT fsm_state_id_t ifsm_state::No_State_Change;
ETL_CONSTANT fsm_state_id_t ifsm_state::Pass_To_Parent;
//***************************************************************************
/// The FSM class.
//***************************************************************************
@ -530,32 +530,27 @@ 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.
//***************************************************************************
template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_, typename... TMessageTypes>
template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_, typename... TMessageTypes>
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 <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_, typename... TMessageTypes>
ETL_CONSTANT etl::fsm_state_id_t fsm_state<TContext, TDerived, STATE_ID_, TMessageTypes...>::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 <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_, ")
cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_, ")
cog.out(" ")
for n in range(1, int(Handlers)):
cog.out("typename T%s = void, " % n)
@ -636,10 +636,7 @@ namespace etl
cog.outl("{")
cog.outl("public:")
cog.outl("")
cog.outl(" enum")
cog.outl(" {")
cog.outl(" STATE_ID = STATE_ID_")
cog.outl(" };")
cog.outl(" static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_;")
cog.outl("")
cog.outl(" fsm_state()")
cog.outl(" : ifsm_state(STATE_ID)")
@ -690,7 +687,7 @@ namespace etl
else:
cog.outl("// Specialisation for %d message types." % n)
cog.outl("//***************************************************************************")
cog.outl("template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_, ")
cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_, ")
cog.out(" ")
for t in range(1, n):
cog.out("typename T%d, " % t)
@ -713,10 +710,7 @@ namespace etl
cog.outl("{")
cog.outl("public:")
cog.outl("")
cog.outl(" enum")
cog.outl(" {")
cog.outl(" STATE_ID = STATE_ID_")
cog.outl(" };")
cog.outl(" static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_;")
cog.outl("")
cog.outl(" fsm_state()")
cog.outl(" : ifsm_state(STATE_ID)")
@ -762,7 +756,7 @@ namespace etl
cog.outl("//***************************************************************************")
cog.outl("// Specialisation for 0 message types.")
cog.outl("//***************************************************************************")
cog.outl("template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_>")
cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_>")
cog.out("class fsm_state<TContext, TDerived, STATE_ID_, ")
for t in range(1, int(Handlers)):
cog.out("void, ")
@ -773,10 +767,7 @@ namespace etl
cog.outl("{")
cog.outl("public:")
cog.outl("")
cog.outl(" enum")
cog.outl(" {")
cog.outl(" STATE_ID = STATE_ID_")
cog.outl(" };")
cog.outl(" static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_;")
cog.outl("")
cog.outl(" fsm_state()")
cog.outl(" : ifsm_state(STATE_ID)")
@ -800,6 +791,20 @@ namespace etl
cog.outl(" return p_parent ? p_parent->process_event(message) : static_cast<TDerived*>(this)->on_event_unknown(message);")
cog.outl(" }")
cog.outl("};")
cog.outl("")
cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_, ")
cog.out(" ")
for n in range(1, int(Handlers)):
cog.out("typename T%s, " % n)
if n % 4 == 0:
cog.outl("")
cog.out(" ")
cog.outl("typename T%s>" % Handlers)
cog.out("ETL_CONSTANT etl::fsm_state_id_t fsm_state<TContext, TDerived, STATE_ID_, ")
for n in range(1, int(Handlers)):
cog.out("T%s, " % n)
cog.outl("T%s>::STATE_ID;" % Handlers)
]]]*/
/*[[[end]]]*/
#endif