diff --git a/include/etl/message_packet.h b/include/etl/message_packet.h index 556b3e35..9858dd24 100644 --- a/include/etl/message_packet.h +++ b/include/etl/message_packet.h @@ -351,271 +351,9 @@ namespace etl } } }; + #else - //*************************************************************************** - /// Exception base for message_packet. - //*************************************************************************** - class message_packet_exception : public etl::exception - { - public: - message_packet_exception(string_type reason_, string_type file_name_, numeric_type line_number_) - : exception(reason_, file_name_, line_number_) - { - } - }; - - //*************************************************************************** - /// Exception for illegal message type. - //*************************************************************************** - class message_packet_illegal_type : public etl::message_packet_exception - { - public: - - message_packet_illegal_type(string_type file_name_, numeric_type line_number_) - : message_packet_exception(ETL_ERROR_TEXT("message_packet:illegal type", ETL_MESSAGE_PACKET_FILE_ID"A"), file_name_, line_number_) - { - } - }; - -#if ETL_CPP17_SUPPORTED && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03) - //*************************************************************************** - // The definition for all message types. - //*************************************************************************** - template - class message_packet - { - public: - - //******************************************** - message_packet() - : valid(false) - { - } - - //******************************************** - explicit message_packet(const etl::imessage& msg) - : valid(true) - { - add_new_message(msg); - } - - //******************************************** - explicit message_packet(etl::imessage&& msg) - : valid(true) - { - add_new_message(etl::move(msg)); - } - - //********************************************** - message_packet(const message_packet& other) - : valid(other.is_valid()) - { - if (valid) - { - add_new_message(other.get()); - } - } - - //********************************************** - message_packet(message_packet&& other) - : valid(other.is_valid()) - { - if (valid) - { - add_new_message(etl::move(other.get())); - } - } - - //********************************************** - message_packet& operator =(const message_packet& rhs) - { - delete_current_message(); - valid = rhs.is_valid(); - if (valid) - { - add_new_message(rhs.get()); - } - - return *this; - } - - //********************************************** - message_packet& operator =(message_packet&& rhs) - { - delete_current_message(); - valid = rhs.is_valid(); - if (valid) - { - add_new_message(etl::move(rhs.get())); - } - - return *this; - } - - //******************************************** - ~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(TMessage::ID); - } - - enum - { - SIZE = etl::largest::size, - ALIGNMENT = etl::largest::alignment - }; - - private: - - //********************************************** - template - static ETL_CONSTEXPR bool accepts_message() - { - return Id1 == Id2; - } - - //********************************************** - template - static ETL_CONSTEXPR bool accepts_message(etl::message_id_t id2) - { - return Id1 == id2; - } - - //******************************************** - void delete_current_message() - { - if (valid) - { - etl::imessage* pmsg = static_cast(data); - -#if defined(ETL_MESSAGES_ARE_VIRTUAL) || defined(ETL_POLYMORPHIC_MESSAGES) - pmsg->~imessage(); -#else - if (!(delete_current_message_type(pmsg->get_message_id()) || ...)) - { - ETL_ALWAYS_ASSERT(ETL_ERROR(unhandled_message_exception)); - } -#endif - } - } - - //******************************************** - void add_new_message(const etl::imessage& msg) - { - if (!(add_new_message_type(msg) || ...)) - { - ETL_ALWAYS_ASSERT(ETL_ERROR(unhandled_message_exception)); - } - } - - //******************************************** - void add_new_message(etl::imessage&& msg) - { - if (!(add_new_message_type(etl::move(msg)) || ...)) - { - ETL_ALWAYS_ASSERT(ETL_ERROR(unhandled_message_exception)); - } - } - - typename etl::aligned_storage::type data; - bool valid; - - private: - - //******************************************** - template - bool delete_current_message_type(etl::message_id_t Id) - { - if (TMessage::ID == Id) - { - static_cast(data)->~TMessage(); - return true; - } - else - { - return false; - } - } - - //******************************************** - template - bool add_new_message_type(const etl::imessage& msg) - { - if (TMessage::ID == msg.get_message_id()) - { - void* p = data; - new (p) TMessage(static_cast(msg)); - return true; - } - else - { - return false; - } - } - - //******************************************** - template - bool add_new_message_type(etl::imessage&& msg) - { - if (TMessage::ID == msg.get_message_id()) - { - void* p = data; - new (p) TMessage(static_cast(msg)); - return true; - } - else - { - return false; - } - } - }; -#else //*************************************************************************** // The definition for all 16 message types. //*************************************************************************** diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index f77d1710..25a56d06 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -2076,6 +2076,8 @@ Source Files\Sanity Checks + Source Files\Sanity Checks + Source Files\Sanity Checks @@ -2119,8 +2121,8 @@ Source Files\Sanity Checks - Source Files\Sanity Checks - + Source Files\Sanity Checks + Source Files\Sanity Checks