34#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
63#ifndef ETL_MESSAGE_PACKET_INCLUDED
64#define ETL_MESSAGE_PACKET_INCLUDED
68#if ETL_HAS_VIRTUAL_MESSAGES
72#include "static_assert.h"
81#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
85 template <
typename... TMessageTypes>
114 template <
typename T,
typename =
typename etl::enable_if<IsIMessage<T> || IsInMessageList<T>,
int>::type>
115 explicit message_packet(T&& msg)
118 if constexpr (IsIMessage<T>)
130 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
132 else if constexpr (IsInMessageList<T>)
138 ETL_STATIC_ASSERT(IsInMessageList<T>,
"Message not in packet type list");
144 message_packet(
const message_packet& other)
146 valid = other.is_valid();
150 add_new_message(other.get());
156 message_packet(message_packet&& other)
158 valid = other.is_valid();
162 add_new_message(etl::move(other.get()));
168 void copy(
const message_packet& other)
170 valid = other.is_valid();
174 add_new_message(other.get());
179 void copy(message_packet&& other)
181 valid = other.is_valid();
185 add_new_message(etl::move(other.get()));
191 message_packet& operator =(
const message_packet& rhs)
193 delete_current_message();
194 valid = rhs.is_valid();
197 add_new_message(rhs.get());
206 message_packet& operator =(message_packet&& rhs)
208 delete_current_message();
209 valid = rhs.is_valid();
212 add_new_message(etl::move(rhs.get()));
222 delete_current_message();
238 bool is_valid()
const
246 return (accepts_message<TMessageTypes::ID>(
id) || ...);
252 return accepts(msg.get_message_id());
256 template <etl::message_
id_t Id>
257 static ETL_CONSTEXPR
bool accepts()
259 return (accepts_message<TMessageTypes::ID, Id>() || ...);
263 template <
typename TMessage>
268 return accepts<TMessage::ID>();
280 template <etl::message_
id_t Id1, etl::message_
id_t Id2>
281 static bool accepts_message()
287 template <etl::message_
id_t Id1>
295 void delete_current_message()
309 (add_new_message_type<TMessageTypes>(msg) || ...);
315 (add_new_message_type<TMessageTypes>(etl::move(msg)) || ...);
322 template <
typename TMessage>
324 add_new_message_type(TMessage&& msg)
333 template <
typename TType>
336 if (TType::ID == msg.get_message_id())
339 new (p) TType(
static_cast<const TType&
>(msg));
350 template <
typename TType>
353 if (TType::ID == msg.get_message_id())
356 new (p) TType(
static_cast<TType&&
>(msg));
517 cog.outl(" : valid(true)
")
519 generate_static_assert_cpp11(int(Handlers))
521 cog.outl("#include \
"private/diagnostic_pop.h\"")
523 cog.outl(
" //********************************************")
524 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
525 cog.outl(
" template <typename TMessage>")
526 cog.out(
" explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<")
527 for n in range(1,
int(Handlers)):
529 cog.outl(
"T%s> >::value &&" % int(Handlers))
530 cog.outl(
" !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&")
531 cog.out(
" !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, ")
532 for n in range(1, int(Handlers)):
534 cog.outl(
"T%s>::value, int>::type = 0)" % int(Handlers))
535 cog.outl(
" : valid(true)")
537 generate_static_assert_cpp03(int(Handlers))
539 cog.outl(
"#include \"private/diagnostic_pop.h\"")
542 cog.outl(
" //**********************************************")
543 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
544 cog.outl(
" message_packet(const message_packet& other)")
545 cog.outl(
" : valid(other.is_valid())")
547 cog.outl(
" if (valid)")
549 cog.outl(
" add_new_message(other.get());")
552 cog.outl(
"#include \"private/diagnostic_pop.h\"")
554 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
555 cog.outl(
" //**********************************************")
556 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
557 cog.outl(
" message_packet(message_packet&& other)")
558 cog.outl(
" : valid(other.is_valid())")
560 cog.outl(
" if (valid)")
562 cog.outl(
" add_new_message(etl::move(other.get()));")
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& operator =(const message_packet& rhs)")
572 cog.outl(
" delete_current_message();")
573 cog.outl(
" valid = rhs.is_valid();")
574 cog.outl(
" if (valid)")
576 cog.outl(
" add_new_message(rhs.get());")
579 cog.outl(
" return *this;")
581 cog.outl(
"#include \"private/diagnostic_pop.h\"")
583 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
584 cog.outl(
" //**********************************************")
585 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
586 cog.outl(
" message_packet& operator =(message_packet&& rhs)")
588 cog.outl(
" delete_current_message();")
589 cog.outl(
" valid = rhs.is_valid();")
590 cog.outl(
" if (valid)")
592 cog.outl(
" add_new_message(etl::move(rhs.get()));")
595 cog.outl(
" return *this;")
597 cog.outl(
"#include \"private/diagnostic_pop.h\"")
600 cog.outl(
" //********************************************")
601 cog.outl(
" ~message_packet()")
603 cog.outl(
" delete_current_message();")
606 cog.outl(
" //********************************************")
607 cog.outl(
" etl::imessage& get() ETL_NOEXCEPT")
609 cog.outl(
" return *static_cast<etl::imessage*>(data);")
612 cog.outl(
" //********************************************")
613 cog.outl(
" const etl::imessage& get() const ETL_NOEXCEPT")
615 cog.outl(
" return *static_cast<const etl::imessage*>(data);")
618 cog.outl(
" //********************************************")
619 cog.outl(
" bool is_valid() const")
621 cog.outl(
" return valid;")
624 cog.outl(
" //**********************************************")
625 cog.outl(
" static ETL_CONSTEXPR bool accepts(etl::message_id_t id)")
627 generate_accepts_return(int(Handlers))
630 cog.outl(
" //**********************************************")
631 cog.outl(
" static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)")
633 cog.outl(
" return accepts(msg.get_message_id());")
636 cog.outl(
" //**********************************************")
637 cog.outl(
" template <etl::message_id_t Id>")
638 cog.outl(
" static ETL_CONSTEXPR bool accepts()")
640 generate_accepts_return_compile_time(int(Handlers))
643 cog.outl(
" //**********************************************")
644 cog.outl(
" template <typename TMessage>")
645 cog.outl(
" static ETL_CONSTEXPR")
646 cog.outl(
" typename etl::enable_if<etl::is_base_of<etl::imessage, TMessage>::value, bool>::type")
647 cog.outl(
" accepts()")
649 generate_accepts_return_compile_time_TMessage(int(Handlers))
654 cog.out(
" SIZE = etl::largest<")
655 for n in range(1, int(Handlers)):
657 cog.outl(
"T%s>::size," % int(Handlers))
658 cog.out(
" ALIGNMENT = etl::largest<")
659 for n in range(1, int(Handlers)):
661 cog.outl(
"T%s>::alignment" % int(Handlers))
666 cog.outl(
" //********************************************")
667 cog.outl(
" #include \"private/diagnostic_uninitialized_push.h\"")
668 cog.outl(
" void delete_current_message()")
670 cog.outl(
" if (valid)")
672 cog.outl(
" etl::imessage* pmsg = static_cast<etl::imessage*>(data);")
674 cog.outl(
" pmsg->~imessage();")
677 cog.outl(
" #include \"private/diagnostic_pop.h\"")
679 cog.outl(
" //********************************************")
680 cog.outl(
" void add_new_message(const etl::imessage& msg)")
682 cog.outl(
" const size_t id = msg.get_message_id();")
683 cog.outl(
" void* p = data;")
685 cog.outl(
" switch (id)")
687 for n in range(1, int(Handlers) + 1):
688 cog.outl(
" case T%d::ID: ::new (p) T%d(static_cast<const T%d&>(msg)); break;" %(n, n, n))
689 cog.outl(
" default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;")
693 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
694 cog.outl(
" //********************************************")
695 cog.outl(
" void add_new_message(etl::imessage&& msg)")
697 cog.outl(
" const size_t id = msg.get_message_id();")
698 cog.outl(
" void* p = data;")
700 cog.outl(
" switch (id)")
702 for n in range(1, int(Handlers) + 1):
703 cog.outl(
" case T%d::ID: ::new (p) T%d(static_cast<T%d&&>(msg)); break;" %(n, n, n))
704 cog.outl(
" default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;")
709 cog.outl(
" typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;")
710 cog.outl(
" bool valid;")
713 ####################################
714 # All of the other specialisations.
715 ####################################
716 for n in range(int(Handlers) - 1, 0, -1):
718 cog.outl(
"//***************************************************************************")
720 cog.outl(
"// Specialisation for %d message type." % n)
722 cog.outl(
"// Specialisation for %d message types." % n)
723 cog.outl(
"//***************************************************************************")
724 cog.out(
"template <")
725 for t in range(1, n):
726 cog.out(
"typename T%s, " % t)
730 cog.outl(
"typename T%s>" % n)
731 cog.out(
"class message_packet<")
732 for t in range(1, n + 1):
737 for t in range(n + 1, int(Handlers)):
746 cog.outl(
" //********************************************")
747 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
748 cog.outl(
" message_packet()")
749 cog.outl(
" : valid(false)")
752 cog.outl(
"#include \"private/diagnostic_pop.h\"")
754 cog.outl(
" //********************************************")
755 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
756 cog.outl(
" explicit message_packet(const etl::imessage& msg)")
758 cog.outl(
" if (accepts(msg))")
760 cog.outl(
" add_new_message(msg);")
761 cog.outl(
" valid = true;")
765 cog.outl(
" valid = false;")
768 cog.outl(
" ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));")
770 cog.outl(
"#include \"private/diagnostic_pop.h\"")
772 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
773 cog.outl(
" //********************************************")
774 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
775 cog.outl(
" explicit message_packet(etl::imessage&& msg)")
777 cog.outl(
" if (accepts(msg))")
779 cog.outl(
" add_new_message(etl::move(msg));")
780 cog.outl(
" valid = true;")
784 cog.outl(
" valid = false;")
787 cog.outl(
" ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));")
789 cog.outl(
"#include \"private/diagnostic_pop.h\"")
792 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)")
793 cog.outl(
" //********************************************")
794 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
795 cog.out(
" template <typename TMessage, typename = typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<")
796 for t in range(1, n):
798 cog.outl(
"T%s> >::value &&" % n)
799 cog.outl(
" !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&")
800 cog.out(
" !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, ")
801 for t in range(1, n):
803 cog.outl(
"T%s>::value, int>::type>" % n)
804 cog.outl(
" explicit message_packet(TMessage&& /*msg*/)")
805 cog.outl(
" : valid(true)")
807 generate_static_assert_cpp11(n)
809 cog.outl(
"#include \"private/diagnostic_pop.h\"")
811 cog.outl(
" //********************************************")
812 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
813 cog.outl(
" template <typename TMessage>")
814 cog.out(
" explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<")
815 for t in range(1, n):
817 cog.outl(
"T%s> >::value &&" % n)
818 cog.outl(
" !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&")
819 cog.out(
" !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, ")
820 for t in range(1, n):
822 cog.outl(
"T%s>::value, int>::type = 0)" % n)
823 cog.outl(
" : valid(true)")
825 generate_static_assert_cpp03(n)
827 cog.outl(
"#include \"private/diagnostic_pop.h\"")
830 cog.outl(
" //**********************************************")
831 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
832 cog.outl(
" message_packet(const message_packet& other)")
833 cog.outl(
" : valid(other.is_valid())")
835 cog.outl(
" if (valid)")
837 cog.outl(
" add_new_message(other.get());")
840 cog.outl(
"#include \"private/diagnostic_pop.h\"")
842 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
843 cog.outl(
" //**********************************************")
844 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
845 cog.outl(
" message_packet(message_packet&& other)")
846 cog.outl(
" : valid(other.is_valid())")
848 cog.outl(
" if (valid)")
850 cog.outl(
" add_new_message(etl::move(other.get()));")
853 cog.outl(
"#include \"private/diagnostic_pop.h\"")
856 cog.outl(
" //**********************************************")
857 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
858 cog.outl(
" message_packet& operator =(const message_packet& rhs)")
860 cog.outl(
" delete_current_message();")
861 cog.outl(
" valid = rhs.is_valid();")
862 cog.outl(
" if (valid)")
864 cog.outl(
" add_new_message(rhs.get());")
867 cog.outl(
" return *this;")
869 cog.outl(
"#include \"private/diagnostic_pop.h\"")
871 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
872 cog.outl(
" //**********************************************")
873 cog.outl(
"#include \"private/diagnostic_uninitialized_push.h\"")
874 cog.outl(
" message_packet& operator =(message_packet&& rhs)")
876 cog.outl(
" delete_current_message();")
877 cog.outl(
" valid = rhs.is_valid();")
878 cog.outl(
" if (valid)")
880 cog.outl(
" add_new_message(etl::move(rhs.get()));")
883 cog.outl(
" return *this;")
885 cog.outl(
"#include \"private/diagnostic_pop.h\"")
888 cog.outl(
" //********************************************")
889 cog.outl(
" ~message_packet()")
891 cog.outl(
" delete_current_message();")
894 cog.outl(
" //********************************************")
895 cog.outl(
" etl::imessage& get() ETL_NOEXCEPT")
897 cog.outl(
" return *static_cast<etl::imessage*>(data);")
900 cog.outl(
" //********************************************")
901 cog.outl(
" const etl::imessage& get() const ETL_NOEXCEPT")
903 cog.outl(
" return *static_cast<const etl::imessage*>(data);")
906 cog.outl(
" //********************************************")
907 cog.outl(
" bool is_valid() const")
909 cog.outl(
" return valid;")
912 cog.outl(
" //**********************************************")
913 cog.outl(
" static ETL_CONSTEXPR bool accepts(etl::message_id_t id)")
915 generate_accepts_return(n)
918 cog.outl(
" //**********************************************")
919 cog.outl(
" static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)")
921 cog.outl(
" return accepts(msg.get_message_id());")
924 cog.outl(
" //**********************************************")
925 cog.outl(
" template <etl::message_id_t Id>")
926 cog.outl(
" static ETL_CONSTEXPR bool accepts()")
928 generate_accepts_return_compile_time(n)
931 cog.outl(
" //**********************************************")
932 cog.outl(
" template <typename TMessage>")
933 cog.outl(
" static ETL_CONSTEXPR")
934 cog.outl(
" typename etl::enable_if<etl::is_base_of<etl::imessage, TMessage>::value, bool>::type")
935 cog.outl(
" accepts()")
937 generate_accepts_return_compile_time_TMessage(n)
942 cog.out(
" SIZE = etl::largest<")
943 for t in range(1, n):
945 cog.outl(
"T%s>::size," % n)
946 cog.out(
" ALIGNMENT = etl::largest<")
947 for t in range(1, n):
949 cog.outl(
"T%s>::alignment" % n)
954 cog.outl(
" //********************************************")
955 cog.outl(
" #include \"private/diagnostic_uninitialized_push.h\"")
956 cog.outl(
" void delete_current_message()")
958 cog.outl(
" if (valid)")
960 cog.outl(
" etl::imessage* pmsg = static_cast<etl::imessage*>(data);")
962 cog.outl(
" pmsg->~imessage();")
965 cog.outl(
" #include \"private/diagnostic_pop.h\"")
967 cog.outl(
" //********************************************")
968 cog.outl(
" void add_new_message(const etl::imessage& msg)")
970 cog.outl(
" const size_t id = msg.get_message_id();")
971 cog.outl(
" void* p = data;")
973 cog.outl(
" switch (id)")
975 for t in range(1, n + 1):
976 cog.outl(
" case T%d::ID: ::new (p) T%d(static_cast<const T%d&>(msg)); break;" %(t, t, t))
977 cog.outl(
" default: break;")
981 cog.outl(
"#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)")
982 cog.outl(
" //********************************************")
983 cog.outl(
" void add_new_message(etl::imessage&& msg)")
985 cog.outl(
" const size_t id = msg.get_message_id();")
986 cog.outl(
" void* p = data;")
988 cog.outl(
" switch (id)")
990 for t in range(1, n + 1):
991 cog.outl(
" case T%d::ID: ::new (p) T%d(static_cast<T%d&&>(msg)); break;" %(t, t, t))
992 cog.outl(
" default: break;")
997 cog.outl(
" typename etl::aligned_storage<SIZE, ALIGNMENT>::type data;")
998 cog.outl(
" bool valid;")
1005 #error
"etl::message_packet is not compatible with non-virtual etl::imessage"
Definition message_packet.h:367
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
bitset_ext
Definition absolute.h:38
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
Definition alignment.h:233
pair holds two objects of arbitrary type
Definition utility.h:164