Loading...
Searching...
No Matches
fsm_cpp03_generator.h
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2026 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
//***************************************************************************
// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.
//***************************************************************************
//*************************************************************************************************
// For C++03 and below.
//*************************************************************************************************
/*[[[cog
import cog
################################################
# The first definition for all of the events.
################################################
cog.outl("//***************************************************************************")
cog.outl("// The definition for all %s message types." % Handlers)
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 = void," % n)
if n % 4 == 0:
cog.outl("")
cog.out(" ")
cog.outl(" typename T%s = void>" % Handlers)
cog.outl("class fsm_state : public ifsm_state")
cog.outl("{")
cog.outl("public:")
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)")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl("protected:")
cog.outl("")
cog.outl(" ~fsm_state()")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl(" TContext& get_fsm_context() const")
cog.outl(" {")
cog.outl(" return static_cast<TContext&>(ifsm_state::get_fsm_context());")
cog.outl(" }")
cog.outl("")
cog.outl("private:")
cog.outl("")
cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)")
cog.outl(" {")
cog.outl(" etl::fsm_state_id_t new_state_id;")
cog.outl(" etl::message_id_t event_id = message.get_message_id();")
cog.outl("")
cog.outl(" switch (event_id)")
cog.outl(" {")
for n in range(1, int(Handlers) + 1):
cog.out(" case T%d::ID:" % n)
cog.out(" new_state_id = static_cast<TDerived*>(this)->on_event(static_cast<const T%d&>(message));" % n)
cog.outl(" break;")
cog.out(" default:")
cog.out(" new_state_id = p_parent ? p_parent->process_event(message) : static_cast<TDerived*>(this)->on_event_unknown(message);")
cog.outl(" break;")
cog.outl(" }")
cog.outl("")
cog.outl(" return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(message) : No_State_Change);")
cog.outl(" }")
cog.outl("};")
####################################
# All of the other specialisations.
####################################
for n in range(int(Handlers) - 1, 0, -1):
cog.outl("")
cog.outl("//***************************************************************************")
if n == 1:
cog.outl("// Specialisation for %d message type." % n)
else:
cog.outl("// Specialisation for %d message types." % n)
cog.outl("//***************************************************************************")
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)
if t % 4 == 0:
cog.outl("")
cog.out(" ")
cog.outl(" typename T%d>" % n)
cog.out("class fsm_state<TContext, TDerived, STATE_ID_,")
for t in range(1, n + 1):
cog.out(" T%d," % t)
if t % 16 == 0:
cog.outl("")
cog.out(" ")
for t in range(n + 1, int(Handlers)):
cog.out(" void,")
if t % 16 == 0:
cog.outl("")
cog.out(" ")
cog.outl(" void> : public ifsm_state")
cog.outl("{")
cog.outl("public:")
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)")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl("protected:")
cog.outl("")
cog.outl(" ~fsm_state()")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl(" TContext& get_fsm_context() const")
cog.outl(" {")
cog.outl(" return static_cast<TContext&>(ifsm_state::get_fsm_context());")
cog.outl(" }")
cog.outl("")
cog.outl("private:")
cog.outl("")
cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)")
cog.outl(" {")
cog.outl(" etl::fsm_state_id_t new_state_id;")
cog.outl(" etl::message_id_t event_id = message.get_message_id();")
cog.outl("")
cog.outl(" switch (event_id)")
cog.outl(" {")
for n in range(1, n + 1):
cog.out(" case T%d::ID:" % n)
cog.out(" new_state_id = static_cast<TDerived*>(this)->on_event(static_cast<const T%d&>(message));" % n)
cog.outl(" break;")
cog.out(" default:")
cog.out(" new_state_id = p_parent ? p_parent->process_event(message) : static_cast<TDerived*>(this)->on_event_unknown(message);")
cog.outl(" break;")
cog.outl(" }")
cog.outl("")
cog.outl(" return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(message) : No_State_Change);")
cog.outl(" }")
cog.outl("};")
####################################
# Specialisation for zero messages.
####################################
cog.outl("")
cog.outl("//***************************************************************************")
cog.outl("// Specialisation for 0 message types.")
cog.outl("//***************************************************************************")
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,")
if t % 16 == 0:
cog.outl("")
cog.out(" ")
cog.outl(" void> : public ifsm_state")
cog.outl("{")
cog.outl("public:")
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)")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl("protected:")
cog.outl("")
cog.outl(" ~fsm_state()")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl(" TContext& get_fsm_context() const")
cog.outl(" {")
cog.outl(" return static_cast<TContext&>(ifsm_state::get_fsm_context());")
cog.outl(" }")
cog.outl("private:")
cog.outl("")
cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)")
cog.outl(" {")
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]]]*/