diff --git a/include/etl/message_packet.h b/include/etl/message_packet.h index d729c940..a1565f40 100644 --- a/include/etl/message_packet.h +++ b/include/etl/message_packet.h @@ -383,6 +383,119 @@ namespace etl bool valid; }; + //*************************************************************************** + // The definition for no 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 = false; + + template + static constexpr bool IsIMessage = etl::is_same_v>, etl::imessage>; + + public: + + using message_types = etl::type_list<>; + + //******************************************** +#include "private/diagnostic_uninitialized_push.h" + message_packet() + { + } +#include "private/diagnostic_pop.h" + + //********************************************** + message_packet(const message_packet& other) + { + } + +#if ETL_USING_CPP11 + //********************************************** + message_packet(message_packet&& other) + { + } +#endif + + //********************************************** + void copy(const message_packet& other) + { + } + + //********************************************** + void copy(message_packet&& other) + { + } + + //********************************************** +#include "private/diagnostic_uninitialized_push.h" + message_packet& operator =(const message_packet& rhs) + { + return *this; + } +#include "private/diagnostic_pop.h" + + //********************************************** +#include "private/diagnostic_uninitialized_push.h" + message_packet& operator =(message_packet&& rhs) + { + return *this; + } +#include "private/diagnostic_pop.h" + + //******************************************** + ~message_packet() + { + } + + //******************************************** + bool is_valid() const + { + return false; + } + + //********************************************** + static ETL_CONSTEXPR bool accepts(etl::message_id_t id) + { + return false; + } + + //********************************************** + static ETL_CONSTEXPR bool accepts(const etl::imessage& msg) + { + return false; + } + + //********************************************** + template + static ETL_CONSTEXPR bool accepts() + { + return false; + } + + //********************************************** + template + static ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + accepts() + { + false; + } + + enum + { + SIZE = 0, + ALIGNMENT = 1 + }; + }; + //*************************************************************************** /// Helper to turn etl::type_list into etl::message_packet template @@ -5208,6 +5321,63 @@ namespace etl typename etl::aligned_storage::type data; bool valid; }; + + //*************************************************************************** + // Specialisation for 0 message types. + //*************************************************************************** + template <> + class message_packet + { + public: + +#if ETL_USING_CPP11 + using message_types = etl::type_list<>; +#endif + + message_packet() + : valid(false) + { + } + + static ETL_CONSTEXPR bool accepts(etl::message_id_t) + { + return false; + } + + static ETL_CONSTEXPR bool accepts(const etl::imessage&) + { + return false; + } + + template + static ETL_CONSTEXPR bool accepts() + { + ETL_UNUSED(Id); + return false; + } + + template + static ETL_CONSTEXPR typename etl::enable_if::value, bool>::type accepts() + { + return false; + } + + bool is_valid() const + { + return valid; + } + + enum + { + SIZE = 0U, + ALIGNMENT = 1U + }; + + private: + + bool valid; + }; #endif } diff --git a/test/test_message_packet.cpp b/test/test_message_packet.cpp index 3492a898..e77a3f5b 100644 --- a/test/test_message_packet.cpp +++ b/test/test_message_packet.cpp @@ -199,12 +199,12 @@ namespace { }; + using NullPacket = etl::message_packet<>; + using Packet = etl::message_packet; -#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) using MessageTypes = etl::type_list; using PacketFromMessageTypes = etl::message_packet_from_type_list_t; -#endif struct Object { @@ -228,20 +228,16 @@ namespace Packet packet1(message1); Packet packet2(message2); -#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) PacketFromMessageTypes packet3(message3); -#else - Packet packet3(message3); -#endif + NullPacket null_packet; // Should cause a static assert. //Packet packet4(message4); //Packet packet4((Message4())); CHECK_TRUE((std::is_same, typename Packet::message_types>::value)); -#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) CHECK_TRUE((std::is_same, typename PacketFromMessageTypes::message_types>::value)); -#endif + CHECK_TRUE((std::is_same, typename NullPacket::message_types>::value)); CHECK_EQUAL(MESSAGE1, packet1.get().get_message_id()); CHECK_EQUAL(MESSAGE2, packet2.get().get_message_id());