Loading...
Searching...
No Matches
message_router_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/98.
//*************************************************************************************************
/*[[[cog
import cog
################################################
# The first definition for all of the messages.
################################################
cog.outl("//***************************************************************************")
cog.outl("// The definition for all %s message types." % Handlers)
cog.outl("//***************************************************************************")
cog.outl("template <typename TDerived,")
cog.out(" ")
for n in range(1, int(Handlers)):
cog.out("typename T%s = void," % n)
if n % 4 == 0:
cog.outl("")
cog.out(" ")
else:
cog.out(" ")
cog.outl("typename T%s = void>" % int(Handlers))
cog.out("class message_router")
cog.outl(" : public imessage_router")
cog.outl("{")
cog.outl("public:")
cog.outl("")
cog.out(" typedef etl::message_packet<")
for n in range(1, int(Handlers)):
cog.out("T%s, " % n)
cog.outl("T%s> message_packet;" % int(Handlers))
cog.outl("")
cog.outl("#if ETL_USING_CPP11")
cog.out(" using message_types = etl::type_list<")
for n in range(1, int(Handlers)):
cog.out("T%s, " % n)
cog.outl("T%s>;" % int(Handlers))
cog.outl("#endif")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" message_router(etl::message_router_id_t id_)")
cog.outl(" : imessage_router(id_)")
cog.outl(" {")
cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)")
cog.outl(" : imessage_router(id_, successor_)")
cog.outl(" {")
cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" message_router()")
cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER)")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" message_router(etl::imessage_router& successor_)")
cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" using etl::imessage_router::receive;")
cog.outl("")
cog.outl(" void receive(const etl::imessage& msg) ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" const etl::message_id_t id = msg.get_message_id();")
cog.outl("")
cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
cog.outl(" switch (id)")
cog.outl(" {")
for n in range(1, int(Handlers) + 1):
cog.out(" case T%d::ID:" % n)
cog.out(" static_cast<TDerived*>(this)->on_receive(static_cast<const T%d&>(msg));" % n)
cog.outl(" break;")
cog.outl(" default:")
cog.outl(" {")
cog.outl(" if (has_successor())")
cog.outl(" {")
cog.outl(" get_successor().receive(msg);")
cog.outl(" }")
cog.outl(" else")
cog.outl(" {")
cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
cog.outl(" }")
cog.outl(" break;")
cog.outl(" }")
cog.outl(" }")
cog.outl("#include \"etl/private/diagnostic_pop.h\"")
cog.outl(" }")
cog.outl("")
cog.outl(" template <typename TMessage>")
cog.out(" typename etl::enable_if<etl::is_message<TMessage>::value && etl::is_one_of<TMessage, ")
for n in range(1, int(Handlers)):
cog.out("T%s, " % n)
cog.outl("T%s>::value, void>::type" % int(Handlers))
cog.outl(" receive(const TMessage& msg)")
cog.outl(" {")
cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
cog.outl(" static_cast<TDerived*>(this)->on_receive(msg);")
cog.outl("#include \"etl/private/diagnostic_pop.h\"")
cog.outl(" }")
cog.outl("")
cog.outl(" template <typename TMessage>")
cog.out(" typename etl::enable_if<etl::is_message<TMessage>::value && !etl::is_one_of<TMessage, ")
for n in range(1, int(Handlers)):
cog.out("T%s, " % n)
cog.outl("T%s>::value, void>::type" % int(Handlers))
cog.outl(" receive(const TMessage& msg)")
cog.outl(" {")
cog.outl(" if (has_successor())")
cog.outl(" {")
cog.outl(" get_successor().receive(msg);")
cog.outl(" }")
cog.outl(" else")
cog.outl(" {")
cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
cog.outl("#include \"etl/private/diagnostic_pop.h\"")
cog.outl(" }")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" using imessage_router::accepts;")
cog.outl("")
cog.outl(" bool accepts(etl::message_id_t id) const ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" switch (id)")
cog.outl(" {")
cog.out(" ")
for n in range(1, int(Handlers) + 1):
cog.out(" case T%d::ID:" % n)
if n % 8 == 0:
cog.outl("")
cog.out(" ")
cog.outl(" return true;")
cog.outl(" default:")
cog.outl(" {")
cog.outl(" if (has_successor())")
cog.outl(" {")
cog.outl(" return get_successor().accepts(id);")
cog.outl(" }")
cog.outl(" else")
cog.outl(" {")
cog.outl(" return false;")
cog.outl(" }")
cog.outl(" }")
cog.outl(" }")
cog.outl(" }")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" return false;")
cog.outl(" }")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" bool is_producer() const ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" return true;")
cog.outl(" }")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" bool is_consumer() const ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" return true;")
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 TDerived,")
cog.out(" ")
for t in range(1, n):
cog.out("typename T%d," % t)
if t % 4 == 0:
cog.outl("")
cog.out(" ")
else:
cog.out(" ")
cog.outl("typename T%d>" % n)
cog.out("class message_router<TDerived, ")
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>")
cog.outl(" : public imessage_router")
cog.outl("{")
cog.outl("public:")
cog.outl("")
cog.out(" typedef etl::message_packet<")
for t in range(1, n):
cog.out("T%s, " % t)
cog.outl(" T%s> message_packet;" % n)
cog.outl("")
cog.outl("#if ETL_USING_CPP11")
cog.out(" using message_types = etl::type_list<")
for t in range(1, n):
cog.out("T%s, " % t)
cog.outl("T%s>;" % n)
cog.outl("#endif")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" message_router(etl::message_router_id_t id_)")
cog.outl(" : imessage_router(id_)")
cog.outl(" {")
cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)")
cog.outl(" : imessage_router(id_, successor_)")
cog.outl(" {")
cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" message_router()")
cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER)")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" message_router(etl::imessage_router& successor_)")
cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)")
cog.outl(" {")
cog.outl(" }")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" using etl::imessage_router::receive;")
cog.outl("")
cog.outl(" void receive(const etl::imessage& msg) ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" const etl::message_id_t id = msg.get_message_id();")
cog.outl("")
cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
cog.outl(" switch (id)")
cog.outl(" {")
for t in range(1, n + 1):
cog.out(" case T%d::ID:" % t)
cog.out(" static_cast<TDerived*>(this)->on_receive(static_cast<const T%d&>(msg));" % t)
cog.outl(" break;")
cog.outl(" default:")
cog.outl(" {")
cog.outl(" if (has_successor())")
cog.outl(" {")
cog.outl(" get_successor().receive(msg);")
cog.outl(" }")
cog.outl(" else")
cog.outl(" {")
cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
cog.outl(" }")
cog.outl(" break;")
cog.outl(" }")
cog.outl(" }")
cog.outl("#include \"etl/private/diagnostic_pop.h\"")
cog.outl(" }")
cog.outl("")
cog.outl(" template <typename TMessage>")
cog.out(" typename etl::enable_if<etl::is_message<TMessage>::value && etl::is_one_of<TMessage, ")
for t in range(1, n):
cog.out("T%s, " % t)
cog.outl("T%s>::value, void>::type" % n)
cog.outl(" receive(const TMessage& msg)")
cog.outl(" {")
cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
cog.outl(" static_cast<TDerived*>(this)->on_receive(msg);")
cog.outl("#include \"etl/private/diagnostic_pop.h\"")
cog.outl(" }")
cog.outl("")
cog.outl(" template <typename TMessage>")
cog.out(" typename etl::enable_if<etl::is_message<TMessage>::value && !etl::is_one_of<TMessage, ")
for t in range(1, n):
cog.out("T%s, " % t)
cog.outl("T%s>::value, void>::type" % n)
cog.outl(" receive(const TMessage& msg)")
cog.outl(" {")
cog.outl(" if (has_successor())")
cog.outl(" {")
cog.outl(" get_successor().receive(msg);")
cog.outl(" }")
cog.outl(" else")
cog.outl(" {")
cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
cog.outl("#include \"etl/private/diagnostic_pop.h\"")
cog.outl(" }")
cog.outl(" }")
cog.outl("")
cog.outl("")
cog.outl(" //**********************************************")
cog.outl(" using imessage_router::accepts;")
cog.outl("")
cog.outl(" bool accepts(etl::message_id_t id) const ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" switch (id)")
cog.outl(" {")
cog.out(" ")
for t in range(1, n + 1):
cog.out(" case T%d::ID:" % t)
if t % 8 == 0:
cog.outl("")
if t != n:
cog.out(" ")
cog.outl("")
cog.outl(" return true;")
cog.outl(" default:")
cog.outl(" {")
cog.outl(" if (has_successor())")
cog.outl(" {")
cog.outl(" return get_successor().accepts(id);")
cog.outl(" }")
cog.outl(" else")
cog.outl(" {")
cog.outl(" return false;")
cog.outl(" }")
cog.outl(" }")
cog.outl(" }")
cog.outl(" }")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" return false;")
cog.outl(" }")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" bool is_producer() const ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" return true;")
cog.outl(" }")
cog.outl("")
cog.outl(" //********************************************")
cog.outl(" bool is_consumer() const ETL_OVERRIDE")
cog.outl(" {")
cog.outl(" return true;")
cog.outl(" }")
cog.outl("};")
]]]*/
/*[[[end]]]*/
//***************************************************************************
// Specialisation for 0 message types.
//***************************************************************************
template <typename TDerived>
class message_router<TDerived, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void>
: public imessage_router
{
public:
typedef etl::message_packet<> message_packet;
#if ETL_USING_CPP11
using message_types = etl::type_list<>;
#endif
//**********************************************
message_router(etl::message_router_id_t id_)
: imessage_router(id_)
{
ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
}
//**********************************************
message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)
: imessage_router(id_, successor_)
{
ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
}
//**********************************************
message_router()
: imessage_router(etl::imessage_router::MESSAGE_ROUTER)
{
}
//**********************************************
message_router(etl::imessage_router& successor_)
: imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
{
}
//**********************************************
using etl::imessage_router::receive;
void receive(const etl::imessage& msg) ETL_OVERRIDE
{
#include "etl/private/diagnostic_array_bounds_push.h"
if (has_successor())
{
get_successor().receive(msg);
}
#include "etl/private/diagnostic_pop.h"
}
//**********************************************
using imessage_router::accepts;
bool accepts(etl::message_id_t id) const ETL_OVERRIDE
{
if (has_successor())
{
return get_successor().accepts(id);
}
else
{
return false;
}
}
//********************************************
ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
{
return false;
}
//********************************************
bool is_producer() const ETL_OVERRIDE
{
return true;
}
//********************************************
bool is_consumer() const ETL_OVERRIDE
{
return true;
}
};
etl::imessage_router
This is the base of all message routers.
Definition message_router.h:141
etl::imessage
Definition message.h:73
etl::message_packet
Definition message_packet.h:42
etl::message_router_illegal_id
Router id is out of the legal range.
Definition message_router.h:67
diagnostic_array_bounds_push.h
diagnostic_pop.h
ETL_ASSERT
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
etl::message_id_t
uint_least8_t message_id_t
Allow alternative type for message id.
Definition message_types.h:40