/****************************************************************************** The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com Copyright(c) 2020 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. ******************************************************************************/ #if 0 #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. #endif //*************************************************************************** // THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE. //*************************************************************************** //*************************************************************************** // 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= message_packet_generator.h // Where 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 "platform.h" #if ETL_HAS_VIRTUAL_MESSAGES #include "message.h" #include "error_handler.h" #include "static_assert.h" #include "largest.h" #include "alignment.h" #include "utility.h" #include namespace etl { #if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** // The definition for all message types. //*************************************************************************** template class message_packet { private: template static constexpr bool IsMessagePacket = etl::is_same_v< etl::remove_const_t>, etl::message_packet>; template static constexpr bool IsInMessageList = etl::is_one_of_v>, TMessageTypes...>; template static constexpr bool IsIMessage = etl::is_same_v>, etl::imessage>; public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** /// //******************************************** #include "private/diagnostic_uninitialized_push.h" template || IsInMessageList, int>::type> explicit message_packet(T&& msg) : valid(true) { if constexpr (IsIMessage) { if (accepts(msg)) { add_new_message(etl::forward(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } else if constexpr (IsInMessageList) { add_new_message_type(etl::forward(msg)); } else { ETL_STATIC_ASSERT(IsInMessageList, "Message not in packet type list"); } } #include "private/diagnostic_pop.h" //********************************************** message_packet(const message_packet& other) { valid = other.is_valid(); if (valid) { add_new_message(other.get()); } } #if ETL_USING_CPP11 //********************************************** message_packet(message_packet&& other) { valid = other.is_valid(); if (valid) { add_new_message(etl::move(other.get())); } } #endif //********************************************** void copy(const message_packet& other) { valid = other.is_valid(); if (valid) { add_new_message(other.get()); } } //********************************************** void copy(message_packet&& other) { valid = other.is_valid(); if (valid) { add_new_message(etl::move(other.get())); } } //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return (accepts_message(id) || ...); } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return (accepts_message() || ...); } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return accepts(); } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //********************************************** template static bool accepts_message() { return Id1 == Id2; } //********************************************** template static bool accepts_message(etl::message_id_t id2) { return Id1 == id2; } //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { (add_new_message_type(msg) || ...); } //******************************************** void add_new_message(etl::imessage&& msg) { (add_new_message_type(etl::move(msg)) || ...); } #include "private/diagnostic_uninitialized_push.h" //******************************************** /// Only enabled for types that are in the typelist. //******************************************** template etl::enable_if_t>, TMessageTypes...>, void> add_new_message_type(TMessage&& msg) { void* p = data; new (p) etl::remove_reference_t((etl::forward(msg))); } #include "private/diagnostic_pop.h" #include "private/diagnostic_uninitialized_push.h" //******************************************** template bool add_new_message_type(const etl::imessage& msg) { if (TType::ID == msg.get_message_id()) { void* p = data; new (p) TType(static_cast(msg)); return true; } else { return false; } } #include "private/diagnostic_pop.h" //******************************************** template bool add_new_message_type(etl::imessage&& msg) { if (TType::ID == msg.get_message_id()) { void* p = data; new (p) TType(static_cast(msg)); return true; } else { return false; } } typename etl::aligned_storage::type data; bool valid; }; #else //*************************************************************************** // The definition for all 16 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id || T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id || T13::ID == id || T14::ID == id || T15::ID == id || T16::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id || T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id || T13::ID == Id || T14::ID == Id || T15::ID == Id || T16::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID || T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID || T13::ID == TMessage::ID || T14::ID == TMessage::ID || T15::ID == TMessage::ID || T16::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; case T14::ID: ::new (p) T14(static_cast(msg)); break; case T15::ID: ::new (p) T15(static_cast(msg)); break; case T16::ID: ::new (p) T16(static_cast(msg)); break; default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; case T14::ID: ::new (p) T14(static_cast(msg)); break; case T15::ID: ::new (p) T15(static_cast(msg)); break; case T16::ID: ::new (p) T16(static_cast(msg)); break; default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 15 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id || T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id || T13::ID == id || T14::ID == id || T15::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id || T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id || T13::ID == Id || T14::ID == Id || T15::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID || T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID || T13::ID == TMessage::ID || T14::ID == TMessage::ID || T15::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; case T14::ID: ::new (p) T14(static_cast(msg)); break; case T15::ID: ::new (p) T15(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; case T14::ID: ::new (p) T14(static_cast(msg)); break; case T15::ID: ::new (p) T15(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 14 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id || T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id || T13::ID == id || T14::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id || T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id || T13::ID == Id || T14::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID || T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID || T13::ID == TMessage::ID || T14::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; case T14::ID: ::new (p) T14(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; case T14::ID: ::new (p) T14(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 13 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id || T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id || T13::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id || T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id || T13::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID || T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID || T13::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 12 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id || T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id || T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID || T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 11 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id || T9::ID == id || T10::ID == id || T11::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id || T9::ID == Id || T10::ID == Id || T11::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID || T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 10 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id || T9::ID == id || T10::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id || T9::ID == Id || T10::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID || T9::ID == TMessage::ID || T10::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 9 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8, T9>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8, T9>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id || T9::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id || T9::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID || T9::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 8 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7, T8>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7, T8>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 7 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6, T7>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6, T7>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id || T7::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id || T7::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 6 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5, T6>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5, T6>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id || T6::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id || T6::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID || T6::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 5 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4, T5>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4, T5>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id || T5::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id || T5::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID || T5::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 4 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3, T4>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3, T4>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 3 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2, T3>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2, T3>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id || T3::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id || T3::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 2 message types. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1, T2>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1, T2>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id || T2::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id || T2::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID || T2::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; //*************************************************************************** // Specialisation for 1 message type. //*************************************************************************** template class message_packet { public: //******************************************** #include "private/diagnostic_uninitialized_push.h" message_packet() : valid(false) { } #include "private/diagnostic_pop.h" //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(const etl::imessage& msg) { if (accepts(msg)) { add_new_message(msg); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** #include "private/diagnostic_uninitialized_push.h" explicit message_packet(etl::imessage&& msg) { if (accepts(msg)) { add_new_message(etl::move(msg)); valid = true; } else { valid = false; } ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception)); } #include "private/diagnostic_pop.h" #endif #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS) //******************************************** #include "private/diagnostic_uninitialized_push.h" template ::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1>::value, int>::type> explicit message_packet(TMessage&& /*msg*/) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #else //******************************************** #include "private/diagnostic_uninitialized_push.h" template explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && !etl::is_one_of::type, T1>::value, int>::type = 0) : valid(true) { // Not etl::message_packet, not etl::imessage and in typelist. static const bool Enabled = (!etl::is_same::type, etl::message_packet >::value && !etl::is_same::type, etl::imessage>::value && etl::is_one_of::type,T1>::value); ETL_STATIC_ASSERT(Enabled, "Message not in packet type list"); } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(const message_packet& other) : valid(other.is_valid()) { if (valid) { add_new_message(other.get()); } } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet(message_packet&& other) : valid(other.is_valid()) { if (valid) { add_new_message(etl::move(other.get())); } } #include "private/diagnostic_pop.h" #endif //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(rhs.get()); } return *this; } #include "private/diagnostic_pop.h" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //********************************************** #include "private/diagnostic_uninitialized_push.h" message_packet& operator =(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); if (valid) { add_new_message(etl::move(rhs.get())); } return *this; } #include "private/diagnostic_pop.h" #endif //******************************************** ~message_packet() { delete_current_message(); } //******************************************** etl::imessage& get() ETL_NOEXCEPT { return *static_cast(data); } //******************************************** const etl::imessage& get() const ETL_NOEXCEPT { return *static_cast(data); } //******************************************** bool is_valid() const { return valid; } //********************************************** static ETL_CONSTEXPR bool accepts(etl::message_id_t id) { return T1::ID == id; } //********************************************** static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) { return accepts(msg.get_message_id()); } //********************************************** template static ETL_CONSTEXPR bool accepts() { return T1::ID == Id; } //********************************************** template static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() { return T1::ID == TMessage::ID; } enum { SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; private: //******************************************** #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); pmsg->~imessage(); } } #include "private/diagnostic_pop.h" //******************************************** void add_new_message(const etl::imessage& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; default: break; } } #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //******************************************** void add_new_message(etl::imessage&& msg) { const size_t id = msg.get_message_id(); void* p = data; switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; default: break; } } #endif typename etl::aligned_storage::type data; bool valid; }; #endif } #else #error "etl::message_packet is not compatible with non-virtual etl::imessage" #endif #endif