34#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
63#ifndef ETL_MESSAGE_PACKET_INCLUDED
64#define ETL_MESSAGE_PACKET_INCLUDED
70#include "static_assert.h"
79#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
112 template <
typename T,
typename =
typename etl::enable_if<IsIMessage<T> || IsInMessageList<T>,
int>::type>
113 explicit message_packet(
T&&
msg)
128 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
142 message_packet(
const message_packet&
other)
144 valid =
other.is_valid();
148 add_new_message(
other.get());
154 message_packet(message_packet&&
other)
156 valid =
other.is_valid();
160 add_new_message(etl::move(
other.get()));
166 void copy(
const message_packet&
other)
168 valid =
other.is_valid();
172 add_new_message(
other.get());
177 void copy(message_packet&&
other)
179 valid =
other.is_valid();
183 add_new_message(etl::move(
other.get()));
189 message_packet& operator =(
const message_packet&
rhs)
191 delete_current_message();
192 valid =
rhs.is_valid();
195 add_new_message(
rhs.get());
204 message_packet& operator =(message_packet&&
rhs)
206 delete_current_message();
207 valid =
rhs.is_valid();
210 add_new_message(etl::move(
rhs.get()));
220 delete_current_message();
236 bool is_valid()
const
250 return accepts(
msg.get_message_id());
254 template <etl::message_
id_t Id>
255 static ETL_CONSTEXPR
bool accepts()
261 template <
typename TMessage>
278 template <etl::message_
id_t Id1, etl::message_
id_t Id2>
285 template <etl::message_
id_t Id1>
293 void delete_current_message()
299#if ETL_HAS_VIRTUAL_MESSAGES
302 delete_message(
pmsg);
308#if !ETL_HAS_VIRTUAL_MESSAGES
316 template <
typename TType>
319 if (TType::ID ==
pmsg->get_message_id())
348 template <
typename TMessage>
359 template <
typename TType>
362 if (TType::ID ==
msg.get_message_id())
376 template <
typename TType>
379 if (TType::ID ==
msg.get_message_id())
543 cog.outl(" : valid(true)
")
545 generate_static_assert_cpp11(int(Handlers))
547 cog.outl("#
include \
"private/diagnostic_pop.h\"")
549 cog.outl(
" //********************************************")
550 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
551 cog.outl(
" template <typename TMessage>")
552 cog.out(
" explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<")
556 cog.outl(
" !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&")
557 cog.out(
" !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, ")
561 cog.outl(
" : valid(true)")
565 cog.outl(
"#include \"private/diagnostic_pop.h\"")
568 cog.outl(
" //**********************************************")
569 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
570 cog.outl(
" message_packet(const message_packet& other)")
571 cog.outl(
" : valid(other.is_valid())")
573 cog.outl(
" if (valid)")
575 cog.outl(
" add_new_message(other.get());")
578 cog.outl(
"#include \"private/diagnostic_pop.h\"")
580 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
581 cog.outl(
" //**********************************************")
582 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
583 cog.outl(
" message_packet(message_packet&& other)")
584 cog.outl(
" : valid(other.is_valid())")
586 cog.outl(
" if (valid)")
588 cog.outl(
" add_new_message(etl::move(other.get()));")
591 cog.outl(
"#include \"private/diagnostic_pop.h\"")
594 cog.outl(
" //**********************************************")
595 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
596 cog.outl(
" message_packet& operator =(const message_packet& rhs)")
598 cog.outl(
" delete_current_message();")
599 cog.outl(
" valid = rhs.is_valid();")
600 cog.outl(
" if (valid)")
602 cog.outl(
" add_new_message(rhs.get());")
605 cog.outl(
" return *this;")
607 cog.outl(
"#include \"private/diagnostic_pop.h\"")
609 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
610 cog.outl(
" //**********************************************")
611 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
612 cog.outl(
" message_packet& operator =(message_packet&& rhs)")
614 cog.outl(
" delete_current_message();")
615 cog.outl(
" valid = rhs.is_valid();")
616 cog.outl(
" if (valid)")
618 cog.outl(
" add_new_message(etl::move(rhs.get()));")
621 cog.outl(
" return *this;")
623 cog.outl(
"#include \"private/diagnostic_pop.h\"")
626 cog.outl(
" //********************************************")
627 cog.outl(
" ~message_packet()")
629 cog.outl(
" delete_current_message();")
632 cog.outl(
" //********************************************")
633 cog.outl(
" etl::imessage& get() ETL_NOEXCEPT")
635 cog.outl(
" return *static_cast<etl::imessage*>(data);")
638 cog.outl(
" //********************************************")
639 cog.outl(
" const etl::imessage& get() const ETL_NOEXCEPT")
641 cog.outl(
" return *static_cast<const etl::imessage*>(data);")
644 cog.outl(
" //********************************************")
645 cog.outl(
" bool is_valid() const")
647 cog.outl(
" return valid;")
650 cog.outl(
" //**********************************************")
651 cog.outl(
" static ETL_CONSTEXPR bool accepts(etl::message_id_t id)")
656 cog.outl(
" //**********************************************")
657 cog.outl(
" static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)")
659 cog.outl(
" return accepts(msg.get_message_id());")
662 cog.outl(
" //**********************************************")
663 cog.outl(
" template <etl::message_id_t Id>")
664 cog.outl(
" static ETL_CONSTEXPR bool accepts()")
669 cog.outl(
" //**********************************************")
670 cog.outl(
" template <typename TMessage>")
671 cog.outl(
" static ETL_CONSTEXPR")
672 cog.outl(
" typename etl::enable_if<etl::is_base_of<etl::imessage, TMessage>::value, bool>::type")
673 cog.outl(
" accepts()")
680 cog.out(
" SIZE = etl::largest<")
684 cog.out(
" ALIGNMENT = etl::largest<")
692 cog.outl(
" //********************************************")
693 cog.outl(
" #include \"private/diagnostic_uninitialized_push.h\"")
694 cog.outl(
" void delete_current_message()")
696 cog.outl(
" if (valid)")
698 cog.outl(
" etl::imessage* pmsg = static_cast<etl::imessage*>(data);")
700 cog.outl(
"#if ETL_HAS_VIRTUAL_MESSAGES")
701 cog.outl(
" pmsg->~imessage();")
703 cog.outl(
" delete_message(pmsg);")
707 cog.outl(
" #include \"private/diagnostic_pop.h\"")
709 cog.outl(
" //********************************************")
710 cog.outl(
" void delete_message(etl::imessage* pmsg)")
712 cog.outl(
" switch (pmsg->get_message_id())")
715 cog.out(
" case T%d::ID: static_cast<const T%d" %(
n,
n))
716 cog.outl(
"*>(pmsg)->~T%d(); break;" %
n)
717 cog.outl(
" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;")
721 cog.outl(
" //********************************************")
722 cog.outl(
" void add_new_message(const etl::imessage& msg)")
724 cog.outl(
" const size_t id = msg.get_message_id();")
725 cog.outl(
" void* p = data;")
727 cog.outl(
" switch (id)")
730 cog.outl(
" case T%d::ID: ::new (p) T%d(static_cast<const T%d&>(msg)); break;" %(
n,
n,
n))
731 cog.outl(
" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;")
735 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
736 cog.outl(
" //********************************************")
737 cog.outl(
" void add_new_message(etl::imessage&& msg)")
739 cog.outl(
" const size_t id = msg.get_message_id();")
740 cog.outl(
" void* p = data;")
742 cog.outl(
" switch (id)")
745 cog.outl(
" case T%d::ID: ::new (p) T%d(static_cast<T%d&&>(msg)); break;" %(
n,
n,
n))
746 cog.outl(
" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;")
751 cog.outl(
" typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;")
752 cog.outl(
" bool valid;")
755 ####################################
757 ####################################
760 cog.outl(
"//***************************************************************************")
762 cog.outl(
"// Specialisation for %d message type." %
n)
764 cog.outl(
"// Specialisation for %d message types." %
n)
765 cog.outl(
"//***************************************************************************")
766 cog.out(
"template <")
767 for t in range(1,
n):
768 cog.out(
"typename T%s, " % t)
772 cog.outl(
"typename T%s>" %
n)
773 cog.out(
"class message_packet<")
774 for t in range(1,
n + 1):
788 cog.outl(
" //********************************************")
789 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
790 cog.outl(
" message_packet()")
791 cog.outl(
" : valid(false)")
794 cog.outl(
"#include \"private/diagnostic_pop.h\"")
796 cog.outl(
" //********************************************")
797 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
798 cog.outl(
" explicit message_packet(const etl::imessage& msg)")
800 cog.outl(
" if (accepts(msg))")
802 cog.outl(
" add_new_message(msg);")
803 cog.outl(
" valid = true;")
807 cog.outl(
" valid = false;")
810 cog.outl(
" ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));")
812 cog.outl(
"#include \"private/diagnostic_pop.h\"")
814 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
815 cog.outl(
" //********************************************")
816 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
817 cog.outl(
" explicit message_packet(etl::imessage&& msg)")
819 cog.outl(
" if (accepts(msg))")
821 cog.outl(
" add_new_message(etl::move(msg));")
822 cog.outl(
" valid = true;")
826 cog.outl(
" valid = false;")
829 cog.outl(
" ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));")
831 cog.outl(
"#include \"private/diagnostic_pop.h\"")
834 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)")
835 cog.outl(
" //********************************************")
836 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
837 cog.out(
" template <typename TMessage, typename = typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<")
838 for t in range(1,
n):
840 cog.outl(
"T%s> >::value &&" %
n)
841 cog.outl(
" !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&")
842 cog.out(
" !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, ")
843 for t in range(1,
n):
845 cog.outl(
"T%s>::value, int>::type>" %
n)
846 cog.outl(
" explicit message_packet(TMessage&& /*msg*/)")
847 cog.outl(
" : valid(true)")
851 cog.outl(
"#include \"private/diagnostic_pop.h\"")
853 cog.outl(
" //********************************************")
854 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
855 cog.outl(
" template <typename TMessage>")
856 cog.out(
" explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<")
857 for t in range(1,
n):
859 cog.outl(
"T%s> >::value &&" %
n)
860 cog.outl(
" !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&")
861 cog.out(
" !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, ")
862 for t in range(1,
n):
864 cog.outl(
"T%s>::value, int>::type = 0)" %
n)
865 cog.outl(
" : valid(true)")
869 cog.outl(
"#include \"private/diagnostic_pop.h\"")
872 cog.outl(
" //**********************************************")
873 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
874 cog.outl(
" message_packet(const message_packet& other)")
875 cog.outl(
" : valid(other.is_valid())")
877 cog.outl(
" if (valid)")
879 cog.outl(
" add_new_message(other.get());")
882 cog.outl(
"#include \"private/diagnostic_pop.h\"")
884 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
885 cog.outl(
" //**********************************************")
886 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
887 cog.outl(
" message_packet(message_packet&& other)")
888 cog.outl(
" : valid(other.is_valid())")
890 cog.outl(
" if (valid)")
892 cog.outl(
" add_new_message(etl::move(other.get()));")
895 cog.outl(
"#include \"private/diagnostic_pop.h\"")
898 cog.outl(
" //**********************************************")
899 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
900 cog.outl(
" message_packet& operator =(const message_packet& rhs)")
902 cog.outl(
" delete_current_message();")
903 cog.outl(
" valid = rhs.is_valid();")
904 cog.outl(
" if (valid)")
906 cog.outl(
" add_new_message(rhs.get());")
909 cog.outl(
" return *this;")
911 cog.outl(
"#include \"private/diagnostic_pop.h\"")
913 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
914 cog.outl(
" //**********************************************")
915 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
916 cog.outl(
" message_packet& operator =(message_packet&& rhs)")
918 cog.outl(
" delete_current_message();")
919 cog.outl(
" valid = rhs.is_valid();")
920 cog.outl(
" if (valid)")
922 cog.outl(
" add_new_message(etl::move(rhs.get()));")
925 cog.outl(
" return *this;")
927 cog.outl(
"#include \"private/diagnostic_pop.h\"")
930 cog.outl(
" //********************************************")
931 cog.outl(
" ~message_packet()")
933 cog.outl(
" delete_current_message();")
936 cog.outl(
" //********************************************")
937 cog.outl(
" etl::imessage& get() ETL_NOEXCEPT")
939 cog.outl(
" return *static_cast<etl::imessage*>(data);")
942 cog.outl(
" //********************************************")
943 cog.outl(
" const etl::imessage& get() const ETL_NOEXCEPT")
945 cog.outl(
" return *static_cast<const etl::imessage*>(data);")
948 cog.outl(
" //********************************************")
949 cog.outl(
" bool is_valid() const")
951 cog.outl(
" return valid;")
954 cog.outl(
" //**********************************************")
955 cog.outl(
" static ETL_CONSTEXPR bool accepts(etl::message_id_t id)")
960 cog.outl(
" //**********************************************")
961 cog.outl(
" static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)")
963 cog.outl(
" return accepts(msg.get_message_id());")
966 cog.outl(
" //**********************************************")
967 cog.outl(
" template <etl::message_id_t Id>")
968 cog.outl(
" static ETL_CONSTEXPR bool accepts()")
973 cog.outl(
" //**********************************************")
974 cog.outl(
" template <typename TMessage>")
975 cog.outl(
" static ETL_CONSTEXPR")
976 cog.outl(
" typename etl::enable_if<etl::is_base_of<etl::imessage, TMessage>::value, bool>::type")
977 cog.outl(
" accepts()")
984 cog.out(
" SIZE = etl::largest<")
985 for t in range(1,
n):
987 cog.outl(
"T%s>::size," %
n)
988 cog.out(
" ALIGNMENT = etl::largest<")
989 for t in range(1,
n):
991 cog.outl(
"T%s>::alignment" %
n)
996 cog.outl(
" //********************************************")
997 cog.outl(
" #include \"private/diagnostic_uninitialized_push.h\"")
998 cog.outl(
" void delete_current_message()")
1000 cog.outl(
" if (valid)")
1002 cog.outl(
" etl::imessage* pmsg = static_cast<etl::imessage*>(data);")
1005 cog.outl(
"#if ETL_HAS_VIRTUAL_MESSAGES")
1006 cog.outl(
" pmsg->~imessage();")
1008 cog.outl(
" delete_message(pmsg);")
1012 cog.outl(
" #include \"private/diagnostic_pop.h\"")
1014 cog.outl(
" //********************************************")
1015 cog.outl(
" void delete_message(etl::imessage* pmsg)")
1017 cog.outl(
" switch (pmsg->get_message_id())")
1019 for t in range(1,
n + 1):
1020 cog.out(
" case T%d::ID: static_cast<const T%d" %(t, t))
1021 cog.outl(
"*>(pmsg)->~T%d(); break;" % t)
1022 cog.outl(
" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;")
1026 cog.outl(
" //********************************************")
1027 cog.outl(
" void add_new_message(const etl::imessage& msg)")
1029 cog.outl(
" const size_t id = msg.get_message_id();")
1030 cog.outl(
" void* p = data;")
1032 cog.outl(
" switch (id)")
1034 for t in range(1,
n + 1):
1035 cog.outl(
" case T%d::ID: ::new (p) T%d(static_cast<const T%d&>(msg)); break;" %(t, t, t))
1036 cog.outl(
" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;")
1040 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
1041 cog.outl(
" //********************************************")
1042 cog.outl(
" void add_new_message(etl::imessage&& msg)")
1044 cog.outl(
" const size_t id = msg.get_message_id();")
1045 cog.outl(
" void* p = data;")
1047 cog.outl(
" switch (id)")
1049 for t in range(1,
n + 1):
1050 cog.outl(
" case T%d::ID: ::new (p) T%d(static_cast<T%d&&>(msg)); break;" %(t, t, t))
1051 cog.outl(
" default: break;")
1056 cog.outl(
" typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;")
1057 cog.outl(
" bool valid;")
Definition message_packet.h:393
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
enable_if
Definition type_traits_generator.h:1230
bitset_ext
Definition absolute.h:38
uint_least8_t message_id_t
Allow alternative type for message id.
Definition message_types.h:40
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
Definition alignment.h:247