Embedded Template Library 1.0
Loading...
Searching...
No Matches
message_packet.h
1/******************************************************************************
2The MIT License(MIT)
3
4Embedded Template Library.
5https://github.com/ETLCPP/etl
6https://www.etlcpp.com
7
8Copyright(c) 2020 John Wellbelove
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files(the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions :
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27******************************************************************************/
28
29#if 0
30#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
31#endif
32
33//***************************************************************************
34// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.
35//***************************************************************************
36
37//***************************************************************************
38// To generate to header file, run this at the command line.
39// Note: You will need Python and COG installed.
40//
41// python -m cogapp -d -e -omessage_packet.h -DHandlers=<n> message_packet_generator.h
42// Where <n> is the number of messages to support.
43//
44// e.g.
45// To generate handlers for up to 16 messages...
46// python -m cogapp -d -e -omessage_packet.h -DHandlers=16 message_packet_generator.h
47//
48// See generate.bat
49//***************************************************************************
50
51#ifndef ETL_MESSAGE_PACKET_INCLUDED
52#define ETL_MESSAGE_PACKET_INCLUDED
53
54#include "platform.h"
55
56#if ETL_HAS_VIRTUAL_MESSAGES
57
58#include "message.h"
59#include "error_handler.h"
60#include "static_assert.h"
61#include "largest.h"
62#include "alignment.h"
63#include "utility.h"
64
65#include <stdint.h>
66
67namespace etl
68{
69#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
70 //***************************************************************************
71 // The definition for all message types.
72 //***************************************************************************
73 template <typename... TMessageTypes>
74 class message_packet
75 {
76
77 private:
78
79 template <typename T>
80 static constexpr bool IsMessagePacket = etl::is_same_v< etl::remove_const_t<etl::remove_reference_t<T>>, etl::message_packet<TMessageTypes...>>;
81
82 template <typename T>
83 static constexpr bool IsInMessageList = etl::is_one_of_v<etl::remove_const_t<etl::remove_reference_t<T>>, TMessageTypes...>;
84
85 template <typename T>
87
88 public:
89
90 //********************************************
92 message_packet()
93 : valid(false)
94 {
95 }
97
98 //********************************************
100 //********************************************
102 template <typename T, typename = typename etl::enable_if<IsIMessage<T> || IsInMessageList<T>, int>::type>
103 explicit message_packet(T&& msg)
104 : valid(true)
105 {
106 if constexpr (IsIMessage<T>)
107 {
108 if (accepts(msg))
109 {
110 add_new_message(etl::forward<T>(msg));
111 valid = true;
112 }
113 else
114 {
115 valid = false;
116 }
117
118 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
119 }
120 else if constexpr (IsInMessageList<T>)
121 {
122 add_new_message_type<T>(etl::forward<T>(msg));
123 }
124 else
125 {
126 ETL_STATIC_ASSERT(IsInMessageList<T>, "Message not in packet type list");
127 }
128 }
130
131 //**********************************************
132 message_packet(const message_packet& other)
133 {
134 valid = other.is_valid();
135
136 if (valid)
137 {
138 add_new_message(other.get());
139 }
140 }
141
142#if ETL_USING_CPP11
143 //**********************************************
144 message_packet(message_packet&& other)
145 {
146 valid = other.is_valid();
147
148 if (valid)
149 {
150 add_new_message(etl::move(other.get()));
151 }
152 }
153#endif
154
155 //**********************************************
156 void copy(const message_packet& other)
157 {
158 valid = other.is_valid();
159
160 if (valid)
161 {
162 add_new_message(other.get());
163 }
164 }
165
166 //**********************************************
167 void copy(message_packet&& other)
168 {
169 valid = other.is_valid();
170
171 if (valid)
172 {
173 add_new_message(etl::move(other.get()));
174 }
175 }
176
177 //**********************************************
179 message_packet& operator =(const message_packet& rhs)
180 {
181 delete_current_message();
182 valid = rhs.is_valid();
183 if (valid)
184 {
185 add_new_message(rhs.get());
186 }
187
188 return *this;
189 }
191
192 //**********************************************
194 message_packet& operator =(message_packet&& rhs)
195 {
196 delete_current_message();
197 valid = rhs.is_valid();
198 if (valid)
199 {
200 add_new_message(etl::move(rhs.get()));
201 }
202
203 return *this;
204 }
206
207 //********************************************
208 ~message_packet()
209 {
210 delete_current_message();
211 }
212
213 //********************************************
214 etl::imessage& get() ETL_NOEXCEPT
215 {
216 return *static_cast<etl::imessage*>(data);
217 }
218
219 //********************************************
220 const etl::imessage& get() const ETL_NOEXCEPT
221 {
222 return *static_cast<const etl::imessage*>(data);
223 }
224
225 //********************************************
226 bool is_valid() const
227 {
228 return valid;
229 }
230
231 //**********************************************
232 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
233 {
234 return (accepts_message<TMessageTypes::ID>(id) || ...);
235 }
236
237 //**********************************************
238 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
239 {
240 return accepts(msg.get_message_id());
241 }
242
243 //**********************************************
244 template <etl::message_id_t Id>
245 static ETL_CONSTEXPR bool accepts()
246 {
247 return (accepts_message<TMessageTypes::ID, Id>() || ...);
248 }
249
250 //**********************************************
251 template <typename TMessage>
252 static ETL_CONSTEXPR
254 accepts()
255 {
256 return accepts<TMessage::ID>();
257 }
258
259 enum
260 {
261 SIZE = etl::largest<TMessageTypes...>::size,
262 ALIGNMENT = etl::largest<TMessageTypes...>::alignment
263 };
264
265 private:
266
267 //**********************************************
268 template <etl::message_id_t Id1, etl::message_id_t Id2>
269 static bool accepts_message()
270 {
271 return Id1 == Id2;
272 }
273
274 //**********************************************
275 template <etl::message_id_t Id1>
276 static bool accepts_message(etl::message_id_t id2)
277 {
278 return Id1 == id2;
279 }
280
281 //********************************************
283 void delete_current_message()
284 {
285 if (valid)
286 {
287 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
288
289 pmsg->~imessage();
290 }
291 }
293
294 //********************************************
295 void add_new_message(const etl::imessage& msg)
296 {
297 (add_new_message_type<TMessageTypes>(msg) || ...);
298 }
299
300 //********************************************
301 void add_new_message(etl::imessage&& msg)
302 {
303 (add_new_message_type<TMessageTypes>(etl::move(msg)) || ...);
304 }
305
307 //********************************************
309 //********************************************
310 template <typename TMessage>
312 add_new_message_type(TMessage&& msg)
313 {
314 void* p = data;
316 }
318
320 //********************************************
321 template <typename TType>
322 bool add_new_message_type(const etl::imessage& msg)
323 {
324 if (TType::ID == msg.get_message_id())
325 {
326 void* p = data;
327 new (p) TType(static_cast<const TType&>(msg));
328 return true;
329 }
330 else
331 {
332 return false;
333 }
334 }
336
337 //********************************************
338 template <typename TType>
339 bool add_new_message_type(etl::imessage&& msg)
340 {
341 if (TType::ID == msg.get_message_id())
342 {
343 void* p = data;
344 new (p) TType(static_cast<TType&&>(msg));
345 return true;
346 }
347 else
348 {
349 return false;
350 }
351 }
352
354 bool valid;
355 };
356
357#else
358
359 //***************************************************************************
360 // The definition for all 16 message types.
361 //***************************************************************************
362 template <typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
363 typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
364 typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
365 typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
367 {
368 public:
369
370 //********************************************
373 : valid(false)
374 {
375 }
376 #include "private/diagnostic_pop.h"
377
378 //********************************************
380 explicit message_packet(const etl::imessage& msg)
381 {
382 if (accepts(msg))
383 {
384 add_new_message(msg);
385 valid = true;
386 }
387 else
388 {
389 valid = false;
390 }
391
392 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
393 }
394 #include "private/diagnostic_pop.h"
395
396 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
397 //********************************************
400 {
401 if (accepts(msg))
402 {
403 add_new_message(etl::move(msg));
404 valid = true;
405 }
406 else
407 {
408 valid = false;
409 }
410
411 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
412 }
413 #include "private/diagnostic_pop.h"
414 #endif
415
416 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
417 //********************************************
422 explicit message_packet(TMessage&& /*msg*/)
423 : valid(true)
424 {
425 // Not etl::message_packet, not etl::imessage and in typelist.
429
430 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
431 }
432 #include "private/diagnostic_pop.h"
433 #else
434 //********************************************
436 template <typename TMessage>
437 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> >::value &&
438 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
439 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value, int>::type = 0)
440 : valid(true)
441 {
442 // Not etl::message_packet, not etl::imessage and in typelist.
446
447 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
448 }
449 #include "private/diagnostic_pop.h"
450 #endif
451
452 //**********************************************
455 : valid(other.is_valid())
456 {
457 if (valid)
458 {
459 add_new_message(other.get());
460 }
461 }
462 #include "private/diagnostic_pop.h"
463
464 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
465 //**********************************************
468 : valid(other.is_valid())
469 {
470 if (valid)
471 {
472 add_new_message(etl::move(other.get()));
473 }
474 }
475 #include "private/diagnostic_pop.h"
476 #endif
477
478 //**********************************************
481 {
482 delete_current_message();
483 valid = rhs.is_valid();
484 if (valid)
485 {
486 add_new_message(rhs.get());
487 }
488
489 return *this;
490 }
491 #include "private/diagnostic_pop.h"
492
493 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
494 //**********************************************
497 {
498 delete_current_message();
499 valid = rhs.is_valid();
500 if (valid)
501 {
502 add_new_message(etl::move(rhs.get()));
503 }
504
505 return *this;
506 }
507 #include "private/diagnostic_pop.h"
508 #endif
509
510 //********************************************
512 {
513 delete_current_message();
514 }
515
516 //********************************************
517 etl::imessage& get() ETL_NOEXCEPT
518 {
519 return *static_cast<etl::imessage*>(data);
520 }
521
522 //********************************************
523 const etl::imessage& get() const ETL_NOEXCEPT
524 {
525 return *static_cast<const etl::imessage*>(data);
526 }
527
528 //********************************************
529 bool is_valid() const
530 {
531 return valid;
532 }
533
534 //**********************************************
535 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
536 {
537 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
538 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
539 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id ||
540 T13::ID == id || T14::ID == id || T15::ID == id || T16::ID == id;
541 }
542
543 //**********************************************
544 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
545 {
546 return accepts(msg.get_message_id());
547 }
548
549 //**********************************************
550 template <etl::message_id_t Id>
551 static ETL_CONSTEXPR bool accepts()
552 {
553 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
554 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
555 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id ||
556 T13::ID == Id || T14::ID == Id || T15::ID == Id || T16::ID == Id;
557 }
558
559 //**********************************************
560 template <typename TMessage>
561 static ETL_CONSTEXPR
563 accepts()
564 {
565 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
566 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
567 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID ||
568 T13::ID == TMessage::ID || T14::ID == TMessage::ID || T15::ID == TMessage::ID || T16::ID == TMessage::ID;
569 }
570
571 enum
572 {
575 };
576
577 private:
578
579 //********************************************
581 void delete_current_message()
582 {
583 if (valid)
584 {
585 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
586
587 pmsg->~imessage();
588 }
589 }
590 #include "private/diagnostic_pop.h"
591
592 //********************************************
593 void add_new_message(const etl::imessage& msg)
594 {
595 const size_t id = msg.get_message_id();
596 void* p = data;
597
598 switch (id)
599 {
600 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
601 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
602 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
603 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
604 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
605 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
606 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
607 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
608 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
609 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
610 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
611 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
612 case T13::ID: ::new (p) T13(static_cast<const T13&>(msg)); break;
613 case T14::ID: ::new (p) T14(static_cast<const T14&>(msg)); break;
614 case T15::ID: ::new (p) T15(static_cast<const T15&>(msg)); break;
615 case T16::ID: ::new (p) T16(static_cast<const T16&>(msg)); break;
616 default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;
617 }
618 }
619
620 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
621 //********************************************
622 void add_new_message(etl::imessage&& msg)
623 {
624 const size_t id = msg.get_message_id();
625 void* p = data;
626
627 switch (id)
628 {
629 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
630 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
631 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
632 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
633 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
634 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
635 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
636 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
637 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
638 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
639 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
640 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
641 case T13::ID: ::new (p) T13(static_cast<T13&&>(msg)); break;
642 case T14::ID: ::new (p) T14(static_cast<T14&&>(msg)); break;
643 case T15::ID: ::new (p) T15(static_cast<T15&&>(msg)); break;
644 case T16::ID: ::new (p) T16(static_cast<T16&&>(msg)); break;
645 default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;
646 }
647 }
648 #endif
649
651 bool valid;
652 };
653
654 //***************************************************************************
655 // Specialisation for 15 message types.
656 //***************************************************************************
657 template <typename T1, typename T2, typename T3, typename T4,
658 typename T5, typename T6, typename T7, typename T8,
659 typename T9, typename T10, typename T11, typename T12,
660 typename T13, typename T14, typename T15>
661 class message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, void>
662 {
663 public:
664
665 //********************************************
668 : valid(false)
669 {
670 }
671 #include "private/diagnostic_pop.h"
672
673 //********************************************
675 explicit message_packet(const etl::imessage& msg)
676 {
677 if (accepts(msg))
678 {
679 add_new_message(msg);
680 valid = true;
681 }
682 else
683 {
684 valid = false;
685 }
686
687 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
688 }
689 #include "private/diagnostic_pop.h"
690
691 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
692 //********************************************
695 {
696 if (accepts(msg))
697 {
698 add_new_message(etl::move(msg));
699 valid = true;
700 }
701 else
702 {
703 valid = false;
704 }
705
706 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
707 }
708 #include "private/diagnostic_pop.h"
709 #endif
710
711 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
712 //********************************************
717 explicit message_packet(TMessage&& /*msg*/)
718 : valid(true)
719 {
720 // Not etl::message_packet, not etl::imessage and in typelist.
724
725 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
726 }
727 #include "private/diagnostic_pop.h"
728 #else
729 //********************************************
731 template <typename TMessage>
732 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::value &&
733 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
734 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::value, int>::type = 0)
735 : valid(true)
736 {
737 // Not etl::message_packet, not etl::imessage and in typelist.
741
742 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
743 }
744 #include "private/diagnostic_pop.h"
745 #endif
746
747 //**********************************************
750 : valid(other.is_valid())
751 {
752 if (valid)
753 {
754 add_new_message(other.get());
755 }
756 }
757 #include "private/diagnostic_pop.h"
758
759 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
760 //**********************************************
763 : valid(other.is_valid())
764 {
765 if (valid)
766 {
767 add_new_message(etl::move(other.get()));
768 }
769 }
770 #include "private/diagnostic_pop.h"
771 #endif
772
773 //**********************************************
776 {
777 delete_current_message();
778 valid = rhs.is_valid();
779 if (valid)
780 {
781 add_new_message(rhs.get());
782 }
783
784 return *this;
785 }
786 #include "private/diagnostic_pop.h"
787
788 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
789 //**********************************************
792 {
793 delete_current_message();
794 valid = rhs.is_valid();
795 if (valid)
796 {
797 add_new_message(etl::move(rhs.get()));
798 }
799
800 return *this;
801 }
802 #include "private/diagnostic_pop.h"
803 #endif
804
805 //********************************************
807 {
808 delete_current_message();
809 }
810
811 //********************************************
812 etl::imessage& get() ETL_NOEXCEPT
813 {
814 return *static_cast<etl::imessage*>(data);
815 }
816
817 //********************************************
818 const etl::imessage& get() const ETL_NOEXCEPT
819 {
820 return *static_cast<const etl::imessage*>(data);
821 }
822
823 //********************************************
824 bool is_valid() const
825 {
826 return valid;
827 }
828
829 //**********************************************
830 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
831 {
832 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
833 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
834 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id ||
835 T13::ID == id || T14::ID == id || T15::ID == id;
836 }
837
838 //**********************************************
839 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
840 {
841 return accepts(msg.get_message_id());
842 }
843
844 //**********************************************
845 template <etl::message_id_t Id>
846 static ETL_CONSTEXPR bool accepts()
847 {
848 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
849 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
850 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id ||
851 T13::ID == Id || T14::ID == Id || T15::ID == Id;
852 }
853
854 //**********************************************
855 template <typename TMessage>
856 static ETL_CONSTEXPR
858 accepts()
859 {
860 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
861 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
862 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID ||
863 T13::ID == TMessage::ID || T14::ID == TMessage::ID || T15::ID == TMessage::ID;
864 }
865
866 enum
867 {
870 };
871
872 private:
873
874 //********************************************
876 void delete_current_message()
877 {
878 if (valid)
879 {
880 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
881
882 pmsg->~imessage();
883 }
884 }
885 #include "private/diagnostic_pop.h"
886
887 //********************************************
888 void add_new_message(const etl::imessage& msg)
889 {
890 const size_t id = msg.get_message_id();
891 void* p = data;
892
893 switch (id)
894 {
895 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
896 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
897 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
898 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
899 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
900 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
901 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
902 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
903 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
904 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
905 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
906 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
907 case T13::ID: ::new (p) T13(static_cast<const T13&>(msg)); break;
908 case T14::ID: ::new (p) T14(static_cast<const T14&>(msg)); break;
909 case T15::ID: ::new (p) T15(static_cast<const T15&>(msg)); break;
910 default: break;
911 }
912 }
913
914 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
915 //********************************************
916 void add_new_message(etl::imessage&& msg)
917 {
918 const size_t id = msg.get_message_id();
919 void* p = data;
920
921 switch (id)
922 {
923 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
924 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
925 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
926 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
927 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
928 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
929 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
930 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
931 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
932 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
933 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
934 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
935 case T13::ID: ::new (p) T13(static_cast<T13&&>(msg)); break;
936 case T14::ID: ::new (p) T14(static_cast<T14&&>(msg)); break;
937 case T15::ID: ::new (p) T15(static_cast<T15&&>(msg)); break;
938 default: break;
939 }
940 }
941 #endif
942
944 bool valid;
945 };
946
947 //***************************************************************************
948 // Specialisation for 14 message types.
949 //***************************************************************************
950 template <typename T1, typename T2, typename T3, typename T4,
951 typename T5, typename T6, typename T7, typename T8,
952 typename T9, typename T10, typename T11, typename T12,
953 typename T13, typename T14>
955 {
956 public:
957
958 //********************************************
961 : valid(false)
962 {
963 }
964 #include "private/diagnostic_pop.h"
965
966 //********************************************
968 explicit message_packet(const etl::imessage& msg)
969 {
970 if (accepts(msg))
971 {
972 add_new_message(msg);
973 valid = true;
974 }
975 else
976 {
977 valid = false;
978 }
979
980 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
981 }
982 #include "private/diagnostic_pop.h"
983
984 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
985 //********************************************
988 {
989 if (accepts(msg))
990 {
991 add_new_message(etl::move(msg));
992 valid = true;
993 }
994 else
995 {
996 valid = false;
997 }
998
999 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1000 }
1001 #include "private/diagnostic_pop.h"
1002 #endif
1003
1004 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
1005 //********************************************
1010 explicit message_packet(TMessage&& /*msg*/)
1011 : valid(true)
1012 {
1013 // Not etl::message_packet, not etl::imessage and in typelist.
1017
1018 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1019 }
1020 #include "private/diagnostic_pop.h"
1021 #else
1022 //********************************************
1024 template <typename TMessage>
1025 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> >::value &&
1026 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
1027 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>::value, int>::type = 0)
1028 : valid(true)
1029 {
1030 // Not etl::message_packet, not etl::imessage and in typelist.
1034
1035 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1036 }
1037 #include "private/diagnostic_pop.h"
1038 #endif
1039
1040 //**********************************************
1043 : valid(other.is_valid())
1044 {
1045 if (valid)
1046 {
1047 add_new_message(other.get());
1048 }
1049 }
1050 #include "private/diagnostic_pop.h"
1051
1052 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1053 //**********************************************
1056 : valid(other.is_valid())
1057 {
1058 if (valid)
1059 {
1060 add_new_message(etl::move(other.get()));
1061 }
1062 }
1063 #include "private/diagnostic_pop.h"
1064 #endif
1065
1066 //**********************************************
1069 {
1070 delete_current_message();
1071 valid = rhs.is_valid();
1072 if (valid)
1073 {
1074 add_new_message(rhs.get());
1075 }
1076
1077 return *this;
1078 }
1079 #include "private/diagnostic_pop.h"
1080
1081 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1082 //**********************************************
1085 {
1086 delete_current_message();
1087 valid = rhs.is_valid();
1088 if (valid)
1089 {
1090 add_new_message(etl::move(rhs.get()));
1091 }
1092
1093 return *this;
1094 }
1095 #include "private/diagnostic_pop.h"
1096 #endif
1097
1098 //********************************************
1100 {
1101 delete_current_message();
1102 }
1103
1104 //********************************************
1105 etl::imessage& get() ETL_NOEXCEPT
1106 {
1107 return *static_cast<etl::imessage*>(data);
1108 }
1109
1110 //********************************************
1111 const etl::imessage& get() const ETL_NOEXCEPT
1112 {
1113 return *static_cast<const etl::imessage*>(data);
1114 }
1115
1116 //********************************************
1117 bool is_valid() const
1118 {
1119 return valid;
1120 }
1121
1122 //**********************************************
1123 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
1124 {
1125 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
1126 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
1127 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id ||
1128 T13::ID == id || T14::ID == id;
1129 }
1130
1131 //**********************************************
1132 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
1133 {
1134 return accepts(msg.get_message_id());
1135 }
1136
1137 //**********************************************
1138 template <etl::message_id_t Id>
1139 static ETL_CONSTEXPR bool accepts()
1140 {
1141 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
1142 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
1143 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id ||
1144 T13::ID == Id || T14::ID == Id;
1145 }
1146
1147 //**********************************************
1148 template <typename TMessage>
1149 static ETL_CONSTEXPR
1151 accepts()
1152 {
1153 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
1154 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
1155 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID ||
1156 T13::ID == TMessage::ID || T14::ID == TMessage::ID;
1157 }
1158
1159 enum
1160 {
1163 };
1164
1165 private:
1166
1167 //********************************************
1169 void delete_current_message()
1170 {
1171 if (valid)
1172 {
1173 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
1174
1175 pmsg->~imessage();
1176 }
1177 }
1178 #include "private/diagnostic_pop.h"
1179
1180 //********************************************
1181 void add_new_message(const etl::imessage& msg)
1182 {
1183 const size_t id = msg.get_message_id();
1184 void* p = data;
1185
1186 switch (id)
1187 {
1188 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
1189 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
1190 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
1191 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
1192 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
1193 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
1194 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
1195 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
1196 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
1197 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
1198 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
1199 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
1200 case T13::ID: ::new (p) T13(static_cast<const T13&>(msg)); break;
1201 case T14::ID: ::new (p) T14(static_cast<const T14&>(msg)); break;
1202 default: break;
1203 }
1204 }
1205
1206 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1207 //********************************************
1208 void add_new_message(etl::imessage&& msg)
1209 {
1210 const size_t id = msg.get_message_id();
1211 void* p = data;
1212
1213 switch (id)
1214 {
1215 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
1216 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
1217 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
1218 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
1219 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
1220 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
1221 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
1222 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
1223 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
1224 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
1225 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
1226 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
1227 case T13::ID: ::new (p) T13(static_cast<T13&&>(msg)); break;
1228 case T14::ID: ::new (p) T14(static_cast<T14&&>(msg)); break;
1229 default: break;
1230 }
1231 }
1232 #endif
1233
1235 bool valid;
1236 };
1237
1238 //***************************************************************************
1239 // Specialisation for 13 message types.
1240 //***************************************************************************
1241 template <typename T1, typename T2, typename T3, typename T4,
1242 typename T5, typename T6, typename T7, typename T8,
1243 typename T9, typename T10, typename T11, typename T12,
1244 typename T13>
1246 {
1247 public:
1248
1249 //********************************************
1252 : valid(false)
1253 {
1254 }
1255 #include "private/diagnostic_pop.h"
1256
1257 //********************************************
1259 explicit message_packet(const etl::imessage& msg)
1260 {
1261 if (accepts(msg))
1262 {
1263 add_new_message(msg);
1264 valid = true;
1265 }
1266 else
1267 {
1268 valid = false;
1269 }
1270
1271 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1272 }
1273 #include "private/diagnostic_pop.h"
1274
1275 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1276 //********************************************
1278 explicit message_packet(etl::imessage&& msg)
1279 {
1280 if (accepts(msg))
1281 {
1282 add_new_message(etl::move(msg));
1283 valid = true;
1284 }
1285 else
1286 {
1287 valid = false;
1288 }
1289
1290 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1291 }
1292 #include "private/diagnostic_pop.h"
1293 #endif
1294
1295 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
1296 //********************************************
1301 explicit message_packet(TMessage&& /*msg*/)
1302 : valid(true)
1303 {
1304 // Not etl::message_packet, not etl::imessage and in typelist.
1308
1309 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1310 }
1311 #include "private/diagnostic_pop.h"
1312 #else
1313 //********************************************
1315 template <typename TMessage>
1316 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> >::value &&
1317 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
1318 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>::value, int>::type = 0)
1319 : valid(true)
1320 {
1321 // Not etl::message_packet, not etl::imessage and in typelist.
1325
1326 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1327 }
1328 #include "private/diagnostic_pop.h"
1329 #endif
1330
1331 //**********************************************
1334 : valid(other.is_valid())
1335 {
1336 if (valid)
1337 {
1338 add_new_message(other.get());
1339 }
1340 }
1341 #include "private/diagnostic_pop.h"
1342
1343 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1344 //**********************************************
1347 : valid(other.is_valid())
1348 {
1349 if (valid)
1350 {
1351 add_new_message(etl::move(other.get()));
1352 }
1353 }
1354 #include "private/diagnostic_pop.h"
1355 #endif
1356
1357 //**********************************************
1360 {
1361 delete_current_message();
1362 valid = rhs.is_valid();
1363 if (valid)
1364 {
1365 add_new_message(rhs.get());
1366 }
1367
1368 return *this;
1369 }
1370 #include "private/diagnostic_pop.h"
1371
1372 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1373 //**********************************************
1376 {
1377 delete_current_message();
1378 valid = rhs.is_valid();
1379 if (valid)
1380 {
1381 add_new_message(etl::move(rhs.get()));
1382 }
1383
1384 return *this;
1385 }
1386 #include "private/diagnostic_pop.h"
1387 #endif
1388
1389 //********************************************
1391 {
1392 delete_current_message();
1393 }
1394
1395 //********************************************
1396 etl::imessage& get() ETL_NOEXCEPT
1397 {
1398 return *static_cast<etl::imessage*>(data);
1399 }
1400
1401 //********************************************
1402 const etl::imessage& get() const ETL_NOEXCEPT
1403 {
1404 return *static_cast<const etl::imessage*>(data);
1405 }
1406
1407 //********************************************
1408 bool is_valid() const
1409 {
1410 return valid;
1411 }
1412
1413 //**********************************************
1414 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
1415 {
1416 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
1417 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
1418 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id ||
1419 T13::ID == id;
1420 }
1421
1422 //**********************************************
1423 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
1424 {
1425 return accepts(msg.get_message_id());
1426 }
1427
1428 //**********************************************
1429 template <etl::message_id_t Id>
1430 static ETL_CONSTEXPR bool accepts()
1431 {
1432 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
1433 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
1434 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id ||
1435 T13::ID == Id;
1436 }
1437
1438 //**********************************************
1439 template <typename TMessage>
1440 static ETL_CONSTEXPR
1442 accepts()
1443 {
1444 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
1445 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
1446 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID ||
1447 T13::ID == TMessage::ID;
1448 }
1449
1450 enum
1451 {
1454 };
1455
1456 private:
1457
1458 //********************************************
1460 void delete_current_message()
1461 {
1462 if (valid)
1463 {
1464 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
1465
1466 pmsg->~imessage();
1467 }
1468 }
1469 #include "private/diagnostic_pop.h"
1470
1471 //********************************************
1472 void add_new_message(const etl::imessage& msg)
1473 {
1474 const size_t id = msg.get_message_id();
1475 void* p = data;
1476
1477 switch (id)
1478 {
1479 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
1480 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
1481 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
1482 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
1483 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
1484 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
1485 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
1486 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
1487 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
1488 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
1489 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
1490 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
1491 case T13::ID: ::new (p) T13(static_cast<const T13&>(msg)); break;
1492 default: break;
1493 }
1494 }
1495
1496 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1497 //********************************************
1498 void add_new_message(etl::imessage&& msg)
1499 {
1500 const size_t id = msg.get_message_id();
1501 void* p = data;
1502
1503 switch (id)
1504 {
1505 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
1506 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
1507 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
1508 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
1509 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
1510 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
1511 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
1512 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
1513 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
1514 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
1515 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
1516 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
1517 case T13::ID: ::new (p) T13(static_cast<T13&&>(msg)); break;
1518 default: break;
1519 }
1520 }
1521 #endif
1522
1524 bool valid;
1525 };
1526
1527 //***************************************************************************
1528 // Specialisation for 12 message types.
1529 //***************************************************************************
1530 template <typename T1, typename T2, typename T3, typename T4,
1531 typename T5, typename T6, typename T7, typename T8,
1532 typename T9, typename T10, typename T11, typename T12>
1534 {
1535 public:
1536
1537 //********************************************
1540 : valid(false)
1541 {
1542 }
1543 #include "private/diagnostic_pop.h"
1544
1545 //********************************************
1547 explicit message_packet(const etl::imessage& msg)
1548 {
1549 if (accepts(msg))
1550 {
1551 add_new_message(msg);
1552 valid = true;
1553 }
1554 else
1555 {
1556 valid = false;
1557 }
1558
1559 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1560 }
1561 #include "private/diagnostic_pop.h"
1562
1563 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1564 //********************************************
1566 explicit message_packet(etl::imessage&& msg)
1567 {
1568 if (accepts(msg))
1569 {
1570 add_new_message(etl::move(msg));
1571 valid = true;
1572 }
1573 else
1574 {
1575 valid = false;
1576 }
1577
1578 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1579 }
1580 #include "private/diagnostic_pop.h"
1581 #endif
1582
1583 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
1584 //********************************************
1589 explicit message_packet(TMessage&& /*msg*/)
1590 : valid(true)
1591 {
1592 // Not etl::message_packet, not etl::imessage and in typelist.
1596
1597 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1598 }
1599 #include "private/diagnostic_pop.h"
1600 #else
1601 //********************************************
1603 template <typename TMessage>
1604 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> >::value &&
1605 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
1606 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>::value, int>::type = 0)
1607 : valid(true)
1608 {
1609 // Not etl::message_packet, not etl::imessage and in typelist.
1613
1614 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1615 }
1616 #include "private/diagnostic_pop.h"
1617 #endif
1618
1619 //**********************************************
1622 : valid(other.is_valid())
1623 {
1624 if (valid)
1625 {
1626 add_new_message(other.get());
1627 }
1628 }
1629 #include "private/diagnostic_pop.h"
1630
1631 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1632 //**********************************************
1635 : valid(other.is_valid())
1636 {
1637 if (valid)
1638 {
1639 add_new_message(etl::move(other.get()));
1640 }
1641 }
1642 #include "private/diagnostic_pop.h"
1643 #endif
1644
1645 //**********************************************
1648 {
1649 delete_current_message();
1650 valid = rhs.is_valid();
1651 if (valid)
1652 {
1653 add_new_message(rhs.get());
1654 }
1655
1656 return *this;
1657 }
1658 #include "private/diagnostic_pop.h"
1659
1660 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1661 //**********************************************
1664 {
1665 delete_current_message();
1666 valid = rhs.is_valid();
1667 if (valid)
1668 {
1669 add_new_message(etl::move(rhs.get()));
1670 }
1671
1672 return *this;
1673 }
1674 #include "private/diagnostic_pop.h"
1675 #endif
1676
1677 //********************************************
1679 {
1680 delete_current_message();
1681 }
1682
1683 //********************************************
1684 etl::imessage& get() ETL_NOEXCEPT
1685 {
1686 return *static_cast<etl::imessage*>(data);
1687 }
1688
1689 //********************************************
1690 const etl::imessage& get() const ETL_NOEXCEPT
1691 {
1692 return *static_cast<const etl::imessage*>(data);
1693 }
1694
1695 //********************************************
1696 bool is_valid() const
1697 {
1698 return valid;
1699 }
1700
1701 //**********************************************
1702 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
1703 {
1704 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
1705 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
1706 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id;
1707 }
1708
1709 //**********************************************
1710 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
1711 {
1712 return accepts(msg.get_message_id());
1713 }
1714
1715 //**********************************************
1716 template <etl::message_id_t Id>
1717 static ETL_CONSTEXPR bool accepts()
1718 {
1719 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
1720 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
1721 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id;
1722 }
1723
1724 //**********************************************
1725 template <typename TMessage>
1726 static ETL_CONSTEXPR
1728 accepts()
1729 {
1730 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
1731 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
1732 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID;
1733 }
1734
1735 enum
1736 {
1739 };
1740
1741 private:
1742
1743 //********************************************
1745 void delete_current_message()
1746 {
1747 if (valid)
1748 {
1749 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
1750
1751 pmsg->~imessage();
1752 }
1753 }
1754 #include "private/diagnostic_pop.h"
1755
1756 //********************************************
1757 void add_new_message(const etl::imessage& msg)
1758 {
1759 const size_t id = msg.get_message_id();
1760 void* p = data;
1761
1762 switch (id)
1763 {
1764 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
1765 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
1766 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
1767 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
1768 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
1769 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
1770 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
1771 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
1772 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
1773 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
1774 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
1775 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
1776 default: break;
1777 }
1778 }
1779
1780 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1781 //********************************************
1782 void add_new_message(etl::imessage&& msg)
1783 {
1784 const size_t id = msg.get_message_id();
1785 void* p = data;
1786
1787 switch (id)
1788 {
1789 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
1790 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
1791 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
1792 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
1793 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
1794 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
1795 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
1796 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
1797 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
1798 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
1799 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
1800 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
1801 default: break;
1802 }
1803 }
1804 #endif
1805
1807 bool valid;
1808 };
1809
1810 //***************************************************************************
1811 // Specialisation for 11 message types.
1812 //***************************************************************************
1813 template <typename T1, typename T2, typename T3, typename T4,
1814 typename T5, typename T6, typename T7, typename T8,
1815 typename T9, typename T10, typename T11>
1817 {
1818 public:
1819
1820 //********************************************
1823 : valid(false)
1824 {
1825 }
1826 #include "private/diagnostic_pop.h"
1827
1828 //********************************************
1830 explicit message_packet(const etl::imessage& msg)
1831 {
1832 if (accepts(msg))
1833 {
1834 add_new_message(msg);
1835 valid = true;
1836 }
1837 else
1838 {
1839 valid = false;
1840 }
1841
1842 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1843 }
1844 #include "private/diagnostic_pop.h"
1845
1846 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1847 //********************************************
1849 explicit message_packet(etl::imessage&& msg)
1850 {
1851 if (accepts(msg))
1852 {
1853 add_new_message(etl::move(msg));
1854 valid = true;
1855 }
1856 else
1857 {
1858 valid = false;
1859 }
1860
1861 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1862 }
1863 #include "private/diagnostic_pop.h"
1864 #endif
1865
1866 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
1867 //********************************************
1872 explicit message_packet(TMessage&& /*msg*/)
1873 : valid(true)
1874 {
1875 // Not etl::message_packet, not etl::imessage and in typelist.
1879
1880 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1881 }
1882 #include "private/diagnostic_pop.h"
1883 #else
1884 //********************************************
1886 template <typename TMessage>
1887 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> >::value &&
1888 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
1889 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::value, int>::type = 0)
1890 : valid(true)
1891 {
1892 // Not etl::message_packet, not etl::imessage and in typelist.
1896
1897 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1898 }
1899 #include "private/diagnostic_pop.h"
1900 #endif
1901
1902 //**********************************************
1905 : valid(other.is_valid())
1906 {
1907 if (valid)
1908 {
1909 add_new_message(other.get());
1910 }
1911 }
1912 #include "private/diagnostic_pop.h"
1913
1914 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1915 //**********************************************
1918 : valid(other.is_valid())
1919 {
1920 if (valid)
1921 {
1922 add_new_message(etl::move(other.get()));
1923 }
1924 }
1925 #include "private/diagnostic_pop.h"
1926 #endif
1927
1928 //**********************************************
1931 {
1932 delete_current_message();
1933 valid = rhs.is_valid();
1934 if (valid)
1935 {
1936 add_new_message(rhs.get());
1937 }
1938
1939 return *this;
1940 }
1941 #include "private/diagnostic_pop.h"
1942
1943 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1944 //**********************************************
1947 {
1948 delete_current_message();
1949 valid = rhs.is_valid();
1950 if (valid)
1951 {
1952 add_new_message(etl::move(rhs.get()));
1953 }
1954
1955 return *this;
1956 }
1957 #include "private/diagnostic_pop.h"
1958 #endif
1959
1960 //********************************************
1962 {
1963 delete_current_message();
1964 }
1965
1966 //********************************************
1967 etl::imessage& get() ETL_NOEXCEPT
1968 {
1969 return *static_cast<etl::imessage*>(data);
1970 }
1971
1972 //********************************************
1973 const etl::imessage& get() const ETL_NOEXCEPT
1974 {
1975 return *static_cast<const etl::imessage*>(data);
1976 }
1977
1978 //********************************************
1979 bool is_valid() const
1980 {
1981 return valid;
1982 }
1983
1984 //**********************************************
1985 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
1986 {
1987 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
1988 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
1989 T9::ID == id || T10::ID == id || T11::ID == id;
1990 }
1991
1992 //**********************************************
1993 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
1994 {
1995 return accepts(msg.get_message_id());
1996 }
1997
1998 //**********************************************
1999 template <etl::message_id_t Id>
2000 static ETL_CONSTEXPR bool accepts()
2001 {
2002 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
2003 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
2004 T9::ID == Id || T10::ID == Id || T11::ID == Id;
2005 }
2006
2007 //**********************************************
2008 template <typename TMessage>
2009 static ETL_CONSTEXPR
2011 accepts()
2012 {
2013 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
2014 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
2015 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID;
2016 }
2017
2018 enum
2019 {
2022 };
2023
2024 private:
2025
2026 //********************************************
2028 void delete_current_message()
2029 {
2030 if (valid)
2031 {
2032 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
2033
2034 pmsg->~imessage();
2035 }
2036 }
2037 #include "private/diagnostic_pop.h"
2038
2039 //********************************************
2040 void add_new_message(const etl::imessage& msg)
2041 {
2042 const size_t id = msg.get_message_id();
2043 void* p = data;
2044
2045 switch (id)
2046 {
2047 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
2048 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
2049 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
2050 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
2051 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
2052 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
2053 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
2054 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
2055 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
2056 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
2057 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
2058 default: break;
2059 }
2060 }
2061
2062 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2063 //********************************************
2064 void add_new_message(etl::imessage&& msg)
2065 {
2066 const size_t id = msg.get_message_id();
2067 void* p = data;
2068
2069 switch (id)
2070 {
2071 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
2072 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
2073 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
2074 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
2075 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
2076 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
2077 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
2078 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
2079 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
2080 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
2081 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
2082 default: break;
2083 }
2084 }
2085 #endif
2086
2088 bool valid;
2089 };
2090
2091 //***************************************************************************
2092 // Specialisation for 10 message types.
2093 //***************************************************************************
2094 template <typename T1, typename T2, typename T3, typename T4,
2095 typename T5, typename T6, typename T7, typename T8,
2096 typename T9, typename T10>
2098 {
2099 public:
2100
2101 //********************************************
2104 : valid(false)
2105 {
2106 }
2107 #include "private/diagnostic_pop.h"
2108
2109 //********************************************
2111 explicit message_packet(const etl::imessage& msg)
2112 {
2113 if (accepts(msg))
2114 {
2115 add_new_message(msg);
2116 valid = true;
2117 }
2118 else
2119 {
2120 valid = false;
2121 }
2122
2123 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2124 }
2125 #include "private/diagnostic_pop.h"
2126
2127 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2128 //********************************************
2130 explicit message_packet(etl::imessage&& msg)
2131 {
2132 if (accepts(msg))
2133 {
2134 add_new_message(etl::move(msg));
2135 valid = true;
2136 }
2137 else
2138 {
2139 valid = false;
2140 }
2141
2142 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2143 }
2144 #include "private/diagnostic_pop.h"
2145 #endif
2146
2147 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
2148 //********************************************
2153 explicit message_packet(TMessage&& /*msg*/)
2154 : valid(true)
2155 {
2156 // Not etl::message_packet, not etl::imessage and in typelist.
2160
2161 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2162 }
2163 #include "private/diagnostic_pop.h"
2164 #else
2165 //********************************************
2167 template <typename TMessage>
2168 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> >::value &&
2169 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
2170 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::value, int>::type = 0)
2171 : valid(true)
2172 {
2173 // Not etl::message_packet, not etl::imessage and in typelist.
2177
2178 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2179 }
2180 #include "private/diagnostic_pop.h"
2181 #endif
2182
2183 //**********************************************
2186 : valid(other.is_valid())
2187 {
2188 if (valid)
2189 {
2190 add_new_message(other.get());
2191 }
2192 }
2193 #include "private/diagnostic_pop.h"
2194
2195 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2196 //**********************************************
2199 : valid(other.is_valid())
2200 {
2201 if (valid)
2202 {
2203 add_new_message(etl::move(other.get()));
2204 }
2205 }
2206 #include "private/diagnostic_pop.h"
2207 #endif
2208
2209 //**********************************************
2212 {
2213 delete_current_message();
2214 valid = rhs.is_valid();
2215 if (valid)
2216 {
2217 add_new_message(rhs.get());
2218 }
2219
2220 return *this;
2221 }
2222 #include "private/diagnostic_pop.h"
2223
2224 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2225 //**********************************************
2228 {
2229 delete_current_message();
2230 valid = rhs.is_valid();
2231 if (valid)
2232 {
2233 add_new_message(etl::move(rhs.get()));
2234 }
2235
2236 return *this;
2237 }
2238 #include "private/diagnostic_pop.h"
2239 #endif
2240
2241 //********************************************
2243 {
2244 delete_current_message();
2245 }
2246
2247 //********************************************
2248 etl::imessage& get() ETL_NOEXCEPT
2249 {
2250 return *static_cast<etl::imessage*>(data);
2251 }
2252
2253 //********************************************
2254 const etl::imessage& get() const ETL_NOEXCEPT
2255 {
2256 return *static_cast<const etl::imessage*>(data);
2257 }
2258
2259 //********************************************
2260 bool is_valid() const
2261 {
2262 return valid;
2263 }
2264
2265 //**********************************************
2266 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
2267 {
2268 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
2269 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
2270 T9::ID == id || T10::ID == id;
2271 }
2272
2273 //**********************************************
2274 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
2275 {
2276 return accepts(msg.get_message_id());
2277 }
2278
2279 //**********************************************
2280 template <etl::message_id_t Id>
2281 static ETL_CONSTEXPR bool accepts()
2282 {
2283 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
2284 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
2285 T9::ID == Id || T10::ID == Id;
2286 }
2287
2288 //**********************************************
2289 template <typename TMessage>
2290 static ETL_CONSTEXPR
2292 accepts()
2293 {
2294 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
2295 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
2296 T9::ID == TMessage::ID || T10::ID == TMessage::ID;
2297 }
2298
2299 enum
2300 {
2303 };
2304
2305 private:
2306
2307 //********************************************
2309 void delete_current_message()
2310 {
2311 if (valid)
2312 {
2313 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
2314
2315 pmsg->~imessage();
2316 }
2317 }
2318 #include "private/diagnostic_pop.h"
2319
2320 //********************************************
2321 void add_new_message(const etl::imessage& msg)
2322 {
2323 const size_t id = msg.get_message_id();
2324 void* p = data;
2325
2326 switch (id)
2327 {
2328 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
2329 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
2330 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
2331 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
2332 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
2333 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
2334 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
2335 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
2336 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
2337 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
2338 default: break;
2339 }
2340 }
2341
2342 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2343 //********************************************
2344 void add_new_message(etl::imessage&& msg)
2345 {
2346 const size_t id = msg.get_message_id();
2347 void* p = data;
2348
2349 switch (id)
2350 {
2351 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
2352 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
2353 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
2354 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
2355 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
2356 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
2357 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
2358 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
2359 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
2360 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
2361 default: break;
2362 }
2363 }
2364 #endif
2365
2367 bool valid;
2368 };
2369
2370 //***************************************************************************
2371 // Specialisation for 9 message types.
2372 //***************************************************************************
2373 template <typename T1, typename T2, typename T3, typename T4,
2374 typename T5, typename T6, typename T7, typename T8,
2375 typename T9>
2377 {
2378 public:
2379
2380 //********************************************
2383 : valid(false)
2384 {
2385 }
2386 #include "private/diagnostic_pop.h"
2387
2388 //********************************************
2390 explicit message_packet(const etl::imessage& msg)
2391 {
2392 if (accepts(msg))
2393 {
2394 add_new_message(msg);
2395 valid = true;
2396 }
2397 else
2398 {
2399 valid = false;
2400 }
2401
2402 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2403 }
2404 #include "private/diagnostic_pop.h"
2405
2406 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2407 //********************************************
2409 explicit message_packet(etl::imessage&& msg)
2410 {
2411 if (accepts(msg))
2412 {
2413 add_new_message(etl::move(msg));
2414 valid = true;
2415 }
2416 else
2417 {
2418 valid = false;
2419 }
2420
2421 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2422 }
2423 #include "private/diagnostic_pop.h"
2424 #endif
2425
2426 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
2427 //********************************************
2432 explicit message_packet(TMessage&& /*msg*/)
2433 : valid(true)
2434 {
2435 // Not etl::message_packet, not etl::imessage and in typelist.
2439
2440 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2441 }
2442 #include "private/diagnostic_pop.h"
2443 #else
2444 //********************************************
2446 template <typename TMessage>
2447 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9> >::value &&
2448 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
2449 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9>::value, int>::type = 0)
2450 : valid(true)
2451 {
2452 // Not etl::message_packet, not etl::imessage and in typelist.
2456
2457 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2458 }
2459 #include "private/diagnostic_pop.h"
2460 #endif
2461
2462 //**********************************************
2465 : valid(other.is_valid())
2466 {
2467 if (valid)
2468 {
2469 add_new_message(other.get());
2470 }
2471 }
2472 #include "private/diagnostic_pop.h"
2473
2474 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2475 //**********************************************
2478 : valid(other.is_valid())
2479 {
2480 if (valid)
2481 {
2482 add_new_message(etl::move(other.get()));
2483 }
2484 }
2485 #include "private/diagnostic_pop.h"
2486 #endif
2487
2488 //**********************************************
2491 {
2492 delete_current_message();
2493 valid = rhs.is_valid();
2494 if (valid)
2495 {
2496 add_new_message(rhs.get());
2497 }
2498
2499 return *this;
2500 }
2501 #include "private/diagnostic_pop.h"
2502
2503 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2504 //**********************************************
2507 {
2508 delete_current_message();
2509 valid = rhs.is_valid();
2510 if (valid)
2511 {
2512 add_new_message(etl::move(rhs.get()));
2513 }
2514
2515 return *this;
2516 }
2517 #include "private/diagnostic_pop.h"
2518 #endif
2519
2520 //********************************************
2522 {
2523 delete_current_message();
2524 }
2525
2526 //********************************************
2527 etl::imessage& get() ETL_NOEXCEPT
2528 {
2529 return *static_cast<etl::imessage*>(data);
2530 }
2531
2532 //********************************************
2533 const etl::imessage& get() const ETL_NOEXCEPT
2534 {
2535 return *static_cast<const etl::imessage*>(data);
2536 }
2537
2538 //********************************************
2539 bool is_valid() const
2540 {
2541 return valid;
2542 }
2543
2544 //**********************************************
2545 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
2546 {
2547 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
2548 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
2549 T9::ID == id;
2550 }
2551
2552 //**********************************************
2553 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
2554 {
2555 return accepts(msg.get_message_id());
2556 }
2557
2558 //**********************************************
2559 template <etl::message_id_t Id>
2560 static ETL_CONSTEXPR bool accepts()
2561 {
2562 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
2563 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
2564 T9::ID == Id;
2565 }
2566
2567 //**********************************************
2568 template <typename TMessage>
2569 static ETL_CONSTEXPR
2571 accepts()
2572 {
2573 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
2574 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
2575 T9::ID == TMessage::ID;
2576 }
2577
2578 enum
2579 {
2582 };
2583
2584 private:
2585
2586 //********************************************
2588 void delete_current_message()
2589 {
2590 if (valid)
2591 {
2592 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
2593
2594 pmsg->~imessage();
2595 }
2596 }
2597 #include "private/diagnostic_pop.h"
2598
2599 //********************************************
2600 void add_new_message(const etl::imessage& msg)
2601 {
2602 const size_t id = msg.get_message_id();
2603 void* p = data;
2604
2605 switch (id)
2606 {
2607 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
2608 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
2609 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
2610 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
2611 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
2612 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
2613 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
2614 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
2615 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
2616 default: break;
2617 }
2618 }
2619
2620 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2621 //********************************************
2622 void add_new_message(etl::imessage&& msg)
2623 {
2624 const size_t id = msg.get_message_id();
2625 void* p = data;
2626
2627 switch (id)
2628 {
2629 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
2630 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
2631 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
2632 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
2633 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
2634 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
2635 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
2636 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
2637 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
2638 default: break;
2639 }
2640 }
2641 #endif
2642
2644 bool valid;
2645 };
2646
2647 //***************************************************************************
2648 // Specialisation for 8 message types.
2649 //***************************************************************************
2650 template <typename T1, typename T2, typename T3, typename T4,
2651 typename T5, typename T6, typename T7, typename T8>
2653 {
2654 public:
2655
2656 //********************************************
2659 : valid(false)
2660 {
2661 }
2662 #include "private/diagnostic_pop.h"
2663
2664 //********************************************
2666 explicit message_packet(const etl::imessage& msg)
2667 {
2668 if (accepts(msg))
2669 {
2670 add_new_message(msg);
2671 valid = true;
2672 }
2673 else
2674 {
2675 valid = false;
2676 }
2677
2678 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2679 }
2680 #include "private/diagnostic_pop.h"
2681
2682 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2683 //********************************************
2685 explicit message_packet(etl::imessage&& msg)
2686 {
2687 if (accepts(msg))
2688 {
2689 add_new_message(etl::move(msg));
2690 valid = true;
2691 }
2692 else
2693 {
2694 valid = false;
2695 }
2696
2697 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2698 }
2699 #include "private/diagnostic_pop.h"
2700 #endif
2701
2702 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
2703 //********************************************
2708 explicit message_packet(TMessage&& /*msg*/)
2709 : valid(true)
2710 {
2711 // Not etl::message_packet, not etl::imessage and in typelist.
2715
2716 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2717 }
2718 #include "private/diagnostic_pop.h"
2719 #else
2720 //********************************************
2722 template <typename TMessage>
2723 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7, T8> >::value &&
2724 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
2725 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8>::value, int>::type = 0)
2726 : valid(true)
2727 {
2728 // Not etl::message_packet, not etl::imessage and in typelist.
2732
2733 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2734 }
2735 #include "private/diagnostic_pop.h"
2736 #endif
2737
2738 //**********************************************
2741 : valid(other.is_valid())
2742 {
2743 if (valid)
2744 {
2745 add_new_message(other.get());
2746 }
2747 }
2748 #include "private/diagnostic_pop.h"
2749
2750 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2751 //**********************************************
2754 : valid(other.is_valid())
2755 {
2756 if (valid)
2757 {
2758 add_new_message(etl::move(other.get()));
2759 }
2760 }
2761 #include "private/diagnostic_pop.h"
2762 #endif
2763
2764 //**********************************************
2767 {
2768 delete_current_message();
2769 valid = rhs.is_valid();
2770 if (valid)
2771 {
2772 add_new_message(rhs.get());
2773 }
2774
2775 return *this;
2776 }
2777 #include "private/diagnostic_pop.h"
2778
2779 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2780 //**********************************************
2783 {
2784 delete_current_message();
2785 valid = rhs.is_valid();
2786 if (valid)
2787 {
2788 add_new_message(etl::move(rhs.get()));
2789 }
2790
2791 return *this;
2792 }
2793 #include "private/diagnostic_pop.h"
2794 #endif
2795
2796 //********************************************
2798 {
2799 delete_current_message();
2800 }
2801
2802 //********************************************
2803 etl::imessage& get() ETL_NOEXCEPT
2804 {
2805 return *static_cast<etl::imessage*>(data);
2806 }
2807
2808 //********************************************
2809 const etl::imessage& get() const ETL_NOEXCEPT
2810 {
2811 return *static_cast<const etl::imessage*>(data);
2812 }
2813
2814 //********************************************
2815 bool is_valid() const
2816 {
2817 return valid;
2818 }
2819
2820 //**********************************************
2821 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
2822 {
2823 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
2824 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id;
2825 }
2826
2827 //**********************************************
2828 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
2829 {
2830 return accepts(msg.get_message_id());
2831 }
2832
2833 //**********************************************
2834 template <etl::message_id_t Id>
2835 static ETL_CONSTEXPR bool accepts()
2836 {
2837 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
2838 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id;
2839 }
2840
2841 //**********************************************
2842 template <typename TMessage>
2843 static ETL_CONSTEXPR
2845 accepts()
2846 {
2847 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
2848 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID;
2849 }
2850
2851 enum
2852 {
2855 };
2856
2857 private:
2858
2859 //********************************************
2861 void delete_current_message()
2862 {
2863 if (valid)
2864 {
2865 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
2866
2867 pmsg->~imessage();
2868 }
2869 }
2870 #include "private/diagnostic_pop.h"
2871
2872 //********************************************
2873 void add_new_message(const etl::imessage& msg)
2874 {
2875 const size_t id = msg.get_message_id();
2876 void* p = data;
2877
2878 switch (id)
2879 {
2880 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
2881 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
2882 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
2883 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
2884 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
2885 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
2886 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
2887 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
2888 default: break;
2889 }
2890 }
2891
2892 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2893 //********************************************
2894 void add_new_message(etl::imessage&& msg)
2895 {
2896 const size_t id = msg.get_message_id();
2897 void* p = data;
2898
2899 switch (id)
2900 {
2901 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
2902 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
2903 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
2904 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
2905 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
2906 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
2907 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
2908 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
2909 default: break;
2910 }
2911 }
2912 #endif
2913
2915 bool valid;
2916 };
2917
2918 //***************************************************************************
2919 // Specialisation for 7 message types.
2920 //***************************************************************************
2921 template <typename T1, typename T2, typename T3, typename T4,
2922 typename T5, typename T6, typename T7>
2924 {
2925 public:
2926
2927 //********************************************
2930 : valid(false)
2931 {
2932 }
2933 #include "private/diagnostic_pop.h"
2934
2935 //********************************************
2937 explicit message_packet(const etl::imessage& msg)
2938 {
2939 if (accepts(msg))
2940 {
2941 add_new_message(msg);
2942 valid = true;
2943 }
2944 else
2945 {
2946 valid = false;
2947 }
2948
2949 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2950 }
2951 #include "private/diagnostic_pop.h"
2952
2953 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2954 //********************************************
2956 explicit message_packet(etl::imessage&& msg)
2957 {
2958 if (accepts(msg))
2959 {
2960 add_new_message(etl::move(msg));
2961 valid = true;
2962 }
2963 else
2964 {
2965 valid = false;
2966 }
2967
2968 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2969 }
2970 #include "private/diagnostic_pop.h"
2971 #endif
2972
2973 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
2974 //********************************************
2979 explicit message_packet(TMessage&& /*msg*/)
2980 : valid(true)
2981 {
2982 // Not etl::message_packet, not etl::imessage and in typelist.
2986
2987 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2988 }
2989 #include "private/diagnostic_pop.h"
2990 #else
2991 //********************************************
2993 template <typename TMessage>
2994 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6, T7> >::value &&
2995 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
2996 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7>::value, int>::type = 0)
2997 : valid(true)
2998 {
2999 // Not etl::message_packet, not etl::imessage and in typelist.
3003
3004 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3005 }
3006 #include "private/diagnostic_pop.h"
3007 #endif
3008
3009 //**********************************************
3012 : valid(other.is_valid())
3013 {
3014 if (valid)
3015 {
3016 add_new_message(other.get());
3017 }
3018 }
3019 #include "private/diagnostic_pop.h"
3020
3021 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3022 //**********************************************
3025 : valid(other.is_valid())
3026 {
3027 if (valid)
3028 {
3029 add_new_message(etl::move(other.get()));
3030 }
3031 }
3032 #include "private/diagnostic_pop.h"
3033 #endif
3034
3035 //**********************************************
3038 {
3039 delete_current_message();
3040 valid = rhs.is_valid();
3041 if (valid)
3042 {
3043 add_new_message(rhs.get());
3044 }
3045
3046 return *this;
3047 }
3048 #include "private/diagnostic_pop.h"
3049
3050 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3051 //**********************************************
3054 {
3055 delete_current_message();
3056 valid = rhs.is_valid();
3057 if (valid)
3058 {
3059 add_new_message(etl::move(rhs.get()));
3060 }
3061
3062 return *this;
3063 }
3064 #include "private/diagnostic_pop.h"
3065 #endif
3066
3067 //********************************************
3069 {
3070 delete_current_message();
3071 }
3072
3073 //********************************************
3074 etl::imessage& get() ETL_NOEXCEPT
3075 {
3076 return *static_cast<etl::imessage*>(data);
3077 }
3078
3079 //********************************************
3080 const etl::imessage& get() const ETL_NOEXCEPT
3081 {
3082 return *static_cast<const etl::imessage*>(data);
3083 }
3084
3085 //********************************************
3086 bool is_valid() const
3087 {
3088 return valid;
3089 }
3090
3091 //**********************************************
3092 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
3093 {
3094 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
3095 T5::ID == id || T6::ID == id || T7::ID == id;
3096 }
3097
3098 //**********************************************
3099 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
3100 {
3101 return accepts(msg.get_message_id());
3102 }
3103
3104 //**********************************************
3105 template <etl::message_id_t Id>
3106 static ETL_CONSTEXPR bool accepts()
3107 {
3108 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
3109 T5::ID == Id || T6::ID == Id || T7::ID == Id;
3110 }
3111
3112 //**********************************************
3113 template <typename TMessage>
3114 static ETL_CONSTEXPR
3116 accepts()
3117 {
3118 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
3119 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID;
3120 }
3121
3122 enum
3123 {
3126 };
3127
3128 private:
3129
3130 //********************************************
3132 void delete_current_message()
3133 {
3134 if (valid)
3135 {
3136 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
3137
3138 pmsg->~imessage();
3139 }
3140 }
3141 #include "private/diagnostic_pop.h"
3142
3143 //********************************************
3144 void add_new_message(const etl::imessage& msg)
3145 {
3146 const size_t id = msg.get_message_id();
3147 void* p = data;
3148
3149 switch (id)
3150 {
3151 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
3152 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
3153 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
3154 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
3155 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
3156 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
3157 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
3158 default: break;
3159 }
3160 }
3161
3162 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3163 //********************************************
3164 void add_new_message(etl::imessage&& msg)
3165 {
3166 const size_t id = msg.get_message_id();
3167 void* p = data;
3168
3169 switch (id)
3170 {
3171 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
3172 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
3173 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
3174 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
3175 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
3176 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
3177 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
3178 default: break;
3179 }
3180 }
3181 #endif
3182
3184 bool valid;
3185 };
3186
3187 //***************************************************************************
3188 // Specialisation for 6 message types.
3189 //***************************************************************************
3190 template <typename T1, typename T2, typename T3, typename T4,
3191 typename T5, typename T6>
3193 {
3194 public:
3195
3196 //********************************************
3199 : valid(false)
3200 {
3201 }
3202 #include "private/diagnostic_pop.h"
3203
3204 //********************************************
3206 explicit message_packet(const etl::imessage& msg)
3207 {
3208 if (accepts(msg))
3209 {
3210 add_new_message(msg);
3211 valid = true;
3212 }
3213 else
3214 {
3215 valid = false;
3216 }
3217
3218 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3219 }
3220 #include "private/diagnostic_pop.h"
3221
3222 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3223 //********************************************
3225 explicit message_packet(etl::imessage&& msg)
3226 {
3227 if (accepts(msg))
3228 {
3229 add_new_message(etl::move(msg));
3230 valid = true;
3231 }
3232 else
3233 {
3234 valid = false;
3235 }
3236
3237 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3238 }
3239 #include "private/diagnostic_pop.h"
3240 #endif
3241
3242 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
3243 //********************************************
3248 explicit message_packet(TMessage&& /*msg*/)
3249 : valid(true)
3250 {
3251 // Not etl::message_packet, not etl::imessage and in typelist.
3255
3256 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3257 }
3258 #include "private/diagnostic_pop.h"
3259 #else
3260 //********************************************
3262 template <typename TMessage>
3263 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5, T6> >::value &&
3264 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
3265 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6>::value, int>::type = 0)
3266 : valid(true)
3267 {
3268 // Not etl::message_packet, not etl::imessage and in typelist.
3272
3273 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3274 }
3275 #include "private/diagnostic_pop.h"
3276 #endif
3277
3278 //**********************************************
3281 : valid(other.is_valid())
3282 {
3283 if (valid)
3284 {
3285 add_new_message(other.get());
3286 }
3287 }
3288 #include "private/diagnostic_pop.h"
3289
3290 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3291 //**********************************************
3294 : valid(other.is_valid())
3295 {
3296 if (valid)
3297 {
3298 add_new_message(etl::move(other.get()));
3299 }
3300 }
3301 #include "private/diagnostic_pop.h"
3302 #endif
3303
3304 //**********************************************
3307 {
3308 delete_current_message();
3309 valid = rhs.is_valid();
3310 if (valid)
3311 {
3312 add_new_message(rhs.get());
3313 }
3314
3315 return *this;
3316 }
3317 #include "private/diagnostic_pop.h"
3318
3319 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3320 //**********************************************
3323 {
3324 delete_current_message();
3325 valid = rhs.is_valid();
3326 if (valid)
3327 {
3328 add_new_message(etl::move(rhs.get()));
3329 }
3330
3331 return *this;
3332 }
3333 #include "private/diagnostic_pop.h"
3334 #endif
3335
3336 //********************************************
3338 {
3339 delete_current_message();
3340 }
3341
3342 //********************************************
3343 etl::imessage& get() ETL_NOEXCEPT
3344 {
3345 return *static_cast<etl::imessage*>(data);
3346 }
3347
3348 //********************************************
3349 const etl::imessage& get() const ETL_NOEXCEPT
3350 {
3351 return *static_cast<const etl::imessage*>(data);
3352 }
3353
3354 //********************************************
3355 bool is_valid() const
3356 {
3357 return valid;
3358 }
3359
3360 //**********************************************
3361 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
3362 {
3363 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
3364 T5::ID == id || T6::ID == id;
3365 }
3366
3367 //**********************************************
3368 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
3369 {
3370 return accepts(msg.get_message_id());
3371 }
3372
3373 //**********************************************
3374 template <etl::message_id_t Id>
3375 static ETL_CONSTEXPR bool accepts()
3376 {
3377 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
3378 T5::ID == Id || T6::ID == Id;
3379 }
3380
3381 //**********************************************
3382 template <typename TMessage>
3383 static ETL_CONSTEXPR
3385 accepts()
3386 {
3387 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
3388 T5::ID == TMessage::ID || T6::ID == TMessage::ID;
3389 }
3390
3391 enum
3392 {
3395 };
3396
3397 private:
3398
3399 //********************************************
3401 void delete_current_message()
3402 {
3403 if (valid)
3404 {
3405 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
3406
3407 pmsg->~imessage();
3408 }
3409 }
3410 #include "private/diagnostic_pop.h"
3411
3412 //********************************************
3413 void add_new_message(const etl::imessage& msg)
3414 {
3415 const size_t id = msg.get_message_id();
3416 void* p = data;
3417
3418 switch (id)
3419 {
3420 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
3421 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
3422 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
3423 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
3424 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
3425 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
3426 default: break;
3427 }
3428 }
3429
3430 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3431 //********************************************
3432 void add_new_message(etl::imessage&& msg)
3433 {
3434 const size_t id = msg.get_message_id();
3435 void* p = data;
3436
3437 switch (id)
3438 {
3439 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
3440 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
3441 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
3442 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
3443 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
3444 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
3445 default: break;
3446 }
3447 }
3448 #endif
3449
3451 bool valid;
3452 };
3453
3454 //***************************************************************************
3455 // Specialisation for 5 message types.
3456 //***************************************************************************
3457 template <typename T1, typename T2, typename T3, typename T4,
3458 typename T5>
3460 {
3461 public:
3462
3463 //********************************************
3466 : valid(false)
3467 {
3468 }
3469 #include "private/diagnostic_pop.h"
3470
3471 //********************************************
3473 explicit message_packet(const etl::imessage& msg)
3474 {
3475 if (accepts(msg))
3476 {
3477 add_new_message(msg);
3478 valid = true;
3479 }
3480 else
3481 {
3482 valid = false;
3483 }
3484
3485 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3486 }
3487 #include "private/diagnostic_pop.h"
3488
3489 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3490 //********************************************
3492 explicit message_packet(etl::imessage&& msg)
3493 {
3494 if (accepts(msg))
3495 {
3496 add_new_message(etl::move(msg));
3497 valid = true;
3498 }
3499 else
3500 {
3501 valid = false;
3502 }
3503
3504 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3505 }
3506 #include "private/diagnostic_pop.h"
3507 #endif
3508
3509 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
3510 //********************************************
3515 explicit message_packet(TMessage&& /*msg*/)
3516 : valid(true)
3517 {
3518 // Not etl::message_packet, not etl::imessage and in typelist.
3522
3523 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3524 }
3525 #include "private/diagnostic_pop.h"
3526 #else
3527 //********************************************
3529 template <typename TMessage>
3530 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4, T5> >::value &&
3531 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
3532 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5>::value, int>::type = 0)
3533 : valid(true)
3534 {
3535 // Not etl::message_packet, not etl::imessage and in typelist.
3539
3540 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3541 }
3542 #include "private/diagnostic_pop.h"
3543 #endif
3544
3545 //**********************************************
3548 : valid(other.is_valid())
3549 {
3550 if (valid)
3551 {
3552 add_new_message(other.get());
3553 }
3554 }
3555 #include "private/diagnostic_pop.h"
3556
3557 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3558 //**********************************************
3561 : valid(other.is_valid())
3562 {
3563 if (valid)
3564 {
3565 add_new_message(etl::move(other.get()));
3566 }
3567 }
3568 #include "private/diagnostic_pop.h"
3569 #endif
3570
3571 //**********************************************
3574 {
3575 delete_current_message();
3576 valid = rhs.is_valid();
3577 if (valid)
3578 {
3579 add_new_message(rhs.get());
3580 }
3581
3582 return *this;
3583 }
3584 #include "private/diagnostic_pop.h"
3585
3586 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3587 //**********************************************
3590 {
3591 delete_current_message();
3592 valid = rhs.is_valid();
3593 if (valid)
3594 {
3595 add_new_message(etl::move(rhs.get()));
3596 }
3597
3598 return *this;
3599 }
3600 #include "private/diagnostic_pop.h"
3601 #endif
3602
3603 //********************************************
3605 {
3606 delete_current_message();
3607 }
3608
3609 //********************************************
3610 etl::imessage& get() ETL_NOEXCEPT
3611 {
3612 return *static_cast<etl::imessage*>(data);
3613 }
3614
3615 //********************************************
3616 const etl::imessage& get() const ETL_NOEXCEPT
3617 {
3618 return *static_cast<const etl::imessage*>(data);
3619 }
3620
3621 //********************************************
3622 bool is_valid() const
3623 {
3624 return valid;
3625 }
3626
3627 //**********************************************
3628 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
3629 {
3630 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
3631 T5::ID == id;
3632 }
3633
3634 //**********************************************
3635 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
3636 {
3637 return accepts(msg.get_message_id());
3638 }
3639
3640 //**********************************************
3641 template <etl::message_id_t Id>
3642 static ETL_CONSTEXPR bool accepts()
3643 {
3644 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
3645 T5::ID == Id;
3646 }
3647
3648 //**********************************************
3649 template <typename TMessage>
3650 static ETL_CONSTEXPR
3652 accepts()
3653 {
3654 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
3655 T5::ID == TMessage::ID;
3656 }
3657
3658 enum
3659 {
3662 };
3663
3664 private:
3665
3666 //********************************************
3668 void delete_current_message()
3669 {
3670 if (valid)
3671 {
3672 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
3673
3674 pmsg->~imessage();
3675 }
3676 }
3677 #include "private/diagnostic_pop.h"
3678
3679 //********************************************
3680 void add_new_message(const etl::imessage& msg)
3681 {
3682 const size_t id = msg.get_message_id();
3683 void* p = data;
3684
3685 switch (id)
3686 {
3687 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
3688 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
3689 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
3690 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
3691 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
3692 default: break;
3693 }
3694 }
3695
3696 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3697 //********************************************
3698 void add_new_message(etl::imessage&& msg)
3699 {
3700 const size_t id = msg.get_message_id();
3701 void* p = data;
3702
3703 switch (id)
3704 {
3705 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
3706 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
3707 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
3708 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
3709 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
3710 default: break;
3711 }
3712 }
3713 #endif
3714
3716 bool valid;
3717 };
3718
3719 //***************************************************************************
3720 // Specialisation for 4 message types.
3721 //***************************************************************************
3722 template <typename T1, typename T2, typename T3, typename T4>
3724 {
3725 public:
3726
3727 //********************************************
3730 : valid(false)
3731 {
3732 }
3733 #include "private/diagnostic_pop.h"
3734
3735 //********************************************
3737 explicit message_packet(const etl::imessage& msg)
3738 {
3739 if (accepts(msg))
3740 {
3741 add_new_message(msg);
3742 valid = true;
3743 }
3744 else
3745 {
3746 valid = false;
3747 }
3748
3749 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3750 }
3751 #include "private/diagnostic_pop.h"
3752
3753 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3754 //********************************************
3756 explicit message_packet(etl::imessage&& msg)
3757 {
3758 if (accepts(msg))
3759 {
3760 add_new_message(etl::move(msg));
3761 valid = true;
3762 }
3763 else
3764 {
3765 valid = false;
3766 }
3767
3768 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3769 }
3770 #include "private/diagnostic_pop.h"
3771 #endif
3772
3773 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
3774 //********************************************
3779 explicit message_packet(TMessage&& /*msg*/)
3780 : valid(true)
3781 {
3782 // Not etl::message_packet, not etl::imessage and in typelist.
3786
3787 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3788 }
3789 #include "private/diagnostic_pop.h"
3790 #else
3791 //********************************************
3793 template <typename TMessage>
3794 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3, T4> >::value &&
3795 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
3796 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4>::value, int>::type = 0)
3797 : valid(true)
3798 {
3799 // Not etl::message_packet, not etl::imessage and in typelist.
3803
3804 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3805 }
3806 #include "private/diagnostic_pop.h"
3807 #endif
3808
3809 //**********************************************
3812 : valid(other.is_valid())
3813 {
3814 if (valid)
3815 {
3816 add_new_message(other.get());
3817 }
3818 }
3819 #include "private/diagnostic_pop.h"
3820
3821 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3822 //**********************************************
3825 : valid(other.is_valid())
3826 {
3827 if (valid)
3828 {
3829 add_new_message(etl::move(other.get()));
3830 }
3831 }
3832 #include "private/diagnostic_pop.h"
3833 #endif
3834
3835 //**********************************************
3838 {
3839 delete_current_message();
3840 valid = rhs.is_valid();
3841 if (valid)
3842 {
3843 add_new_message(rhs.get());
3844 }
3845
3846 return *this;
3847 }
3848 #include "private/diagnostic_pop.h"
3849
3850 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3851 //**********************************************
3854 {
3855 delete_current_message();
3856 valid = rhs.is_valid();
3857 if (valid)
3858 {
3859 add_new_message(etl::move(rhs.get()));
3860 }
3861
3862 return *this;
3863 }
3864 #include "private/diagnostic_pop.h"
3865 #endif
3866
3867 //********************************************
3869 {
3870 delete_current_message();
3871 }
3872
3873 //********************************************
3874 etl::imessage& get() ETL_NOEXCEPT
3875 {
3876 return *static_cast<etl::imessage*>(data);
3877 }
3878
3879 //********************************************
3880 const etl::imessage& get() const ETL_NOEXCEPT
3881 {
3882 return *static_cast<const etl::imessage*>(data);
3883 }
3884
3885 //********************************************
3886 bool is_valid() const
3887 {
3888 return valid;
3889 }
3890
3891 //**********************************************
3892 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
3893 {
3894 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id;
3895 }
3896
3897 //**********************************************
3898 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
3899 {
3900 return accepts(msg.get_message_id());
3901 }
3902
3903 //**********************************************
3904 template <etl::message_id_t Id>
3905 static ETL_CONSTEXPR bool accepts()
3906 {
3907 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id;
3908 }
3909
3910 //**********************************************
3911 template <typename TMessage>
3912 static ETL_CONSTEXPR
3914 accepts()
3915 {
3916 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID;
3917 }
3918
3919 enum
3920 {
3923 };
3924
3925 private:
3926
3927 //********************************************
3929 void delete_current_message()
3930 {
3931 if (valid)
3932 {
3933 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
3934
3935 pmsg->~imessage();
3936 }
3937 }
3938 #include "private/diagnostic_pop.h"
3939
3940 //********************************************
3941 void add_new_message(const etl::imessage& msg)
3942 {
3943 const size_t id = msg.get_message_id();
3944 void* p = data;
3945
3946 switch (id)
3947 {
3948 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
3949 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
3950 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
3951 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
3952 default: break;
3953 }
3954 }
3955
3956 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3957 //********************************************
3958 void add_new_message(etl::imessage&& msg)
3959 {
3960 const size_t id = msg.get_message_id();
3961 void* p = data;
3962
3963 switch (id)
3964 {
3965 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
3966 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
3967 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
3968 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
3969 default: break;
3970 }
3971 }
3972 #endif
3973
3975 bool valid;
3976 };
3977
3978 //***************************************************************************
3979 // Specialisation for 3 message types.
3980 //***************************************************************************
3981 template <typename T1, typename T2, typename T3>
3983 {
3984 public:
3985
3986 //********************************************
3989 : valid(false)
3990 {
3991 }
3992 #include "private/diagnostic_pop.h"
3993
3994 //********************************************
3996 explicit message_packet(const etl::imessage& msg)
3997 {
3998 if (accepts(msg))
3999 {
4000 add_new_message(msg);
4001 valid = true;
4002 }
4003 else
4004 {
4005 valid = false;
4006 }
4007
4008 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4009 }
4010 #include "private/diagnostic_pop.h"
4011
4012 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4013 //********************************************
4015 explicit message_packet(etl::imessage&& msg)
4016 {
4017 if (accepts(msg))
4018 {
4019 add_new_message(etl::move(msg));
4020 valid = true;
4021 }
4022 else
4023 {
4024 valid = false;
4025 }
4026
4027 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4028 }
4029 #include "private/diagnostic_pop.h"
4030 #endif
4031
4032 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
4033 //********************************************
4038 explicit message_packet(TMessage&& /*msg*/)
4039 : valid(true)
4040 {
4041 // Not etl::message_packet, not etl::imessage and in typelist.
4045
4046 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4047 }
4048 #include "private/diagnostic_pop.h"
4049 #else
4050 //********************************************
4052 template <typename TMessage>
4053 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2, T3> >::value &&
4054 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
4055 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3>::value, int>::type = 0)
4056 : valid(true)
4057 {
4058 // Not etl::message_packet, not etl::imessage and in typelist.
4062
4063 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4064 }
4065 #include "private/diagnostic_pop.h"
4066 #endif
4067
4068 //**********************************************
4071 : valid(other.is_valid())
4072 {
4073 if (valid)
4074 {
4075 add_new_message(other.get());
4076 }
4077 }
4078 #include "private/diagnostic_pop.h"
4079
4080 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4081 //**********************************************
4084 : valid(other.is_valid())
4085 {
4086 if (valid)
4087 {
4088 add_new_message(etl::move(other.get()));
4089 }
4090 }
4091 #include "private/diagnostic_pop.h"
4092 #endif
4093
4094 //**********************************************
4097 {
4098 delete_current_message();
4099 valid = rhs.is_valid();
4100 if (valid)
4101 {
4102 add_new_message(rhs.get());
4103 }
4104
4105 return *this;
4106 }
4107 #include "private/diagnostic_pop.h"
4108
4109 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4110 //**********************************************
4113 {
4114 delete_current_message();
4115 valid = rhs.is_valid();
4116 if (valid)
4117 {
4118 add_new_message(etl::move(rhs.get()));
4119 }
4120
4121 return *this;
4122 }
4123 #include "private/diagnostic_pop.h"
4124 #endif
4125
4126 //********************************************
4128 {
4129 delete_current_message();
4130 }
4131
4132 //********************************************
4133 etl::imessage& get() ETL_NOEXCEPT
4134 {
4135 return *static_cast<etl::imessage*>(data);
4136 }
4137
4138 //********************************************
4139 const etl::imessage& get() const ETL_NOEXCEPT
4140 {
4141 return *static_cast<const etl::imessage*>(data);
4142 }
4143
4144 //********************************************
4145 bool is_valid() const
4146 {
4147 return valid;
4148 }
4149
4150 //**********************************************
4151 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
4152 {
4153 return T1::ID == id || T2::ID == id || T3::ID == id;
4154 }
4155
4156 //**********************************************
4157 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
4158 {
4159 return accepts(msg.get_message_id());
4160 }
4161
4162 //**********************************************
4163 template <etl::message_id_t Id>
4164 static ETL_CONSTEXPR bool accepts()
4165 {
4166 return T1::ID == Id || T2::ID == Id || T3::ID == Id;
4167 }
4168
4169 //**********************************************
4170 template <typename TMessage>
4171 static ETL_CONSTEXPR
4173 accepts()
4174 {
4175 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID;
4176 }
4177
4178 enum
4179 {
4182 };
4183
4184 private:
4185
4186 //********************************************
4188 void delete_current_message()
4189 {
4190 if (valid)
4191 {
4192 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
4193
4194 pmsg->~imessage();
4195 }
4196 }
4197 #include "private/diagnostic_pop.h"
4198
4199 //********************************************
4200 void add_new_message(const etl::imessage& msg)
4201 {
4202 const size_t id = msg.get_message_id();
4203 void* p = data;
4204
4205 switch (id)
4206 {
4207 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
4208 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
4209 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
4210 default: break;
4211 }
4212 }
4213
4214 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4215 //********************************************
4216 void add_new_message(etl::imessage&& msg)
4217 {
4218 const size_t id = msg.get_message_id();
4219 void* p = data;
4220
4221 switch (id)
4222 {
4223 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
4224 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
4225 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
4226 default: break;
4227 }
4228 }
4229 #endif
4230
4232 bool valid;
4233 };
4234
4235 //***************************************************************************
4236 // Specialisation for 2 message types.
4237 //***************************************************************************
4238 template <typename T1, typename T2>
4240 {
4241 public:
4242
4243 //********************************************
4246 : valid(false)
4247 {
4248 }
4249 #include "private/diagnostic_pop.h"
4250
4251 //********************************************
4253 explicit message_packet(const etl::imessage& msg)
4254 {
4255 if (accepts(msg))
4256 {
4257 add_new_message(msg);
4258 valid = true;
4259 }
4260 else
4261 {
4262 valid = false;
4263 }
4264
4265 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4266 }
4267 #include "private/diagnostic_pop.h"
4268
4269 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4270 //********************************************
4272 explicit message_packet(etl::imessage&& msg)
4273 {
4274 if (accepts(msg))
4275 {
4276 add_new_message(etl::move(msg));
4277 valid = true;
4278 }
4279 else
4280 {
4281 valid = false;
4282 }
4283
4284 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4285 }
4286 #include "private/diagnostic_pop.h"
4287 #endif
4288
4289 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
4290 //********************************************
4295 explicit message_packet(TMessage&& /*msg*/)
4296 : valid(true)
4297 {
4298 // Not etl::message_packet, not etl::imessage and in typelist.
4302
4303 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4304 }
4305 #include "private/diagnostic_pop.h"
4306 #else
4307 //********************************************
4309 template <typename TMessage>
4310 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1, T2> >::value &&
4311 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
4312 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2>::value, int>::type = 0)
4313 : valid(true)
4314 {
4315 // Not etl::message_packet, not etl::imessage and in typelist.
4319
4320 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4321 }
4322 #include "private/diagnostic_pop.h"
4323 #endif
4324
4325 //**********************************************
4328 : valid(other.is_valid())
4329 {
4330 if (valid)
4331 {
4332 add_new_message(other.get());
4333 }
4334 }
4335 #include "private/diagnostic_pop.h"
4336
4337 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4338 //**********************************************
4341 : valid(other.is_valid())
4342 {
4343 if (valid)
4344 {
4345 add_new_message(etl::move(other.get()));
4346 }
4347 }
4348 #include "private/diagnostic_pop.h"
4349 #endif
4350
4351 //**********************************************
4354 {
4355 delete_current_message();
4356 valid = rhs.is_valid();
4357 if (valid)
4358 {
4359 add_new_message(rhs.get());
4360 }
4361
4362 return *this;
4363 }
4364 #include "private/diagnostic_pop.h"
4365
4366 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4367 //**********************************************
4370 {
4371 delete_current_message();
4372 valid = rhs.is_valid();
4373 if (valid)
4374 {
4375 add_new_message(etl::move(rhs.get()));
4376 }
4377
4378 return *this;
4379 }
4380 #include "private/diagnostic_pop.h"
4381 #endif
4382
4383 //********************************************
4385 {
4386 delete_current_message();
4387 }
4388
4389 //********************************************
4390 etl::imessage& get() ETL_NOEXCEPT
4391 {
4392 return *static_cast<etl::imessage*>(data);
4393 }
4394
4395 //********************************************
4396 const etl::imessage& get() const ETL_NOEXCEPT
4397 {
4398 return *static_cast<const etl::imessage*>(data);
4399 }
4400
4401 //********************************************
4402 bool is_valid() const
4403 {
4404 return valid;
4405 }
4406
4407 //**********************************************
4408 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
4409 {
4410 return T1::ID == id || T2::ID == id;
4411 }
4412
4413 //**********************************************
4414 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
4415 {
4416 return accepts(msg.get_message_id());
4417 }
4418
4419 //**********************************************
4420 template <etl::message_id_t Id>
4421 static ETL_CONSTEXPR bool accepts()
4422 {
4423 return T1::ID == Id || T2::ID == Id;
4424 }
4425
4426 //**********************************************
4427 template <typename TMessage>
4428 static ETL_CONSTEXPR
4430 accepts()
4431 {
4432 return T1::ID == TMessage::ID || T2::ID == TMessage::ID;
4433 }
4434
4435 enum
4436 {
4439 };
4440
4441 private:
4442
4443 //********************************************
4445 void delete_current_message()
4446 {
4447 if (valid)
4448 {
4449 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
4450
4451 pmsg->~imessage();
4452 }
4453 }
4454 #include "private/diagnostic_pop.h"
4455
4456 //********************************************
4457 void add_new_message(const etl::imessage& msg)
4458 {
4459 const size_t id = msg.get_message_id();
4460 void* p = data;
4461
4462 switch (id)
4463 {
4464 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
4465 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
4466 default: break;
4467 }
4468 }
4469
4470 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4471 //********************************************
4472 void add_new_message(etl::imessage&& msg)
4473 {
4474 const size_t id = msg.get_message_id();
4475 void* p = data;
4476
4477 switch (id)
4478 {
4479 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
4480 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
4481 default: break;
4482 }
4483 }
4484 #endif
4485
4487 bool valid;
4488 };
4489
4490 //***************************************************************************
4491 // Specialisation for 1 message type.
4492 //***************************************************************************
4493 template <typename T1>
4495 {
4496 public:
4497
4498 //********************************************
4501 : valid(false)
4502 {
4503 }
4504 #include "private/diagnostic_pop.h"
4505
4506 //********************************************
4508 explicit message_packet(const etl::imessage& msg)
4509 {
4510 if (accepts(msg))
4511 {
4512 add_new_message(msg);
4513 valid = true;
4514 }
4515 else
4516 {
4517 valid = false;
4518 }
4519
4520 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4521 }
4522 #include "private/diagnostic_pop.h"
4523
4524 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4525 //********************************************
4527 explicit message_packet(etl::imessage&& msg)
4528 {
4529 if (accepts(msg))
4530 {
4531 add_new_message(etl::move(msg));
4532 valid = true;
4533 }
4534 else
4535 {
4536 valid = false;
4537 }
4538
4539 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4540 }
4541 #include "private/diagnostic_pop.h"
4542 #endif
4543
4544 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
4545 //********************************************
4550 explicit message_packet(TMessage&& /*msg*/)
4551 : valid(true)
4552 {
4553 // Not etl::message_packet, not etl::imessage and in typelist.
4557
4558 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4559 }
4560 #include "private/diagnostic_pop.h"
4561 #else
4562 //********************************************
4564 template <typename TMessage>
4565 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1> >::value &&
4566 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
4567 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1>::value, int>::type = 0)
4568 : valid(true)
4569 {
4570 // Not etl::message_packet, not etl::imessage and in typelist.
4574
4575 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4576 }
4577 #include "private/diagnostic_pop.h"
4578 #endif
4579
4580 //**********************************************
4583 : valid(other.is_valid())
4584 {
4585 if (valid)
4586 {
4587 add_new_message(other.get());
4588 }
4589 }
4590 #include "private/diagnostic_pop.h"
4591
4592 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4593 //**********************************************
4596 : valid(other.is_valid())
4597 {
4598 if (valid)
4599 {
4600 add_new_message(etl::move(other.get()));
4601 }
4602 }
4603 #include "private/diagnostic_pop.h"
4604 #endif
4605
4606 //**********************************************
4609 {
4610 delete_current_message();
4611 valid = rhs.is_valid();
4612 if (valid)
4613 {
4614 add_new_message(rhs.get());
4615 }
4616
4617 return *this;
4618 }
4619 #include "private/diagnostic_pop.h"
4620
4621 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4622 //**********************************************
4625 {
4626 delete_current_message();
4627 valid = rhs.is_valid();
4628 if (valid)
4629 {
4630 add_new_message(etl::move(rhs.get()));
4631 }
4632
4633 return *this;
4634 }
4635 #include "private/diagnostic_pop.h"
4636 #endif
4637
4638 //********************************************
4640 {
4641 delete_current_message();
4642 }
4643
4644 //********************************************
4645 etl::imessage& get() ETL_NOEXCEPT
4646 {
4647 return *static_cast<etl::imessage*>(data);
4648 }
4649
4650 //********************************************
4651 const etl::imessage& get() const ETL_NOEXCEPT
4652 {
4653 return *static_cast<const etl::imessage*>(data);
4654 }
4655
4656 //********************************************
4657 bool is_valid() const
4658 {
4659 return valid;
4660 }
4661
4662 //**********************************************
4663 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
4664 {
4665 return T1::ID == id;
4666 }
4667
4668 //**********************************************
4669 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
4670 {
4671 return accepts(msg.get_message_id());
4672 }
4673
4674 //**********************************************
4675 template <etl::message_id_t Id>
4676 static ETL_CONSTEXPR bool accepts()
4677 {
4678 return T1::ID == Id;
4679 }
4680
4681 //**********************************************
4682 template <typename TMessage>
4683 static ETL_CONSTEXPR
4685 accepts()
4686 {
4687 return T1::ID == TMessage::ID;
4688 }
4689
4690 enum
4691 {
4693 ALIGNMENT = etl::largest<T1>::alignment
4694 };
4695
4696 private:
4697
4698 //********************************************
4700 void delete_current_message()
4701 {
4702 if (valid)
4703 {
4704 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
4705
4706 pmsg->~imessage();
4707 }
4708 }
4709 #include "private/diagnostic_pop.h"
4710
4711 //********************************************
4712 void add_new_message(const etl::imessage& msg)
4713 {
4714 const size_t id = msg.get_message_id();
4715 void* p = data;
4716
4717 switch (id)
4718 {
4719 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
4720 default: break;
4721 }
4722 }
4723
4724 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4725 //********************************************
4726 void add_new_message(etl::imessage&& msg)
4727 {
4728 const size_t id = msg.get_message_id();
4729 void* p = data;
4730
4731 switch (id)
4732 {
4733 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
4734 default: break;
4735 }
4736 }
4737 #endif
4738
4740 bool valid;
4741 };
4742#endif
4743}
4744#else
4745 #error "etl::message_packet is not compatible with non-virtual etl::imessage"
4746#endif
4747
4748#endif
Definition message.h:73
Definition message_packet.h:367
Definition message.h:56
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
Definition largest.h:367
enable_if
Definition type_traits_generator.h:1191
is_same
Definition type_traits_generator.h:1041
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