mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-28 21:38:44 +08:00
Merge branch 'feature/extract_message_packet' into development
This commit is contained in:
commit
c508dd5b4f
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,9 +9,12 @@ test/keil/Debug
|
||||
test/keil/Release
|
||||
test/keil/Objects
|
||||
test/keil/Listings
|
||||
test/cmake-windows/unittest++/src
|
||||
test/cmake/unittest++/src
|
||||
examples/ArmTimerCallbacks/Listings
|
||||
examples/ArmTimerCallbacks/Objects
|
||||
examples/ArmTimerCallbacks/DebugConfig
|
||||
build-test-Desktop_x86_windows_msvc2017_pe_32bit-Debug/unittest++/src
|
||||
|
||||
#################
|
||||
## Eclipse
|
||||
|
||||
@ -52,3 +52,4 @@
|
||||
52 bitset
|
||||
53 indirect_vector
|
||||
54 queue_spsc_locked
|
||||
55 message_packet
|
||||
|
||||
@ -4,4 +4,5 @@ python -m cogapp -d -e -olargest.h -DNTypes=16 largest_generator.h
|
||||
python -m cogapp -d -e -osmallest.h -DNTypes=16 smallest_generator.h
|
||||
python -m cogapp -d -e -otype_traits.h -DIsOneOf=17 type_traits_generator.h
|
||||
python -m cogapp -d -e -otype_lookup.h -DNTypes=16 type_lookup_generator.h
|
||||
python -m cogapp -d -e -otype_select.h -DNTypes=16 type_select_generator.h
|
||||
python -m cogapp -d -e -otype_select.h -DNTypes=16 type_select_generator.h
|
||||
python -m cogapp -d -e -omessage_packet.h -DHandlers=16 message_packet_generator.h
|
||||
1
include/etl/generate_message_packet.bat
Normal file
1
include/etl/generate_message_packet.bat
Normal file
@ -0,0 +1 @@
|
||||
python -m cogapp -d -e -omessage_packet.h -DHandlers=16 message_packet_generator.h
|
||||
1614
include/etl/message_packet.h
Normal file
1614
include/etl/message_packet.h
Normal file
File diff suppressed because it is too large
Load Diff
309
include/etl/message_packet_generator.h
Normal file
309
include/etl/message_packet_generator.h
Normal file
@ -0,0 +1,309 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2020 jwellbelove
|
||||
|
||||
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.
|
||||
******************************************************************************/
|
||||
|
||||
/*[[[cog
|
||||
import cog
|
||||
cog.outl("#if 0")
|
||||
]]]*/
|
||||
/*[[[end]]]*/
|
||||
#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
|
||||
/*[[[cog
|
||||
import cog
|
||||
cog.outl("#endif")
|
||||
]]]*/
|
||||
/*[[[end]]]*/
|
||||
|
||||
/*[[[cog
|
||||
import cog
|
||||
cog.outl("//***************************************************************************")
|
||||
cog.outl("// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.")
|
||||
cog.outl("//***************************************************************************")
|
||||
]]]*/
|
||||
/*[[[end]]]*/
|
||||
|
||||
//***************************************************************************
|
||||
// To generate to header file, run this at the command line.
|
||||
// Note: You will need Python and COG installed.
|
||||
//
|
||||
// python -m cogapp -d -e -omessage_packet.h -DHandlers=<n> message_packet_generator.h
|
||||
// Where <n> is the number of messages to support.
|
||||
//
|
||||
// e.g.
|
||||
// To generate handlers for up to 16 messages...
|
||||
// python -m cogapp -d -e -omessage_packet.h -DHandlers=16 message_packet_generator.h
|
||||
//
|
||||
// See generate.bat
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef ETL_MESSAGE_PACKET_INCLUDED
|
||||
#define ETL_MESSAGE_PACKET_INCLUDED
|
||||
|
||||
#include "message.h"
|
||||
#include "error_handler.h"
|
||||
#include "static_assert.h"
|
||||
#include "largest.h"
|
||||
#include "alignment.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#undef ETL_FILE
|
||||
#define ETL_FILE "55"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
/*[[[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.out("template <")
|
||||
cog.out("typename T1, ")
|
||||
for n in range(2, int(Handlers)):
|
||||
cog.out("typename T%s = void, " % n)
|
||||
if n % 4 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("typename T%s = void>" % int(Handlers))
|
||||
cog.outl("class message_packet")
|
||||
cog.outl("{")
|
||||
cog.outl("public:")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" explicit message_packet(const etl::imessage& msg)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" const size_t id = msg.message_id;")
|
||||
cog.outl("")
|
||||
cog.outl(" void* p = data;")
|
||||
cog.outl("")
|
||||
cog.outl(" switch (id)")
|
||||
cog.outl(" {")
|
||||
for n in range(1, int(Handlers) + 1):
|
||||
cog.out(" case T%d::ID:" %n)
|
||||
cog.out(" ::new (p) T%d(static_cast<const T%d&>(msg));" % (n, n))
|
||||
cog.outl(" break;")
|
||||
cog.outl(" default: default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;")
|
||||
cog.outl(" }")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" template <typename T>")
|
||||
cog.outl(" explicit message_packet(const T& msg)")
|
||||
cog.outl(" {")
|
||||
cog.out(" ETL_STATIC_ASSERT((etl::is_one_of<T, ")
|
||||
for n in range(1, int(Handlers)):
|
||||
cog.out("T%d, " % n)
|
||||
cog.outl("T%s>::value), \"Unsupported type for this message packet\");" % int(Handlers))
|
||||
cog.outl("")
|
||||
cog.outl(" void* p = data;")
|
||||
cog.outl(" ::new (p) T(static_cast<const T&>(msg));")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" ~message_packet()")
|
||||
cog.outl(" {")
|
||||
cog.outl(" etl::imessage* pmsg = static_cast<etl::imessage*>(data);")
|
||||
cog.outl("")
|
||||
cog.outl("#if defined(ETL_MESSAGES_ARE_VIRTUAL) || defined(ETL_POLYMORPHIC_MESSAGES)")
|
||||
cog.outl(" pmsg->~imessage();")
|
||||
cog.outl("#else")
|
||||
cog.outl(" size_t id = pmsg->message_id;")
|
||||
cog.outl("")
|
||||
cog.outl(" switch (id)")
|
||||
cog.outl(" {")
|
||||
for n in range(1, int(Handlers) + 1):
|
||||
cog.outl(" case T%s::ID: static_cast<T%s*>(pmsg)->~T%s(); break;" % (n, n, n))
|
||||
cog.outl(" default: assert(false); break;")
|
||||
cog.outl(" }")
|
||||
cog.outl("#endif")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" etl::imessage& get() ETL_NOEXCEPT")
|
||||
cog.outl(" {")
|
||||
cog.outl(" return *static_cast<etl::imessage*>(data);")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" const etl::imessage& get() const ETL_NOEXCEPT")
|
||||
cog.outl(" {")
|
||||
cog.outl(" return *static_cast<const etl::imessage*>(data);")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" enum")
|
||||
cog.outl(" {")
|
||||
cog.out(" SIZE = etl::largest<")
|
||||
for n in range(1, int(Handlers)):
|
||||
cog.out("T%d, " % n)
|
||||
cog.outl("T%s>::size," % int(Handlers))
|
||||
cog.out(" ALIGNMENT = etl::largest<")
|
||||
for n in range(1, int(Handlers)):
|
||||
cog.out("T%d, " % n)
|
||||
cog.outl("T%s>::alignment" % int(Handlers))
|
||||
cog.outl(" };")
|
||||
cog.outl("")
|
||||
cog.outl("private:")
|
||||
cog.outl("")
|
||||
cog.outl(" typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;")
|
||||
cog.outl("")
|
||||
cog.outl(" message_packet(const message_packet&) ETL_DELETE;")
|
||||
cog.outl(" message_packet& operator =(const message_packet&) ETL_DELETE;")
|
||||
cog.outl("#if ETL_CPP11_SUPPORTED")
|
||||
cog.outl(" message_packet(message_packet&&) ETL_DELETE;")
|
||||
cog.outl(" message_packet& operator =(message_packet&&) ETL_DELETE;")
|
||||
cog.outl("#endif")
|
||||
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.out("template <")
|
||||
for t in range(1, n):
|
||||
cog.out("typename T%s, " % t)
|
||||
if t % 4 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("typename T%s>" % n)
|
||||
cog.out("class message_packet<")
|
||||
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("{")
|
||||
cog.outl("public:")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" explicit message_packet(const etl::imessage& msg)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" const size_t id = msg.message_id;")
|
||||
cog.outl("")
|
||||
cog.outl(" void* p = data;")
|
||||
cog.outl("")
|
||||
cog.outl(" switch (id)")
|
||||
cog.outl(" {")
|
||||
for t in range(1, n + 1):
|
||||
cog.out(" case T%d::ID:" %t)
|
||||
cog.out(" ::new (p) T%d(static_cast<const T%d&>(msg));" % (t, t))
|
||||
cog.outl(" break;")
|
||||
cog.outl(" default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;")
|
||||
cog.outl(" }")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" template <typename T>")
|
||||
cog.outl(" explicit message_packet(const T& msg)")
|
||||
cog.outl(" {")
|
||||
cog.out(" ETL_STATIC_ASSERT((etl::is_one_of<T, ")
|
||||
for t in range(1, n):
|
||||
cog.out("T%d, " % t)
|
||||
cog.outl("T%s>::value), \"Unsupported type for this message packet\");" % n)
|
||||
cog.outl("")
|
||||
cog.outl(" void* p = data;")
|
||||
cog.outl(" ::new (p) T(static_cast<const T&>(msg));")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" ~message_packet()")
|
||||
cog.outl(" {")
|
||||
cog.outl(" etl::imessage* pmsg = static_cast<etl::imessage*>(data);")
|
||||
cog.outl("")
|
||||
cog.outl("#if defined(ETL_MESSAGES_ARE_VIRTUAL) || defined(ETL_POLYMORPHIC_MESSAGES)")
|
||||
cog.outl(" pmsg->~imessage();")
|
||||
cog.outl("#else")
|
||||
cog.outl(" size_t id = pmsg->message_id;")
|
||||
cog.outl("")
|
||||
cog.outl(" switch (id)")
|
||||
cog.outl(" {")
|
||||
for t in range(1, n + 1):
|
||||
cog.outl(" case T%s::ID: static_cast<T%s*>(pmsg)->~T%s(); break;" % (t, t, t))
|
||||
cog.outl(" default: assert(false); break;")
|
||||
cog.outl(" }")
|
||||
cog.outl("#endif")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" etl::imessage& get() ETL_NOEXCEPT")
|
||||
cog.outl(" {")
|
||||
cog.outl(" return *static_cast<etl::imessage*>(data);")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" const etl::imessage& get() const ETL_NOEXCEPT")
|
||||
cog.outl(" {")
|
||||
cog.outl(" return *static_cast<const etl::imessage*>(data);")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" enum")
|
||||
cog.outl(" {")
|
||||
cog.out(" SIZE = etl::largest<")
|
||||
for t in range(1, n):
|
||||
cog.out("T%d, " % t)
|
||||
cog.outl("T%s>::size," % n)
|
||||
cog.out(" ALIGNMENT = etl::largest<")
|
||||
for t in range(1, n):
|
||||
cog.out("T%d, " % t)
|
||||
cog.outl("T%s>::alignment" % n)
|
||||
cog.outl(" };")
|
||||
cog.outl("")
|
||||
cog.outl("private:")
|
||||
cog.outl("")
|
||||
cog.outl(" typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;")
|
||||
cog.outl("")
|
||||
cog.outl(" message_packet(const message_packet&) ETL_DELETE;")
|
||||
cog.outl(" message_packet& operator =(const message_packet&) ETL_DELETE;")
|
||||
cog.outl("#if ETL_CPP11_SUPPORTED")
|
||||
cog.outl(" message_packet(message_packet&&) ETL_DELETE;")
|
||||
cog.outl(" message_packet& operator =(message_packet&&) ETL_DELETE;")
|
||||
cog.outl("#endif")
|
||||
cog.outl("};")
|
||||
]]]*/
|
||||
/*[[[end]]]*/
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@ -68,6 +68,7 @@ cog.outl("//********************************************************************
|
||||
|
||||
#include "platform.h"
|
||||
#include "message.h"
|
||||
#include "message_packet.h"
|
||||
#include "message_types.h"
|
||||
#include "alignment.h"
|
||||
#include "error_handler.h"
|
||||
@ -272,89 +273,10 @@ namespace etl
|
||||
cog.outl("{")
|
||||
cog.outl("public:")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" class message_packet")
|
||||
cog.outl(" {")
|
||||
cog.outl(" public:")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" explicit message_packet(const etl::imessage& msg)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" const size_t id = msg.message_id;")
|
||||
cog.outl("")
|
||||
cog.outl(" void* p = data;")
|
||||
cog.outl("")
|
||||
cog.outl(" switch (id)")
|
||||
cog.outl(" {")
|
||||
for n in range(1, int(Handlers) + 1):
|
||||
cog.outl(" case T%s::ID: ::new (p) T%s(static_cast<const T%s&>(msg)); break;" % (n, n, n))
|
||||
cog.outl(" default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;")
|
||||
cog.outl(" }")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" template <typename T>")
|
||||
cog.outl(" explicit message_packet(const T& msg)")
|
||||
cog.outl(" {")
|
||||
cog.out(" ETL_STATIC_ASSERT((etl::is_one_of<T, ")
|
||||
cog.out(" typedef etl::message_packet<")
|
||||
for n in range(1, int(Handlers)):
|
||||
cog.out("T%s, " % n)
|
||||
if n % 16 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("""T%s>::value), "Unsupported type for this message packet");""" % int(Handlers))
|
||||
cog.outl("")
|
||||
cog.outl(" void* p = data;")
|
||||
cog.outl(" ::new (p) T(static_cast<const T&>(msg));")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" ~message_packet()")
|
||||
cog.outl(" {")
|
||||
cog.outl(" etl::imessage* pmsg = static_cast<etl::imessage*>(data);")
|
||||
cog.outl("")
|
||||
cog.outl("#if defined(ETL_MESSAGES_ARE_VIRTUAL) || defined(ETL_POLYMORPHIC_MESSAGES)")
|
||||
cog.outl(" pmsg->~imessage();")
|
||||
cog.outl("#else")
|
||||
cog.outl(" size_t id = pmsg->message_id;")
|
||||
cog.outl("")
|
||||
cog.outl(" switch (id)")
|
||||
cog.outl(" {")
|
||||
for n in range(1, int(Handlers) + 1):
|
||||
cog.outl(" case T%s::ID: static_cast<T%s*>(pmsg)->~T%s(); break;" % (n, n, n))
|
||||
cog.outl(" default: assert(false); break;")
|
||||
cog.outl(" }")
|
||||
cog.outl("#endif")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" etl::imessage& get()")
|
||||
cog.outl(" {")
|
||||
cog.outl(" return *static_cast<etl::imessage*>(data);")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" const etl::imessage& get() const")
|
||||
cog.outl(" {")
|
||||
cog.outl(" return *static_cast<const etl::imessage*>(data);")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" enum")
|
||||
cog.outl(" {")
|
||||
cog.out(" SIZE = etl::largest<")
|
||||
for n in range(1, int(Handlers)):
|
||||
cog.out("T%s, " % n)
|
||||
cog.outl("T%s>::size," % int(Handlers))
|
||||
cog.out(" ALIGNMENT = etl::largest<")
|
||||
for n in range(1, int(Handlers)):
|
||||
cog.out("T%s, " % n)
|
||||
cog.outl("T%s>::alignment" % int(Handlers))
|
||||
cog.outl(" };")
|
||||
cog.outl("")
|
||||
cog.outl(" private:")
|
||||
cog.outl("")
|
||||
cog.outl(" typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;")
|
||||
cog.outl(" };")
|
||||
cog.outl(" T%s> message_packet;" % int(Handlers))
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" message_router(etl::message_router_id_t id_)")
|
||||
@ -472,89 +394,10 @@ namespace etl
|
||||
cog.outl("{")
|
||||
cog.outl("public:")
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" class message_packet")
|
||||
cog.outl(" {")
|
||||
cog.outl(" public:")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" explicit message_packet(const etl::imessage& msg)")
|
||||
cog.outl(" {")
|
||||
cog.outl(" const size_t id = msg.message_id;")
|
||||
cog.outl("")
|
||||
cog.outl(" void* p = data;")
|
||||
cog.outl("")
|
||||
cog.outl(" switch (id)")
|
||||
cog.outl(" {")
|
||||
for t in range(1, n + 1):
|
||||
cog.outl(" case T%s::ID: ::new (p) T%s(static_cast<const T%s&>(msg)); break;" % (t, t, t))
|
||||
cog.outl(" default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;")
|
||||
cog.outl(" }")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" template <typename T>")
|
||||
cog.outl(" explicit message_packet(const T& msg)")
|
||||
cog.outl(" {")
|
||||
cog.out(" ETL_STATIC_ASSERT((etl::is_one_of<T, ")
|
||||
cog.out(" typedef etl::message_packet<")
|
||||
for t in range(1, n):
|
||||
cog.out("T%s, " % t)
|
||||
if t % 16 == 0:
|
||||
cog.outl("")
|
||||
cog.out(" ")
|
||||
cog.outl("""T%s>::value), "Unsupported type for this message packet");""" % n)
|
||||
cog.outl("")
|
||||
cog.outl(" void* p = data;")
|
||||
cog.outl(" ::new (p) T(static_cast<const T&>(msg));")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" ~message_packet()")
|
||||
cog.outl(" {")
|
||||
cog.outl(" etl::imessage* pmsg = static_cast<etl::imessage*>(data);")
|
||||
cog.outl("")
|
||||
cog.outl("#if defined(ETL_MESSAGES_ARE_VIRTUAL) || defined(ETL_POLYMORPHIC_MESSAGES)")
|
||||
cog.outl(" pmsg->~imessage();")
|
||||
cog.outl("#else")
|
||||
cog.outl(" size_t id = pmsg->message_id;")
|
||||
cog.outl("")
|
||||
cog.outl(" switch (id)")
|
||||
cog.outl(" {")
|
||||
for t in range(1, n + 1):
|
||||
cog.outl(" case T%s::ID: static_cast<T%s*>(pmsg)->~T%s(); break;" % (t, t, t))
|
||||
cog.outl(" default: assert(false); break;")
|
||||
cog.outl(" }")
|
||||
cog.outl("#endif")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" etl::imessage& get()")
|
||||
cog.outl(" {")
|
||||
cog.outl(" return *static_cast<etl::imessage*>(data);")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" //********************************************")
|
||||
cog.outl(" const etl::imessage& get() const")
|
||||
cog.outl(" {")
|
||||
cog.outl(" return *static_cast<const etl::imessage*>(data);")
|
||||
cog.outl(" }")
|
||||
cog.outl("")
|
||||
cog.outl(" enum")
|
||||
cog.outl(" {")
|
||||
cog.out(" SIZE = etl::largest<")
|
||||
for t in range(1, n):
|
||||
cog.out("T%s, " % t)
|
||||
cog.outl("T%s>::size," % n)
|
||||
cog.out(" ALIGNMENT = etl::largest<")
|
||||
for t in range(1, n):
|
||||
cog.out("T%s, " % t)
|
||||
cog.outl("T%s>::alignment" % n)
|
||||
cog.outl(" };")
|
||||
cog.outl("")
|
||||
cog.outl(" private:")
|
||||
cog.outl("")
|
||||
cog.outl(" typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;")
|
||||
cog.outl(" };")
|
||||
cog.outl(" T%s> message_packet;" % n)
|
||||
cog.outl("")
|
||||
cog.outl(" //**********************************************")
|
||||
cog.outl(" message_router(etl::message_router_id_t id_)")
|
||||
|
||||
@ -72,6 +72,7 @@ SOFTWARE.
|
||||
#define ETL_CONST_OR_CONSTEXPR constexpr
|
||||
#define ETL_DELETE = delete
|
||||
#define ETL_EXPLICIT explicit
|
||||
#define ETL_OVERRIDE override
|
||||
#if defined(ETL_EXCEPTIONS_DISABLED)
|
||||
#define ETL_NOEXCEPT
|
||||
#define ETL_NOEXCEPT_EXPR(expression)
|
||||
@ -84,6 +85,7 @@ SOFTWARE.
|
||||
#define ETL_CONST_OR_CONSTEXPR const
|
||||
#define ETL_DELETE
|
||||
#define ETL_EXPLICIT
|
||||
#define ETL_OVERRIDE
|
||||
#define ETL_NOEXCEPT
|
||||
#define ETL_NOEXCEPT_EXPR(expression)
|
||||
#endif
|
||||
|
||||
@ -38,8 +38,8 @@ SOFTWARE.
|
||||
///\ingroup utilities
|
||||
|
||||
#define ETL_VERSION_MAJOR 16
|
||||
#define ETL_VERSION_MINOR 7
|
||||
#define ETL_VERSION_PATCH 1
|
||||
#define ETL_VERSION_MINOR 8
|
||||
#define ETL_VERSION_PATCH 0
|
||||
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH)
|
||||
#define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH)
|
||||
#define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library",
|
||||
"version": "16.7.1",
|
||||
"version": "16.8.0",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library
|
||||
version=16.7.1
|
||||
version=16.8.0
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
===============================================================================
|
||||
16.8.0
|
||||
Extracted message_packet from etl::message_router for use as an independant class.
|
||||
|
||||
===============================================================================
|
||||
16.7.1
|
||||
Fix C++03 compatibility issues in memory.h and utility.h
|
||||
|
||||
158
test/test_message_packet.cpp
Normal file
158
test/test_message_packet.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
http://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2020 jwellbelove
|
||||
|
||||
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.
|
||||
******************************************************************************/
|
||||
|
||||
#include "UnitTest++/UnitTest++.h"
|
||||
#include "ExtraCheckMacros.h"
|
||||
|
||||
#include "etl/message_packet.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
//***************************************************************************
|
||||
// The set of messages.
|
||||
//***************************************************************************
|
||||
namespace
|
||||
{
|
||||
enum
|
||||
{
|
||||
MESSAGE1,
|
||||
MESSAGE2,
|
||||
MESSAGE3,
|
||||
MESSAGE4
|
||||
};
|
||||
|
||||
struct Message1 : public etl::message<MESSAGE1>
|
||||
{
|
||||
Message1(int x_)
|
||||
: x(x_)
|
||||
{
|
||||
}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
struct Message2 : public etl::message<MESSAGE2>
|
||||
{
|
||||
Message2(double x_)
|
||||
: x(x_)
|
||||
{
|
||||
}
|
||||
|
||||
double x;
|
||||
};
|
||||
|
||||
struct Message3 : public etl::message<MESSAGE3>
|
||||
{
|
||||
Message3(std::string x_)
|
||||
: x(x_)
|
||||
{
|
||||
}
|
||||
|
||||
std::string x;
|
||||
};
|
||||
|
||||
struct Message4 : public etl::message<MESSAGE4>
|
||||
{
|
||||
};
|
||||
|
||||
using Packet = etl::message_packet<Message1, Message2, Message3>;
|
||||
|
||||
SUITE(test_message_packet)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(message_packet_construction)
|
||||
{
|
||||
Message1 message1(1);
|
||||
Message2 message2(2.2);
|
||||
Message3 message3("3");
|
||||
Message4 message4;
|
||||
|
||||
Packet packet1(message1);
|
||||
Packet packet2(message2);
|
||||
Packet packet3(message3);
|
||||
|
||||
// The next line should result in a compile error.
|
||||
//Packet packet4(message4);
|
||||
|
||||
CHECK_EQUAL(MESSAGE1, packet1.get().message_id);
|
||||
CHECK_EQUAL(MESSAGE2, packet2.get().message_id);
|
||||
CHECK_EQUAL(MESSAGE3, packet3.get().message_id);
|
||||
|
||||
CHECK_EQUAL(1, static_cast<Message1&>(packet1.get()).x);
|
||||
CHECK_EQUAL(2.2, static_cast<Message2&>(packet2.get()).x);
|
||||
CHECK_EQUAL("3", static_cast<Message3&>(packet3.get()).x);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(message_constant_packet_construction)
|
||||
{
|
||||
Message1 message1(1);
|
||||
Message2 message2(2.2);
|
||||
Message3 message3("3");
|
||||
Message4 message4;
|
||||
|
||||
const Packet packet1(message1);
|
||||
const Packet packet2(message2);
|
||||
const Packet packet3(message3);
|
||||
|
||||
// The next line should result in a compile error.
|
||||
//Packet packet4(message4);
|
||||
|
||||
CHECK_EQUAL(MESSAGE1, packet1.get().message_id);
|
||||
CHECK_EQUAL(MESSAGE2, packet2.get().message_id);
|
||||
CHECK_EQUAL(MESSAGE3, packet3.get().message_id);
|
||||
|
||||
CHECK_EQUAL(1, static_cast<const Message1&>(packet1.get()).x);
|
||||
CHECK_EQUAL(2.2, static_cast<const Message2&>(packet2.get()).x);
|
||||
CHECK_EQUAL("3", static_cast<const Message3&>(packet3.get()).x);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(message_packet_construction_from_base)
|
||||
{
|
||||
Message1 message1(1);
|
||||
Message2 message2(2.2);
|
||||
Message3 message3("3");
|
||||
Message4 message4;
|
||||
|
||||
Packet packet1(static_cast<etl::imessage&>(message1));
|
||||
Packet packet2(static_cast<etl::imessage&>(message2));
|
||||
Packet packet3(static_cast<etl::imessage&>(message3));
|
||||
|
||||
CHECK_THROW(Packet packet4(static_cast<etl::imessage&>(message4)), etl::unhandled_message_exception);
|
||||
|
||||
CHECK_EQUAL(MESSAGE1, packet1.get().message_id);
|
||||
CHECK_EQUAL(MESSAGE2, packet2.get().message_id);
|
||||
CHECK_EQUAL(MESSAGE3, packet3.get().message_id);
|
||||
|
||||
CHECK_EQUAL(1, static_cast<Message1&>(packet1.get()).x);
|
||||
CHECK_EQUAL(2.2, static_cast<Message2&>(packet2.get()).x);
|
||||
CHECK_EQUAL("3", static_cast<Message3&>(packet3.get()).x);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -32,7 +32,6 @@ SOFTWARE.
|
||||
#include "etl/message_router.h"
|
||||
#include "etl/queue.h"
|
||||
#include "etl/largest.h"
|
||||
#include "etl/packet.h"
|
||||
|
||||
//***************************************************************************
|
||||
// The set of messages.
|
||||
|
||||
@ -888,6 +888,9 @@
|
||||
<ClInclude Include="..\..\include\etl\absolute.h" />
|
||||
<ClInclude Include="..\..\include\etl\limits.h" />
|
||||
<ClInclude Include="..\..\include\etl\macros.h" />
|
||||
<ClInclude Include="..\..\include\etl\message_packet temp.h" />
|
||||
<ClInclude Include="..\..\include\etl\message_packet.h" />
|
||||
<ClInclude Include="..\..\include\etl\message_packet_generator.h" />
|
||||
<ClInclude Include="..\..\include\etl\multi_array.h" />
|
||||
<ClInclude Include="..\..\include\etl\mutex\mutex_freertos.h" />
|
||||
<ClInclude Include="..\..\include\etl\negative.h" />
|
||||
@ -1106,6 +1109,7 @@
|
||||
<ClCompile Include="..\test_limits.cpp" />
|
||||
<ClCompile Include="..\test_list_shared_pool.cpp" />
|
||||
<ClCompile Include="..\test_make_string.cpp" />
|
||||
<ClCompile Include="..\test_message_packet.cpp" />
|
||||
<ClCompile Include="..\test_multi_array.cpp" />
|
||||
<ClCompile Include="..\test_array.cpp">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../../unittest-cpp</AdditionalIncludeDirectories>
|
||||
@ -1442,6 +1446,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="..\..\etl.pspimage" />
|
||||
<None Include="..\..\etl.xar" />
|
||||
<None Include="..\..\include\etl\generate_message_packet.bat" />
|
||||
<None Include="..\..\include\etl\generate_type_select.bat" />
|
||||
<None Include="..\..\library.json" />
|
||||
<None Include="..\..\library.properties" />
|
||||
|
||||
@ -822,6 +822,15 @@
|
||||
<ClInclude Include="..\..\include\etl\mutex\mutex_freertos.h">
|
||||
<Filter>ETL\Utilities\Mutex</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\message_packet_generator.h">
|
||||
<Filter>ETL\Frameworks\Generators</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\message_packet temp.h">
|
||||
<Filter>ETL\Frameworks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\message_packet.h">
|
||||
<Filter>ETL\Frameworks</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\main.cpp">
|
||||
@ -1277,6 +1286,9 @@
|
||||
<ClCompile Include="..\test_parity_checksum.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_message_packet.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
@ -1324,6 +1336,9 @@
|
||||
<None Include="cpp.hint">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include="..\..\include\etl\generate_message_packet.bat">
|
||||
<Filter>Resource Files\Generators</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\..\include\etl\file_error_numbers.txt">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user