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#include "message.h"
57#include "error_handler.h"
58#include "static_assert.h"
59#include "largest.h"
60#include "alignment.h"
61#include "utility.h"
62
63#include <stdint.h>
64
65namespace etl
66{
67#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
68 //***************************************************************************
69 // The definition for all message types.
70 //***************************************************************************
71 template <typename... TMessageTypes>
72 class message_packet
73 {
74
75 private:
76
77 template <typename T>
78 static constexpr bool IsMessagePacket = etl::is_same_v< etl::remove_const_t<etl::remove_reference_t<T>>, etl::message_packet<TMessageTypes...>>;
79
80 template <typename T>
81 static constexpr bool IsInMessageList = etl::is_one_of_v<etl::remove_const_t<etl::remove_reference_t<T>>, TMessageTypes...>;
82
83 template <typename T>
85
86 public:
87
88 //********************************************
90 message_packet()
91 : valid(false)
92 {
93 }
95
96 //********************************************
98 //********************************************
100 template <typename T, typename = typename etl::enable_if<IsIMessage<T> || IsInMessageList<T>, int>::type>
101 explicit message_packet(T&& msg)
102 : valid(true)
103 {
104 if constexpr (IsIMessage<T>)
105 {
106 if (accepts(msg))
107 {
108 add_new_message(etl::forward<T>(msg));
109 valid = true;
110 }
111 else
112 {
113 valid = false;
114 }
115
116 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
117 }
118 else if constexpr (IsInMessageList<T>)
119 {
120 add_new_message_type<T>(etl::forward<T>(msg));
121 }
122 else
123 {
124 ETL_STATIC_ASSERT(IsInMessageList<T>, "Message not in packet type list");
125 }
126 }
128
129 //**********************************************
130 message_packet(const message_packet& other)
131 {
132 valid = other.is_valid();
133
134 if (valid)
135 {
136 add_new_message(other.get());
137 }
138 }
139
140#if ETL_USING_CPP11
141 //**********************************************
142 message_packet(message_packet&& other)
143 {
144 valid = other.is_valid();
145
146 if (valid)
147 {
148 add_new_message(etl::move(other.get()));
149 }
150 }
151#endif
152
153 //**********************************************
154 void copy(const message_packet& other)
155 {
156 valid = other.is_valid();
157
158 if (valid)
159 {
160 add_new_message(other.get());
161 }
162 }
163
164 //**********************************************
165 void copy(message_packet&& other)
166 {
167 valid = other.is_valid();
168
169 if (valid)
170 {
171 add_new_message(etl::move(other.get()));
172 }
173 }
174
175 //**********************************************
177 message_packet& operator =(const message_packet& rhs)
178 {
179 delete_current_message();
180 valid = rhs.is_valid();
181 if (valid)
182 {
183 add_new_message(rhs.get());
184 }
185
186 return *this;
187 }
189
190 //**********************************************
192 message_packet& operator =(message_packet&& rhs)
193 {
194 delete_current_message();
195 valid = rhs.is_valid();
196 if (valid)
197 {
198 add_new_message(etl::move(rhs.get()));
199 }
200
201 return *this;
202 }
204
205 //********************************************
206 ~message_packet()
207 {
208 delete_current_message();
209 }
210
211 //********************************************
212 etl::imessage& get() ETL_NOEXCEPT
213 {
214 return *static_cast<etl::imessage*>(data);
215 }
216
217 //********************************************
218 const etl::imessage& get() const ETL_NOEXCEPT
219 {
220 return *static_cast<const etl::imessage*>(data);
221 }
222
223 //********************************************
224 bool is_valid() const
225 {
226 return valid;
227 }
228
229 //**********************************************
230 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
231 {
232 return (accepts_message<TMessageTypes::ID>(id) || ...);
233 }
234
235 //**********************************************
236 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
237 {
238 return accepts(msg.get_message_id());
239 }
240
241 //**********************************************
242 template <etl::message_id_t Id>
243 static ETL_CONSTEXPR bool accepts()
244 {
245 return (accepts_message<TMessageTypes::ID, Id>() || ...);
246 }
247
248 //**********************************************
249 template <typename TMessage>
250 static ETL_CONSTEXPR
252 accepts()
253 {
254 return accepts<TMessage::ID>();
255 }
256
257 enum
258 {
259 SIZE = etl::largest<TMessageTypes...>::size,
260 ALIGNMENT = etl::largest<TMessageTypes...>::alignment
261 };
262
263 private:
264
265 //**********************************************
266 template <etl::message_id_t Id1, etl::message_id_t Id2>
267 static bool accepts_message()
268 {
269 return Id1 == Id2;
270 }
271
272 //**********************************************
273 template <etl::message_id_t Id1>
274 static bool accepts_message(etl::message_id_t id2)
275 {
276 return Id1 == id2;
277 }
278
279 //********************************************
281 void delete_current_message()
282 {
283 if (valid)
284 {
285 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
286
287#if ETL_HAS_VIRTUAL_MESSAGES
288 pmsg->~imessage();
289#else
290 delete_message(pmsg);
291#endif
292 }
293 }
295
296#if !ETL_HAS_VIRTUAL_MESSAGES
297 //********************************************
298 void delete_message(etl::imessage* pmsg)
299 {
300 (delete_message_type<TMessageTypes>(pmsg) || ...);
301 }
302
303 //********************************************
304 template <typename TType>
305 bool delete_message_type(etl::imessage* pmsg)
306 {
307 if (TType::ID == pmsg->get_message_id())
308 {
309 TType* p = static_cast<TType*>(pmsg);
310 p->~TType();
311 return true;
312 }
313 else
314 {
315 return false;
316 }
317 }
318#endif
319
320 //********************************************
321 void add_new_message(const etl::imessage& msg)
322 {
323 (add_new_message_type<TMessageTypes>(msg) || ...);
324 }
325
326 //********************************************
327 void add_new_message(etl::imessage&& msg)
328 {
329 (add_new_message_type<TMessageTypes>(etl::move(msg)) || ...);
330 }
331
333 //********************************************
335 //********************************************
336 template <typename TMessage>
338 add_new_message_type(TMessage&& msg)
339 {
340 void* p = data;
342 }
344
346 //********************************************
347 template <typename TType>
348 bool add_new_message_type(const etl::imessage& msg)
349 {
350 if (TType::ID == msg.get_message_id())
351 {
352 void* p = data;
353 new (p) TType(static_cast<const TType&>(msg));
354 return true;
355 }
356 else
357 {
358 return false;
359 }
360 }
362
363 //********************************************
364 template <typename TType>
365 bool add_new_message_type(etl::imessage&& msg)
366 {
367 if (TType::ID == msg.get_message_id())
368 {
369 void* p = data;
370 new (p) TType(static_cast<TType&&>(msg));
371 return true;
372 }
373 else
374 {
375 return false;
376 }
377 }
378
380 bool valid;
381 };
382
383#else
384
385 //***************************************************************************
386 // The definition for all 16 message types.
387 //***************************************************************************
388 template <typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
389 typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
390 typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
391 typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
393 {
394 public:
395
396 //********************************************
399 : valid(false)
400 {
401 }
402 #include "private/diagnostic_pop.h"
403
404 //********************************************
406 explicit message_packet(const etl::imessage& msg)
407 {
408 if (accepts(msg))
409 {
410 add_new_message(msg);
411 valid = true;
412 }
413 else
414 {
415 valid = false;
416 }
417
418 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
419 }
420 #include "private/diagnostic_pop.h"
421
422 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
423 //********************************************
426 {
427 if (accepts(msg))
428 {
429 add_new_message(etl::move(msg));
430 valid = true;
431 }
432 else
433 {
434 valid = false;
435 }
436
437 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
438 }
439 #include "private/diagnostic_pop.h"
440 #endif
441
442 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
443 //********************************************
448 explicit message_packet(TMessage&& /*msg*/)
449 : valid(true)
450 {
451 // Not etl::message_packet, not etl::imessage and in typelist.
455
456 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
457 }
458 #include "private/diagnostic_pop.h"
459 #else
460 //********************************************
462 template <typename TMessage>
463 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 &&
464 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
465 !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)
466 : valid(true)
467 {
468 // Not etl::message_packet, not etl::imessage and in typelist.
472
473 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
474 }
475 #include "private/diagnostic_pop.h"
476 #endif
477
478 //**********************************************
481 : valid(other.is_valid())
482 {
483 if (valid)
484 {
485 add_new_message(other.get());
486 }
487 }
488 #include "private/diagnostic_pop.h"
489
490 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
491 //**********************************************
494 : valid(other.is_valid())
495 {
496 if (valid)
497 {
498 add_new_message(etl::move(other.get()));
499 }
500 }
501 #include "private/diagnostic_pop.h"
502 #endif
503
504 //**********************************************
507 {
508 delete_current_message();
509 valid = rhs.is_valid();
510 if (valid)
511 {
512 add_new_message(rhs.get());
513 }
514
515 return *this;
516 }
517 #include "private/diagnostic_pop.h"
518
519 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
520 //**********************************************
523 {
524 delete_current_message();
525 valid = rhs.is_valid();
526 if (valid)
527 {
528 add_new_message(etl::move(rhs.get()));
529 }
530
531 return *this;
532 }
533 #include "private/diagnostic_pop.h"
534 #endif
535
536 //********************************************
538 {
539 delete_current_message();
540 }
541
542 //********************************************
543 etl::imessage& get() ETL_NOEXCEPT
544 {
545 return *static_cast<etl::imessage*>(data);
546 }
547
548 //********************************************
549 const etl::imessage& get() const ETL_NOEXCEPT
550 {
551 return *static_cast<const etl::imessage*>(data);
552 }
553
554 //********************************************
555 bool is_valid() const
556 {
557 return valid;
558 }
559
560 //**********************************************
561 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
562 {
563 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
564 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
565 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id ||
566 T13::ID == id || T14::ID == id || T15::ID == id || T16::ID == id;
567 }
568
569 //**********************************************
570 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
571 {
572 return accepts(msg.get_message_id());
573 }
574
575 //**********************************************
576 template <etl::message_id_t Id>
577 static ETL_CONSTEXPR bool accepts()
578 {
579 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
580 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
581 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id ||
582 T13::ID == Id || T14::ID == Id || T15::ID == Id || T16::ID == Id;
583 }
584
585 //**********************************************
586 template <typename TMessage>
587 static ETL_CONSTEXPR
589 accepts()
590 {
591 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
592 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
593 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID ||
594 T13::ID == TMessage::ID || T14::ID == TMessage::ID || T15::ID == TMessage::ID || T16::ID == TMessage::ID;
595 }
596
597 enum
598 {
601 };
602
603 private:
604
605 //********************************************
607 void delete_current_message()
608 {
609 if (valid)
610 {
611 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
612
613 #if ETL_HAS_VIRTUAL_MESSAGES
614 pmsg->~imessage();
615 #else
616 delete_message(pmsg);
617 #endif
618 }
619 }
620 #include "private/diagnostic_pop.h"
621
622 //********************************************
623 void delete_message(etl::imessage* pmsg)
624 {
625 switch (pmsg->get_message_id())
626 {
627 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
628 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
629 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
630 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
631 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
632 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
633 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
634 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
635 case T9::ID: static_cast<const T9*>(pmsg)->~T9(); break;
636 case T10::ID: static_cast<const T10*>(pmsg)->~T10(); break;
637 case T11::ID: static_cast<const T11*>(pmsg)->~T11(); break;
638 case T12::ID: static_cast<const T12*>(pmsg)->~T12(); break;
639 case T13::ID: static_cast<const T13*>(pmsg)->~T13(); break;
640 case T14::ID: static_cast<const T14*>(pmsg)->~T14(); break;
641 case T15::ID: static_cast<const T15*>(pmsg)->~T15(); break;
642 case T16::ID: static_cast<const T16*>(pmsg)->~T16(); break;
643 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
644 }
645 }
646
647 //********************************************
648 void add_new_message(const etl::imessage& msg)
649 {
650 const size_t id = msg.get_message_id();
651 void* p = data;
652
653 switch (id)
654 {
655 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
656 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
657 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
658 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
659 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
660 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
661 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
662 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
663 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
664 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
665 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
666 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
667 case T13::ID: ::new (p) T13(static_cast<const T13&>(msg)); break;
668 case T14::ID: ::new (p) T14(static_cast<const T14&>(msg)); break;
669 case T15::ID: ::new (p) T15(static_cast<const T15&>(msg)); break;
670 case T16::ID: ::new (p) T16(static_cast<const T16&>(msg)); break;
671 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
672 }
673 }
674
675 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
676 //********************************************
677 void add_new_message(etl::imessage&& msg)
678 {
679 const size_t id = msg.get_message_id();
680 void* p = data;
681
682 switch (id)
683 {
684 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
685 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
686 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
687 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
688 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
689 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
690 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
691 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
692 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
693 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
694 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
695 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
696 case T13::ID: ::new (p) T13(static_cast<T13&&>(msg)); break;
697 case T14::ID: ::new (p) T14(static_cast<T14&&>(msg)); break;
698 case T15::ID: ::new (p) T15(static_cast<T15&&>(msg)); break;
699 case T16::ID: ::new (p) T16(static_cast<T16&&>(msg)); break;
700 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
701 }
702 }
703 #endif
704
706 bool valid;
707 };
708
709 //***************************************************************************
710 // Specialisation for 15 message types.
711 //***************************************************************************
712 template <typename T1, typename T2, typename T3, typename T4,
713 typename T5, typename T6, typename T7, typename T8,
714 typename T9, typename T10, typename T11, typename T12,
715 typename T13, typename T14, typename T15>
716 class message_packet<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, void>
717 {
718 public:
719
720 //********************************************
723 : valid(false)
724 {
725 }
726 #include "private/diagnostic_pop.h"
727
728 //********************************************
730 explicit message_packet(const etl::imessage& msg)
731 {
732 if (accepts(msg))
733 {
734 add_new_message(msg);
735 valid = true;
736 }
737 else
738 {
739 valid = false;
740 }
741
742 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
743 }
744 #include "private/diagnostic_pop.h"
745
746 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
747 //********************************************
750 {
751 if (accepts(msg))
752 {
753 add_new_message(etl::move(msg));
754 valid = true;
755 }
756 else
757 {
758 valid = false;
759 }
760
761 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
762 }
763 #include "private/diagnostic_pop.h"
764 #endif
765
766 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
767 //********************************************
772 explicit message_packet(TMessage&& /*msg*/)
773 : valid(true)
774 {
775 // Not etl::message_packet, not etl::imessage and in typelist.
779
780 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
781 }
782 #include "private/diagnostic_pop.h"
783 #else
784 //********************************************
786 template <typename TMessage>
787 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 &&
788 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
789 !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)
790 : valid(true)
791 {
792 // Not etl::message_packet, not etl::imessage and in typelist.
796
797 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
798 }
799 #include "private/diagnostic_pop.h"
800 #endif
801
802 //**********************************************
805 : valid(other.is_valid())
806 {
807 if (valid)
808 {
809 add_new_message(other.get());
810 }
811 }
812 #include "private/diagnostic_pop.h"
813
814 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
815 //**********************************************
818 : valid(other.is_valid())
819 {
820 if (valid)
821 {
822 add_new_message(etl::move(other.get()));
823 }
824 }
825 #include "private/diagnostic_pop.h"
826 #endif
827
828 //**********************************************
831 {
832 delete_current_message();
833 valid = rhs.is_valid();
834 if (valid)
835 {
836 add_new_message(rhs.get());
837 }
838
839 return *this;
840 }
841 #include "private/diagnostic_pop.h"
842
843 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
844 //**********************************************
847 {
848 delete_current_message();
849 valid = rhs.is_valid();
850 if (valid)
851 {
852 add_new_message(etl::move(rhs.get()));
853 }
854
855 return *this;
856 }
857 #include "private/diagnostic_pop.h"
858 #endif
859
860 //********************************************
862 {
863 delete_current_message();
864 }
865
866 //********************************************
867 etl::imessage& get() ETL_NOEXCEPT
868 {
869 return *static_cast<etl::imessage*>(data);
870 }
871
872 //********************************************
873 const etl::imessage& get() const ETL_NOEXCEPT
874 {
875 return *static_cast<const etl::imessage*>(data);
876 }
877
878 //********************************************
879 bool is_valid() const
880 {
881 return valid;
882 }
883
884 //**********************************************
885 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
886 {
887 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
888 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
889 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id ||
890 T13::ID == id || T14::ID == id || T15::ID == id;
891 }
892
893 //**********************************************
894 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
895 {
896 return accepts(msg.get_message_id());
897 }
898
899 //**********************************************
900 template <etl::message_id_t Id>
901 static ETL_CONSTEXPR bool accepts()
902 {
903 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
904 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
905 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id ||
906 T13::ID == Id || T14::ID == Id || T15::ID == Id;
907 }
908
909 //**********************************************
910 template <typename TMessage>
911 static ETL_CONSTEXPR
913 accepts()
914 {
915 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
916 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
917 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID ||
918 T13::ID == TMessage::ID || T14::ID == TMessage::ID || T15::ID == TMessage::ID;
919 }
920
921 enum
922 {
925 };
926
927 private:
928
929 //********************************************
931 void delete_current_message()
932 {
933 if (valid)
934 {
935 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
936
937
938 #if ETL_HAS_VIRTUAL_MESSAGES
939 pmsg->~imessage();
940 #else
941 delete_message(pmsg);
942 #endif
943 }
944 }
945 #include "private/diagnostic_pop.h"
946
947 //********************************************
948 void delete_message(etl::imessage* pmsg)
949 {
950 switch (pmsg->get_message_id())
951 {
952 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
953 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
954 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
955 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
956 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
957 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
958 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
959 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
960 case T9::ID: static_cast<const T9*>(pmsg)->~T9(); break;
961 case T10::ID: static_cast<const T10*>(pmsg)->~T10(); break;
962 case T11::ID: static_cast<const T11*>(pmsg)->~T11(); break;
963 case T12::ID: static_cast<const T12*>(pmsg)->~T12(); break;
964 case T13::ID: static_cast<const T13*>(pmsg)->~T13(); break;
965 case T14::ID: static_cast<const T14*>(pmsg)->~T14(); break;
966 case T15::ID: static_cast<const T15*>(pmsg)->~T15(); break;
967 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
968 }
969 }
970
971 //********************************************
972 void add_new_message(const etl::imessage& msg)
973 {
974 const size_t id = msg.get_message_id();
975 void* p = data;
976
977 switch (id)
978 {
979 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
980 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
981 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
982 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
983 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
984 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
985 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
986 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
987 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
988 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
989 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
990 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
991 case T13::ID: ::new (p) T13(static_cast<const T13&>(msg)); break;
992 case T14::ID: ::new (p) T14(static_cast<const T14&>(msg)); break;
993 case T15::ID: ::new (p) T15(static_cast<const T15&>(msg)); break;
994 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
995 }
996 }
997
998 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
999 //********************************************
1000 void add_new_message(etl::imessage&& msg)
1001 {
1002 const size_t id = msg.get_message_id();
1003 void* p = data;
1004
1005 switch (id)
1006 {
1007 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
1008 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
1009 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
1010 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
1011 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
1012 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
1013 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
1014 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
1015 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
1016 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
1017 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
1018 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
1019 case T13::ID: ::new (p) T13(static_cast<T13&&>(msg)); break;
1020 case T14::ID: ::new (p) T14(static_cast<T14&&>(msg)); break;
1021 case T15::ID: ::new (p) T15(static_cast<T15&&>(msg)); break;
1022 default: break;
1023 }
1024 }
1025 #endif
1026
1028 bool valid;
1029 };
1030
1031 //***************************************************************************
1032 // Specialisation for 14 message types.
1033 //***************************************************************************
1034 template <typename T1, typename T2, typename T3, typename T4,
1035 typename T5, typename T6, typename T7, typename T8,
1036 typename T9, typename T10, typename T11, typename T12,
1037 typename T13, typename T14>
1039 {
1040 public:
1041
1042 //********************************************
1045 : valid(false)
1046 {
1047 }
1048 #include "private/diagnostic_pop.h"
1049
1050 //********************************************
1052 explicit message_packet(const etl::imessage& msg)
1053 {
1054 if (accepts(msg))
1055 {
1056 add_new_message(msg);
1057 valid = true;
1058 }
1059 else
1060 {
1061 valid = false;
1062 }
1063
1064 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1065 }
1066 #include "private/diagnostic_pop.h"
1067
1068 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1069 //********************************************
1071 explicit message_packet(etl::imessage&& msg)
1072 {
1073 if (accepts(msg))
1074 {
1075 add_new_message(etl::move(msg));
1076 valid = true;
1077 }
1078 else
1079 {
1080 valid = false;
1081 }
1082
1083 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1084 }
1085 #include "private/diagnostic_pop.h"
1086 #endif
1087
1088 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
1089 //********************************************
1094 explicit message_packet(TMessage&& /*msg*/)
1095 : valid(true)
1096 {
1097 // Not etl::message_packet, not etl::imessage and in typelist.
1101
1102 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1103 }
1104 #include "private/diagnostic_pop.h"
1105 #else
1106 //********************************************
1108 template <typename TMessage>
1109 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 &&
1110 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
1111 !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)
1112 : valid(true)
1113 {
1114 // Not etl::message_packet, not etl::imessage and in typelist.
1118
1119 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1120 }
1121 #include "private/diagnostic_pop.h"
1122 #endif
1123
1124 //**********************************************
1127 : valid(other.is_valid())
1128 {
1129 if (valid)
1130 {
1131 add_new_message(other.get());
1132 }
1133 }
1134 #include "private/diagnostic_pop.h"
1135
1136 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1137 //**********************************************
1140 : valid(other.is_valid())
1141 {
1142 if (valid)
1143 {
1144 add_new_message(etl::move(other.get()));
1145 }
1146 }
1147 #include "private/diagnostic_pop.h"
1148 #endif
1149
1150 //**********************************************
1153 {
1154 delete_current_message();
1155 valid = rhs.is_valid();
1156 if (valid)
1157 {
1158 add_new_message(rhs.get());
1159 }
1160
1161 return *this;
1162 }
1163 #include "private/diagnostic_pop.h"
1164
1165 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1166 //**********************************************
1169 {
1170 delete_current_message();
1171 valid = rhs.is_valid();
1172 if (valid)
1173 {
1174 add_new_message(etl::move(rhs.get()));
1175 }
1176
1177 return *this;
1178 }
1179 #include "private/diagnostic_pop.h"
1180 #endif
1181
1182 //********************************************
1184 {
1185 delete_current_message();
1186 }
1187
1188 //********************************************
1189 etl::imessage& get() ETL_NOEXCEPT
1190 {
1191 return *static_cast<etl::imessage*>(data);
1192 }
1193
1194 //********************************************
1195 const etl::imessage& get() const ETL_NOEXCEPT
1196 {
1197 return *static_cast<const etl::imessage*>(data);
1198 }
1199
1200 //********************************************
1201 bool is_valid() const
1202 {
1203 return valid;
1204 }
1205
1206 //**********************************************
1207 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
1208 {
1209 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
1210 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
1211 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id ||
1212 T13::ID == id || T14::ID == id;
1213 }
1214
1215 //**********************************************
1216 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
1217 {
1218 return accepts(msg.get_message_id());
1219 }
1220
1221 //**********************************************
1222 template <etl::message_id_t Id>
1223 static ETL_CONSTEXPR bool accepts()
1224 {
1225 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
1226 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
1227 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id ||
1228 T13::ID == Id || T14::ID == Id;
1229 }
1230
1231 //**********************************************
1232 template <typename TMessage>
1233 static ETL_CONSTEXPR
1235 accepts()
1236 {
1237 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
1238 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
1239 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID ||
1240 T13::ID == TMessage::ID || T14::ID == TMessage::ID;
1241 }
1242
1243 enum
1244 {
1247 };
1248
1249 private:
1250
1251 //********************************************
1253 void delete_current_message()
1254 {
1255 if (valid)
1256 {
1257 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
1258
1259
1260 #if ETL_HAS_VIRTUAL_MESSAGES
1261 pmsg->~imessage();
1262 #else
1263 delete_message(pmsg);
1264 #endif
1265 }
1266 }
1267 #include "private/diagnostic_pop.h"
1268
1269 //********************************************
1270 void delete_message(etl::imessage* pmsg)
1271 {
1272 switch (pmsg->get_message_id())
1273 {
1274 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
1275 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
1276 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
1277 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
1278 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
1279 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
1280 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
1281 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
1282 case T9::ID: static_cast<const T9*>(pmsg)->~T9(); break;
1283 case T10::ID: static_cast<const T10*>(pmsg)->~T10(); break;
1284 case T11::ID: static_cast<const T11*>(pmsg)->~T11(); break;
1285 case T12::ID: static_cast<const T12*>(pmsg)->~T12(); break;
1286 case T13::ID: static_cast<const T13*>(pmsg)->~T13(); break;
1287 case T14::ID: static_cast<const T14*>(pmsg)->~T14(); break;
1288 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
1289 }
1290 }
1291
1292 //********************************************
1293 void add_new_message(const etl::imessage& msg)
1294 {
1295 const size_t id = msg.get_message_id();
1296 void* p = data;
1297
1298 switch (id)
1299 {
1300 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
1301 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
1302 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
1303 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
1304 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
1305 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
1306 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
1307 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
1308 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
1309 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
1310 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
1311 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
1312 case T13::ID: ::new (p) T13(static_cast<const T13&>(msg)); break;
1313 case T14::ID: ::new (p) T14(static_cast<const T14&>(msg)); break;
1314 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
1315 }
1316 }
1317
1318 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1319 //********************************************
1320 void add_new_message(etl::imessage&& msg)
1321 {
1322 const size_t id = msg.get_message_id();
1323 void* p = data;
1324
1325 switch (id)
1326 {
1327 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
1328 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
1329 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
1330 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
1331 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
1332 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
1333 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
1334 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
1335 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
1336 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
1337 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
1338 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
1339 case T13::ID: ::new (p) T13(static_cast<T13&&>(msg)); break;
1340 case T14::ID: ::new (p) T14(static_cast<T14&&>(msg)); break;
1341 default: break;
1342 }
1343 }
1344 #endif
1345
1347 bool valid;
1348 };
1349
1350 //***************************************************************************
1351 // Specialisation for 13 message types.
1352 //***************************************************************************
1353 template <typename T1, typename T2, typename T3, typename T4,
1354 typename T5, typename T6, typename T7, typename T8,
1355 typename T9, typename T10, typename T11, typename T12,
1356 typename T13>
1358 {
1359 public:
1360
1361 //********************************************
1364 : valid(false)
1365 {
1366 }
1367 #include "private/diagnostic_pop.h"
1368
1369 //********************************************
1371 explicit message_packet(const etl::imessage& msg)
1372 {
1373 if (accepts(msg))
1374 {
1375 add_new_message(msg);
1376 valid = true;
1377 }
1378 else
1379 {
1380 valid = false;
1381 }
1382
1383 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1384 }
1385 #include "private/diagnostic_pop.h"
1386
1387 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1388 //********************************************
1390 explicit message_packet(etl::imessage&& msg)
1391 {
1392 if (accepts(msg))
1393 {
1394 add_new_message(etl::move(msg));
1395 valid = true;
1396 }
1397 else
1398 {
1399 valid = false;
1400 }
1401
1402 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1403 }
1404 #include "private/diagnostic_pop.h"
1405 #endif
1406
1407 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
1408 //********************************************
1413 explicit message_packet(TMessage&& /*msg*/)
1414 : valid(true)
1415 {
1416 // Not etl::message_packet, not etl::imessage and in typelist.
1420
1421 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1422 }
1423 #include "private/diagnostic_pop.h"
1424 #else
1425 //********************************************
1427 template <typename TMessage>
1428 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 &&
1429 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
1430 !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)
1431 : valid(true)
1432 {
1433 // Not etl::message_packet, not etl::imessage and in typelist.
1437
1438 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1439 }
1440 #include "private/diagnostic_pop.h"
1441 #endif
1442
1443 //**********************************************
1446 : valid(other.is_valid())
1447 {
1448 if (valid)
1449 {
1450 add_new_message(other.get());
1451 }
1452 }
1453 #include "private/diagnostic_pop.h"
1454
1455 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1456 //**********************************************
1459 : valid(other.is_valid())
1460 {
1461 if (valid)
1462 {
1463 add_new_message(etl::move(other.get()));
1464 }
1465 }
1466 #include "private/diagnostic_pop.h"
1467 #endif
1468
1469 //**********************************************
1472 {
1473 delete_current_message();
1474 valid = rhs.is_valid();
1475 if (valid)
1476 {
1477 add_new_message(rhs.get());
1478 }
1479
1480 return *this;
1481 }
1482 #include "private/diagnostic_pop.h"
1483
1484 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1485 //**********************************************
1488 {
1489 delete_current_message();
1490 valid = rhs.is_valid();
1491 if (valid)
1492 {
1493 add_new_message(etl::move(rhs.get()));
1494 }
1495
1496 return *this;
1497 }
1498 #include "private/diagnostic_pop.h"
1499 #endif
1500
1501 //********************************************
1503 {
1504 delete_current_message();
1505 }
1506
1507 //********************************************
1508 etl::imessage& get() ETL_NOEXCEPT
1509 {
1510 return *static_cast<etl::imessage*>(data);
1511 }
1512
1513 //********************************************
1514 const etl::imessage& get() const ETL_NOEXCEPT
1515 {
1516 return *static_cast<const etl::imessage*>(data);
1517 }
1518
1519 //********************************************
1520 bool is_valid() const
1521 {
1522 return valid;
1523 }
1524
1525 //**********************************************
1526 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
1527 {
1528 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
1529 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
1530 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id ||
1531 T13::ID == id;
1532 }
1533
1534 //**********************************************
1535 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
1536 {
1537 return accepts(msg.get_message_id());
1538 }
1539
1540 //**********************************************
1541 template <etl::message_id_t Id>
1542 static ETL_CONSTEXPR bool accepts()
1543 {
1544 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
1545 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
1546 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id ||
1547 T13::ID == Id;
1548 }
1549
1550 //**********************************************
1551 template <typename TMessage>
1552 static ETL_CONSTEXPR
1554 accepts()
1555 {
1556 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
1557 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
1558 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID ||
1559 T13::ID == TMessage::ID;
1560 }
1561
1562 enum
1563 {
1566 };
1567
1568 private:
1569
1570 //********************************************
1572 void delete_current_message()
1573 {
1574 if (valid)
1575 {
1576 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
1577
1578
1579 #if ETL_HAS_VIRTUAL_MESSAGES
1580 pmsg->~imessage();
1581 #else
1582 delete_message(pmsg);
1583 #endif
1584 }
1585 }
1586 #include "private/diagnostic_pop.h"
1587
1588 //********************************************
1589 void delete_message(etl::imessage* pmsg)
1590 {
1591 switch (pmsg->get_message_id())
1592 {
1593 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
1594 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
1595 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
1596 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
1597 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
1598 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
1599 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
1600 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
1601 case T9::ID: static_cast<const T9*>(pmsg)->~T9(); break;
1602 case T10::ID: static_cast<const T10*>(pmsg)->~T10(); break;
1603 case T11::ID: static_cast<const T11*>(pmsg)->~T11(); break;
1604 case T12::ID: static_cast<const T12*>(pmsg)->~T12(); break;
1605 case T13::ID: static_cast<const T13*>(pmsg)->~T13(); break;
1606 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
1607 }
1608 }
1609
1610 //********************************************
1611 void add_new_message(const etl::imessage& msg)
1612 {
1613 const size_t id = msg.get_message_id();
1614 void* p = data;
1615
1616 switch (id)
1617 {
1618 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
1619 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
1620 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
1621 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
1622 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
1623 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
1624 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
1625 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
1626 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
1627 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
1628 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
1629 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
1630 case T13::ID: ::new (p) T13(static_cast<const T13&>(msg)); break;
1631 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
1632 }
1633 }
1634
1635 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1636 //********************************************
1637 void add_new_message(etl::imessage&& msg)
1638 {
1639 const size_t id = msg.get_message_id();
1640 void* p = data;
1641
1642 switch (id)
1643 {
1644 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
1645 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
1646 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
1647 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
1648 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
1649 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
1650 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
1651 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
1652 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
1653 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
1654 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
1655 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
1656 case T13::ID: ::new (p) T13(static_cast<T13&&>(msg)); break;
1657 default: break;
1658 }
1659 }
1660 #endif
1661
1663 bool valid;
1664 };
1665
1666 //***************************************************************************
1667 // Specialisation for 12 message types.
1668 //***************************************************************************
1669 template <typename T1, typename T2, typename T3, typename T4,
1670 typename T5, typename T6, typename T7, typename T8,
1671 typename T9, typename T10, typename T11, typename T12>
1673 {
1674 public:
1675
1676 //********************************************
1679 : valid(false)
1680 {
1681 }
1682 #include "private/diagnostic_pop.h"
1683
1684 //********************************************
1686 explicit message_packet(const etl::imessage& msg)
1687 {
1688 if (accepts(msg))
1689 {
1690 add_new_message(msg);
1691 valid = true;
1692 }
1693 else
1694 {
1695 valid = false;
1696 }
1697
1698 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1699 }
1700 #include "private/diagnostic_pop.h"
1701
1702 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1703 //********************************************
1705 explicit message_packet(etl::imessage&& msg)
1706 {
1707 if (accepts(msg))
1708 {
1709 add_new_message(etl::move(msg));
1710 valid = true;
1711 }
1712 else
1713 {
1714 valid = false;
1715 }
1716
1717 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
1718 }
1719 #include "private/diagnostic_pop.h"
1720 #endif
1721
1722 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
1723 //********************************************
1728 explicit message_packet(TMessage&& /*msg*/)
1729 : valid(true)
1730 {
1731 // Not etl::message_packet, not etl::imessage and in typelist.
1735
1736 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1737 }
1738 #include "private/diagnostic_pop.h"
1739 #else
1740 //********************************************
1742 template <typename TMessage>
1743 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 &&
1744 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
1745 !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)
1746 : valid(true)
1747 {
1748 // Not etl::message_packet, not etl::imessage and in typelist.
1752
1753 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
1754 }
1755 #include "private/diagnostic_pop.h"
1756 #endif
1757
1758 //**********************************************
1761 : valid(other.is_valid())
1762 {
1763 if (valid)
1764 {
1765 add_new_message(other.get());
1766 }
1767 }
1768 #include "private/diagnostic_pop.h"
1769
1770 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1771 //**********************************************
1774 : valid(other.is_valid())
1775 {
1776 if (valid)
1777 {
1778 add_new_message(etl::move(other.get()));
1779 }
1780 }
1781 #include "private/diagnostic_pop.h"
1782 #endif
1783
1784 //**********************************************
1787 {
1788 delete_current_message();
1789 valid = rhs.is_valid();
1790 if (valid)
1791 {
1792 add_new_message(rhs.get());
1793 }
1794
1795 return *this;
1796 }
1797 #include "private/diagnostic_pop.h"
1798
1799 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1800 //**********************************************
1803 {
1804 delete_current_message();
1805 valid = rhs.is_valid();
1806 if (valid)
1807 {
1808 add_new_message(etl::move(rhs.get()));
1809 }
1810
1811 return *this;
1812 }
1813 #include "private/diagnostic_pop.h"
1814 #endif
1815
1816 //********************************************
1818 {
1819 delete_current_message();
1820 }
1821
1822 //********************************************
1823 etl::imessage& get() ETL_NOEXCEPT
1824 {
1825 return *static_cast<etl::imessage*>(data);
1826 }
1827
1828 //********************************************
1829 const etl::imessage& get() const ETL_NOEXCEPT
1830 {
1831 return *static_cast<const etl::imessage*>(data);
1832 }
1833
1834 //********************************************
1835 bool is_valid() const
1836 {
1837 return valid;
1838 }
1839
1840 //**********************************************
1841 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
1842 {
1843 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
1844 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
1845 T9::ID == id || T10::ID == id || T11::ID == id || T12::ID == id;
1846 }
1847
1848 //**********************************************
1849 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
1850 {
1851 return accepts(msg.get_message_id());
1852 }
1853
1854 //**********************************************
1855 template <etl::message_id_t Id>
1856 static ETL_CONSTEXPR bool accepts()
1857 {
1858 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
1859 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
1860 T9::ID == Id || T10::ID == Id || T11::ID == Id || T12::ID == Id;
1861 }
1862
1863 //**********************************************
1864 template <typename TMessage>
1865 static ETL_CONSTEXPR
1867 accepts()
1868 {
1869 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
1870 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
1871 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID || T12::ID == TMessage::ID;
1872 }
1873
1874 enum
1875 {
1878 };
1879
1880 private:
1881
1882 //********************************************
1884 void delete_current_message()
1885 {
1886 if (valid)
1887 {
1888 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
1889
1890
1891 #if ETL_HAS_VIRTUAL_MESSAGES
1892 pmsg->~imessage();
1893 #else
1894 delete_message(pmsg);
1895 #endif
1896 }
1897 }
1898 #include "private/diagnostic_pop.h"
1899
1900 //********************************************
1901 void delete_message(etl::imessage* pmsg)
1902 {
1903 switch (pmsg->get_message_id())
1904 {
1905 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
1906 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
1907 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
1908 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
1909 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
1910 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
1911 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
1912 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
1913 case T9::ID: static_cast<const T9*>(pmsg)->~T9(); break;
1914 case T10::ID: static_cast<const T10*>(pmsg)->~T10(); break;
1915 case T11::ID: static_cast<const T11*>(pmsg)->~T11(); break;
1916 case T12::ID: static_cast<const T12*>(pmsg)->~T12(); break;
1917 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
1918 }
1919 }
1920
1921 //********************************************
1922 void add_new_message(const etl::imessage& msg)
1923 {
1924 const size_t id = msg.get_message_id();
1925 void* p = data;
1926
1927 switch (id)
1928 {
1929 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
1930 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
1931 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
1932 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
1933 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
1934 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
1935 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
1936 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
1937 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
1938 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
1939 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
1940 case T12::ID: ::new (p) T12(static_cast<const T12&>(msg)); break;
1941 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
1942 }
1943 }
1944
1945 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
1946 //********************************************
1947 void add_new_message(etl::imessage&& msg)
1948 {
1949 const size_t id = msg.get_message_id();
1950 void* p = data;
1951
1952 switch (id)
1953 {
1954 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
1955 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
1956 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
1957 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
1958 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
1959 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
1960 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
1961 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
1962 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
1963 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
1964 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
1965 case T12::ID: ::new (p) T12(static_cast<T12&&>(msg)); break;
1966 default: break;
1967 }
1968 }
1969 #endif
1970
1972 bool valid;
1973 };
1974
1975 //***************************************************************************
1976 // Specialisation for 11 message types.
1977 //***************************************************************************
1978 template <typename T1, typename T2, typename T3, typename T4,
1979 typename T5, typename T6, typename T7, typename T8,
1980 typename T9, typename T10, typename T11>
1982 {
1983 public:
1984
1985 //********************************************
1988 : valid(false)
1989 {
1990 }
1991 #include "private/diagnostic_pop.h"
1992
1993 //********************************************
1995 explicit message_packet(const etl::imessage& msg)
1996 {
1997 if (accepts(msg))
1998 {
1999 add_new_message(msg);
2000 valid = true;
2001 }
2002 else
2003 {
2004 valid = false;
2005 }
2006
2007 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2008 }
2009 #include "private/diagnostic_pop.h"
2010
2011 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2012 //********************************************
2014 explicit message_packet(etl::imessage&& msg)
2015 {
2016 if (accepts(msg))
2017 {
2018 add_new_message(etl::move(msg));
2019 valid = true;
2020 }
2021 else
2022 {
2023 valid = false;
2024 }
2025
2026 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2027 }
2028 #include "private/diagnostic_pop.h"
2029 #endif
2030
2031 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
2032 //********************************************
2037 explicit message_packet(TMessage&& /*msg*/)
2038 : valid(true)
2039 {
2040 // Not etl::message_packet, not etl::imessage and in typelist.
2044
2045 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2046 }
2047 #include "private/diagnostic_pop.h"
2048 #else
2049 //********************************************
2051 template <typename TMessage>
2052 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 &&
2053 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
2054 !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)
2055 : valid(true)
2056 {
2057 // Not etl::message_packet, not etl::imessage and in typelist.
2061
2062 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2063 }
2064 #include "private/diagnostic_pop.h"
2065 #endif
2066
2067 //**********************************************
2070 : valid(other.is_valid())
2071 {
2072 if (valid)
2073 {
2074 add_new_message(other.get());
2075 }
2076 }
2077 #include "private/diagnostic_pop.h"
2078
2079 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2080 //**********************************************
2083 : valid(other.is_valid())
2084 {
2085 if (valid)
2086 {
2087 add_new_message(etl::move(other.get()));
2088 }
2089 }
2090 #include "private/diagnostic_pop.h"
2091 #endif
2092
2093 //**********************************************
2096 {
2097 delete_current_message();
2098 valid = rhs.is_valid();
2099 if (valid)
2100 {
2101 add_new_message(rhs.get());
2102 }
2103
2104 return *this;
2105 }
2106 #include "private/diagnostic_pop.h"
2107
2108 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2109 //**********************************************
2112 {
2113 delete_current_message();
2114 valid = rhs.is_valid();
2115 if (valid)
2116 {
2117 add_new_message(etl::move(rhs.get()));
2118 }
2119
2120 return *this;
2121 }
2122 #include "private/diagnostic_pop.h"
2123 #endif
2124
2125 //********************************************
2127 {
2128 delete_current_message();
2129 }
2130
2131 //********************************************
2132 etl::imessage& get() ETL_NOEXCEPT
2133 {
2134 return *static_cast<etl::imessage*>(data);
2135 }
2136
2137 //********************************************
2138 const etl::imessage& get() const ETL_NOEXCEPT
2139 {
2140 return *static_cast<const etl::imessage*>(data);
2141 }
2142
2143 //********************************************
2144 bool is_valid() const
2145 {
2146 return valid;
2147 }
2148
2149 //**********************************************
2150 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
2151 {
2152 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
2153 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
2154 T9::ID == id || T10::ID == id || T11::ID == id;
2155 }
2156
2157 //**********************************************
2158 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
2159 {
2160 return accepts(msg.get_message_id());
2161 }
2162
2163 //**********************************************
2164 template <etl::message_id_t Id>
2165 static ETL_CONSTEXPR bool accepts()
2166 {
2167 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
2168 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
2169 T9::ID == Id || T10::ID == Id || T11::ID == Id;
2170 }
2171
2172 //**********************************************
2173 template <typename TMessage>
2174 static ETL_CONSTEXPR
2176 accepts()
2177 {
2178 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
2179 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
2180 T9::ID == TMessage::ID || T10::ID == TMessage::ID || T11::ID == TMessage::ID;
2181 }
2182
2183 enum
2184 {
2187 };
2188
2189 private:
2190
2191 //********************************************
2193 void delete_current_message()
2194 {
2195 if (valid)
2196 {
2197 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
2198
2199
2200 #if ETL_HAS_VIRTUAL_MESSAGES
2201 pmsg->~imessage();
2202 #else
2203 delete_message(pmsg);
2204 #endif
2205 }
2206 }
2207 #include "private/diagnostic_pop.h"
2208
2209 //********************************************
2210 void delete_message(etl::imessage* pmsg)
2211 {
2212 switch (pmsg->get_message_id())
2213 {
2214 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
2215 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
2216 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
2217 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
2218 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
2219 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
2220 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
2221 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
2222 case T9::ID: static_cast<const T9*>(pmsg)->~T9(); break;
2223 case T10::ID: static_cast<const T10*>(pmsg)->~T10(); break;
2224 case T11::ID: static_cast<const T11*>(pmsg)->~T11(); break;
2225 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
2226 }
2227 }
2228
2229 //********************************************
2230 void add_new_message(const etl::imessage& msg)
2231 {
2232 const size_t id = msg.get_message_id();
2233 void* p = data;
2234
2235 switch (id)
2236 {
2237 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
2238 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
2239 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
2240 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
2241 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
2242 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
2243 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
2244 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
2245 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
2246 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
2247 case T11::ID: ::new (p) T11(static_cast<const T11&>(msg)); break;
2248 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
2249 }
2250 }
2251
2252 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2253 //********************************************
2254 void add_new_message(etl::imessage&& msg)
2255 {
2256 const size_t id = msg.get_message_id();
2257 void* p = data;
2258
2259 switch (id)
2260 {
2261 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
2262 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
2263 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
2264 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
2265 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
2266 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
2267 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
2268 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
2269 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
2270 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
2271 case T11::ID: ::new (p) T11(static_cast<T11&&>(msg)); break;
2272 default: break;
2273 }
2274 }
2275 #endif
2276
2278 bool valid;
2279 };
2280
2281 //***************************************************************************
2282 // Specialisation for 10 message types.
2283 //***************************************************************************
2284 template <typename T1, typename T2, typename T3, typename T4,
2285 typename T5, typename T6, typename T7, typename T8,
2286 typename T9, typename T10>
2288 {
2289 public:
2290
2291 //********************************************
2294 : valid(false)
2295 {
2296 }
2297 #include "private/diagnostic_pop.h"
2298
2299 //********************************************
2301 explicit message_packet(const etl::imessage& msg)
2302 {
2303 if (accepts(msg))
2304 {
2305 add_new_message(msg);
2306 valid = true;
2307 }
2308 else
2309 {
2310 valid = false;
2311 }
2312
2313 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2314 }
2315 #include "private/diagnostic_pop.h"
2316
2317 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2318 //********************************************
2320 explicit message_packet(etl::imessage&& msg)
2321 {
2322 if (accepts(msg))
2323 {
2324 add_new_message(etl::move(msg));
2325 valid = true;
2326 }
2327 else
2328 {
2329 valid = false;
2330 }
2331
2332 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2333 }
2334 #include "private/diagnostic_pop.h"
2335 #endif
2336
2337 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
2338 //********************************************
2343 explicit message_packet(TMessage&& /*msg*/)
2344 : valid(true)
2345 {
2346 // Not etl::message_packet, not etl::imessage and in typelist.
2350
2351 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2352 }
2353 #include "private/diagnostic_pop.h"
2354 #else
2355 //********************************************
2357 template <typename TMessage>
2358 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 &&
2359 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
2360 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::value, int>::type = 0)
2361 : valid(true)
2362 {
2363 // Not etl::message_packet, not etl::imessage and in typelist.
2367
2368 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2369 }
2370 #include "private/diagnostic_pop.h"
2371 #endif
2372
2373 //**********************************************
2376 : valid(other.is_valid())
2377 {
2378 if (valid)
2379 {
2380 add_new_message(other.get());
2381 }
2382 }
2383 #include "private/diagnostic_pop.h"
2384
2385 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2386 //**********************************************
2389 : valid(other.is_valid())
2390 {
2391 if (valid)
2392 {
2393 add_new_message(etl::move(other.get()));
2394 }
2395 }
2396 #include "private/diagnostic_pop.h"
2397 #endif
2398
2399 //**********************************************
2402 {
2403 delete_current_message();
2404 valid = rhs.is_valid();
2405 if (valid)
2406 {
2407 add_new_message(rhs.get());
2408 }
2409
2410 return *this;
2411 }
2412 #include "private/diagnostic_pop.h"
2413
2414 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2415 //**********************************************
2418 {
2419 delete_current_message();
2420 valid = rhs.is_valid();
2421 if (valid)
2422 {
2423 add_new_message(etl::move(rhs.get()));
2424 }
2425
2426 return *this;
2427 }
2428 #include "private/diagnostic_pop.h"
2429 #endif
2430
2431 //********************************************
2433 {
2434 delete_current_message();
2435 }
2436
2437 //********************************************
2438 etl::imessage& get() ETL_NOEXCEPT
2439 {
2440 return *static_cast<etl::imessage*>(data);
2441 }
2442
2443 //********************************************
2444 const etl::imessage& get() const ETL_NOEXCEPT
2445 {
2446 return *static_cast<const etl::imessage*>(data);
2447 }
2448
2449 //********************************************
2450 bool is_valid() const
2451 {
2452 return valid;
2453 }
2454
2455 //**********************************************
2456 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
2457 {
2458 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
2459 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
2460 T9::ID == id || T10::ID == id;
2461 }
2462
2463 //**********************************************
2464 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
2465 {
2466 return accepts(msg.get_message_id());
2467 }
2468
2469 //**********************************************
2470 template <etl::message_id_t Id>
2471 static ETL_CONSTEXPR bool accepts()
2472 {
2473 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
2474 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
2475 T9::ID == Id || T10::ID == Id;
2476 }
2477
2478 //**********************************************
2479 template <typename TMessage>
2480 static ETL_CONSTEXPR
2482 accepts()
2483 {
2484 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
2485 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
2486 T9::ID == TMessage::ID || T10::ID == TMessage::ID;
2487 }
2488
2489 enum
2490 {
2493 };
2494
2495 private:
2496
2497 //********************************************
2499 void delete_current_message()
2500 {
2501 if (valid)
2502 {
2503 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
2504
2505
2506 #if ETL_HAS_VIRTUAL_MESSAGES
2507 pmsg->~imessage();
2508 #else
2509 delete_message(pmsg);
2510 #endif
2511 }
2512 }
2513 #include "private/diagnostic_pop.h"
2514
2515 //********************************************
2516 void delete_message(etl::imessage* pmsg)
2517 {
2518 switch (pmsg->get_message_id())
2519 {
2520 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
2521 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
2522 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
2523 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
2524 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
2525 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
2526 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
2527 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
2528 case T9::ID: static_cast<const T9*>(pmsg)->~T9(); break;
2529 case T10::ID: static_cast<const T10*>(pmsg)->~T10(); break;
2530 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
2531 }
2532 }
2533
2534 //********************************************
2535 void add_new_message(const etl::imessage& msg)
2536 {
2537 const size_t id = msg.get_message_id();
2538 void* p = data;
2539
2540 switch (id)
2541 {
2542 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
2543 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
2544 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
2545 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
2546 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
2547 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
2548 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
2549 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
2550 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
2551 case T10::ID: ::new (p) T10(static_cast<const T10&>(msg)); break;
2552 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
2553 }
2554 }
2555
2556 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2557 //********************************************
2558 void add_new_message(etl::imessage&& msg)
2559 {
2560 const size_t id = msg.get_message_id();
2561 void* p = data;
2562
2563 switch (id)
2564 {
2565 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
2566 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
2567 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
2568 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
2569 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
2570 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
2571 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
2572 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
2573 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
2574 case T10::ID: ::new (p) T10(static_cast<T10&&>(msg)); break;
2575 default: break;
2576 }
2577 }
2578 #endif
2579
2581 bool valid;
2582 };
2583
2584 //***************************************************************************
2585 // Specialisation for 9 message types.
2586 //***************************************************************************
2587 template <typename T1, typename T2, typename T3, typename T4,
2588 typename T5, typename T6, typename T7, typename T8,
2589 typename T9>
2591 {
2592 public:
2593
2594 //********************************************
2597 : valid(false)
2598 {
2599 }
2600 #include "private/diagnostic_pop.h"
2601
2602 //********************************************
2604 explicit message_packet(const etl::imessage& msg)
2605 {
2606 if (accepts(msg))
2607 {
2608 add_new_message(msg);
2609 valid = true;
2610 }
2611 else
2612 {
2613 valid = false;
2614 }
2615
2616 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2617 }
2618 #include "private/diagnostic_pop.h"
2619
2620 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2621 //********************************************
2623 explicit message_packet(etl::imessage&& msg)
2624 {
2625 if (accepts(msg))
2626 {
2627 add_new_message(etl::move(msg));
2628 valid = true;
2629 }
2630 else
2631 {
2632 valid = false;
2633 }
2634
2635 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2636 }
2637 #include "private/diagnostic_pop.h"
2638 #endif
2639
2640 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
2641 //********************************************
2646 explicit message_packet(TMessage&& /*msg*/)
2647 : valid(true)
2648 {
2649 // Not etl::message_packet, not etl::imessage and in typelist.
2653
2654 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2655 }
2656 #include "private/diagnostic_pop.h"
2657 #else
2658 //********************************************
2660 template <typename TMessage>
2661 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 &&
2662 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
2663 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8, T9>::value, int>::type = 0)
2664 : valid(true)
2665 {
2666 // Not etl::message_packet, not etl::imessage and in typelist.
2670
2671 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2672 }
2673 #include "private/diagnostic_pop.h"
2674 #endif
2675
2676 //**********************************************
2679 : valid(other.is_valid())
2680 {
2681 if (valid)
2682 {
2683 add_new_message(other.get());
2684 }
2685 }
2686 #include "private/diagnostic_pop.h"
2687
2688 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2689 //**********************************************
2692 : valid(other.is_valid())
2693 {
2694 if (valid)
2695 {
2696 add_new_message(etl::move(other.get()));
2697 }
2698 }
2699 #include "private/diagnostic_pop.h"
2700 #endif
2701
2702 //**********************************************
2705 {
2706 delete_current_message();
2707 valid = rhs.is_valid();
2708 if (valid)
2709 {
2710 add_new_message(rhs.get());
2711 }
2712
2713 return *this;
2714 }
2715 #include "private/diagnostic_pop.h"
2716
2717 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2718 //**********************************************
2721 {
2722 delete_current_message();
2723 valid = rhs.is_valid();
2724 if (valid)
2725 {
2726 add_new_message(etl::move(rhs.get()));
2727 }
2728
2729 return *this;
2730 }
2731 #include "private/diagnostic_pop.h"
2732 #endif
2733
2734 //********************************************
2736 {
2737 delete_current_message();
2738 }
2739
2740 //********************************************
2741 etl::imessage& get() ETL_NOEXCEPT
2742 {
2743 return *static_cast<etl::imessage*>(data);
2744 }
2745
2746 //********************************************
2747 const etl::imessage& get() const ETL_NOEXCEPT
2748 {
2749 return *static_cast<const etl::imessage*>(data);
2750 }
2751
2752 //********************************************
2753 bool is_valid() const
2754 {
2755 return valid;
2756 }
2757
2758 //**********************************************
2759 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
2760 {
2761 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
2762 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id ||
2763 T9::ID == id;
2764 }
2765
2766 //**********************************************
2767 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
2768 {
2769 return accepts(msg.get_message_id());
2770 }
2771
2772 //**********************************************
2773 template <etl::message_id_t Id>
2774 static ETL_CONSTEXPR bool accepts()
2775 {
2776 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
2777 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id ||
2778 T9::ID == Id;
2779 }
2780
2781 //**********************************************
2782 template <typename TMessage>
2783 static ETL_CONSTEXPR
2785 accepts()
2786 {
2787 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
2788 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID ||
2789 T9::ID == TMessage::ID;
2790 }
2791
2792 enum
2793 {
2796 };
2797
2798 private:
2799
2800 //********************************************
2802 void delete_current_message()
2803 {
2804 if (valid)
2805 {
2806 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
2807
2808
2809 #if ETL_HAS_VIRTUAL_MESSAGES
2810 pmsg->~imessage();
2811 #else
2812 delete_message(pmsg);
2813 #endif
2814 }
2815 }
2816 #include "private/diagnostic_pop.h"
2817
2818 //********************************************
2819 void delete_message(etl::imessage* pmsg)
2820 {
2821 switch (pmsg->get_message_id())
2822 {
2823 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
2824 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
2825 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
2826 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
2827 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
2828 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
2829 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
2830 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
2831 case T9::ID: static_cast<const T9*>(pmsg)->~T9(); break;
2832 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
2833 }
2834 }
2835
2836 //********************************************
2837 void add_new_message(const etl::imessage& msg)
2838 {
2839 const size_t id = msg.get_message_id();
2840 void* p = data;
2841
2842 switch (id)
2843 {
2844 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
2845 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
2846 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
2847 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
2848 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
2849 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
2850 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
2851 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
2852 case T9::ID: ::new (p) T9(static_cast<const T9&>(msg)); break;
2853 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
2854 }
2855 }
2856
2857 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2858 //********************************************
2859 void add_new_message(etl::imessage&& msg)
2860 {
2861 const size_t id = msg.get_message_id();
2862 void* p = data;
2863
2864 switch (id)
2865 {
2866 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
2867 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
2868 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
2869 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
2870 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
2871 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
2872 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
2873 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
2874 case T9::ID: ::new (p) T9(static_cast<T9&&>(msg)); break;
2875 default: break;
2876 }
2877 }
2878 #endif
2879
2881 bool valid;
2882 };
2883
2884 //***************************************************************************
2885 // Specialisation for 8 message types.
2886 //***************************************************************************
2887 template <typename T1, typename T2, typename T3, typename T4,
2888 typename T5, typename T6, typename T7, typename T8>
2890 {
2891 public:
2892
2893 //********************************************
2896 : valid(false)
2897 {
2898 }
2899 #include "private/diagnostic_pop.h"
2900
2901 //********************************************
2903 explicit message_packet(const etl::imessage& msg)
2904 {
2905 if (accepts(msg))
2906 {
2907 add_new_message(msg);
2908 valid = true;
2909 }
2910 else
2911 {
2912 valid = false;
2913 }
2914
2915 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2916 }
2917 #include "private/diagnostic_pop.h"
2918
2919 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2920 //********************************************
2922 explicit message_packet(etl::imessage&& msg)
2923 {
2924 if (accepts(msg))
2925 {
2926 add_new_message(etl::move(msg));
2927 valid = true;
2928 }
2929 else
2930 {
2931 valid = false;
2932 }
2933
2934 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
2935 }
2936 #include "private/diagnostic_pop.h"
2937 #endif
2938
2939 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
2940 //********************************************
2945 explicit message_packet(TMessage&& /*msg*/)
2946 : valid(true)
2947 {
2948 // Not etl::message_packet, not etl::imessage and in typelist.
2952
2953 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2954 }
2955 #include "private/diagnostic_pop.h"
2956 #else
2957 //********************************************
2959 template <typename TMessage>
2960 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 &&
2961 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
2962 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7, T8>::value, int>::type = 0)
2963 : valid(true)
2964 {
2965 // Not etl::message_packet, not etl::imessage and in typelist.
2969
2970 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
2971 }
2972 #include "private/diagnostic_pop.h"
2973 #endif
2974
2975 //**********************************************
2978 : valid(other.is_valid())
2979 {
2980 if (valid)
2981 {
2982 add_new_message(other.get());
2983 }
2984 }
2985 #include "private/diagnostic_pop.h"
2986
2987 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
2988 //**********************************************
2991 : valid(other.is_valid())
2992 {
2993 if (valid)
2994 {
2995 add_new_message(etl::move(other.get()));
2996 }
2997 }
2998 #include "private/diagnostic_pop.h"
2999 #endif
3000
3001 //**********************************************
3004 {
3005 delete_current_message();
3006 valid = rhs.is_valid();
3007 if (valid)
3008 {
3009 add_new_message(rhs.get());
3010 }
3011
3012 return *this;
3013 }
3014 #include "private/diagnostic_pop.h"
3015
3016 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3017 //**********************************************
3020 {
3021 delete_current_message();
3022 valid = rhs.is_valid();
3023 if (valid)
3024 {
3025 add_new_message(etl::move(rhs.get()));
3026 }
3027
3028 return *this;
3029 }
3030 #include "private/diagnostic_pop.h"
3031 #endif
3032
3033 //********************************************
3035 {
3036 delete_current_message();
3037 }
3038
3039 //********************************************
3040 etl::imessage& get() ETL_NOEXCEPT
3041 {
3042 return *static_cast<etl::imessage*>(data);
3043 }
3044
3045 //********************************************
3046 const etl::imessage& get() const ETL_NOEXCEPT
3047 {
3048 return *static_cast<const etl::imessage*>(data);
3049 }
3050
3051 //********************************************
3052 bool is_valid() const
3053 {
3054 return valid;
3055 }
3056
3057 //**********************************************
3058 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
3059 {
3060 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
3061 T5::ID == id || T6::ID == id || T7::ID == id || T8::ID == id;
3062 }
3063
3064 //**********************************************
3065 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
3066 {
3067 return accepts(msg.get_message_id());
3068 }
3069
3070 //**********************************************
3071 template <etl::message_id_t Id>
3072 static ETL_CONSTEXPR bool accepts()
3073 {
3074 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
3075 T5::ID == Id || T6::ID == Id || T7::ID == Id || T8::ID == Id;
3076 }
3077
3078 //**********************************************
3079 template <typename TMessage>
3080 static ETL_CONSTEXPR
3082 accepts()
3083 {
3084 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
3085 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID || T8::ID == TMessage::ID;
3086 }
3087
3088 enum
3089 {
3092 };
3093
3094 private:
3095
3096 //********************************************
3098 void delete_current_message()
3099 {
3100 if (valid)
3101 {
3102 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
3103
3104
3105 #if ETL_HAS_VIRTUAL_MESSAGES
3106 pmsg->~imessage();
3107 #else
3108 delete_message(pmsg);
3109 #endif
3110 }
3111 }
3112 #include "private/diagnostic_pop.h"
3113
3114 //********************************************
3115 void delete_message(etl::imessage* pmsg)
3116 {
3117 switch (pmsg->get_message_id())
3118 {
3119 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
3120 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
3121 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
3122 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
3123 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
3124 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
3125 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
3126 case T8::ID: static_cast<const T8*>(pmsg)->~T8(); break;
3127 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
3128 }
3129 }
3130
3131 //********************************************
3132 void add_new_message(const etl::imessage& msg)
3133 {
3134 const size_t id = msg.get_message_id();
3135 void* p = data;
3136
3137 switch (id)
3138 {
3139 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
3140 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
3141 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
3142 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
3143 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
3144 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
3145 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
3146 case T8::ID: ::new (p) T8(static_cast<const T8&>(msg)); break;
3147 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
3148 }
3149 }
3150
3151 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3152 //********************************************
3153 void add_new_message(etl::imessage&& msg)
3154 {
3155 const size_t id = msg.get_message_id();
3156 void* p = data;
3157
3158 switch (id)
3159 {
3160 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
3161 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
3162 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
3163 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
3164 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
3165 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
3166 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
3167 case T8::ID: ::new (p) T8(static_cast<T8&&>(msg)); break;
3168 default: break;
3169 }
3170 }
3171 #endif
3172
3174 bool valid;
3175 };
3176
3177 //***************************************************************************
3178 // Specialisation for 7 message types.
3179 //***************************************************************************
3180 template <typename T1, typename T2, typename T3, typename T4,
3181 typename T5, typename T6, typename T7>
3183 {
3184 public:
3185
3186 //********************************************
3189 : valid(false)
3190 {
3191 }
3192 #include "private/diagnostic_pop.h"
3193
3194 //********************************************
3196 explicit message_packet(const etl::imessage& msg)
3197 {
3198 if (accepts(msg))
3199 {
3200 add_new_message(msg);
3201 valid = true;
3202 }
3203 else
3204 {
3205 valid = false;
3206 }
3207
3208 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3209 }
3210 #include "private/diagnostic_pop.h"
3211
3212 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3213 //********************************************
3215 explicit message_packet(etl::imessage&& msg)
3216 {
3217 if (accepts(msg))
3218 {
3219 add_new_message(etl::move(msg));
3220 valid = true;
3221 }
3222 else
3223 {
3224 valid = false;
3225 }
3226
3227 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3228 }
3229 #include "private/diagnostic_pop.h"
3230 #endif
3231
3232 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
3233 //********************************************
3238 explicit message_packet(TMessage&& /*msg*/)
3239 : valid(true)
3240 {
3241 // Not etl::message_packet, not etl::imessage and in typelist.
3245
3246 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3247 }
3248 #include "private/diagnostic_pop.h"
3249 #else
3250 //********************************************
3252 template <typename TMessage>
3253 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 &&
3254 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
3255 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6, T7>::value, int>::type = 0)
3256 : valid(true)
3257 {
3258 // Not etl::message_packet, not etl::imessage and in typelist.
3262
3263 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3264 }
3265 #include "private/diagnostic_pop.h"
3266 #endif
3267
3268 //**********************************************
3271 : valid(other.is_valid())
3272 {
3273 if (valid)
3274 {
3275 add_new_message(other.get());
3276 }
3277 }
3278 #include "private/diagnostic_pop.h"
3279
3280 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3281 //**********************************************
3284 : valid(other.is_valid())
3285 {
3286 if (valid)
3287 {
3288 add_new_message(etl::move(other.get()));
3289 }
3290 }
3291 #include "private/diagnostic_pop.h"
3292 #endif
3293
3294 //**********************************************
3297 {
3298 delete_current_message();
3299 valid = rhs.is_valid();
3300 if (valid)
3301 {
3302 add_new_message(rhs.get());
3303 }
3304
3305 return *this;
3306 }
3307 #include "private/diagnostic_pop.h"
3308
3309 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3310 //**********************************************
3313 {
3314 delete_current_message();
3315 valid = rhs.is_valid();
3316 if (valid)
3317 {
3318 add_new_message(etl::move(rhs.get()));
3319 }
3320
3321 return *this;
3322 }
3323 #include "private/diagnostic_pop.h"
3324 #endif
3325
3326 //********************************************
3328 {
3329 delete_current_message();
3330 }
3331
3332 //********************************************
3333 etl::imessage& get() ETL_NOEXCEPT
3334 {
3335 return *static_cast<etl::imessage*>(data);
3336 }
3337
3338 //********************************************
3339 const etl::imessage& get() const ETL_NOEXCEPT
3340 {
3341 return *static_cast<const etl::imessage*>(data);
3342 }
3343
3344 //********************************************
3345 bool is_valid() const
3346 {
3347 return valid;
3348 }
3349
3350 //**********************************************
3351 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
3352 {
3353 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
3354 T5::ID == id || T6::ID == id || T7::ID == id;
3355 }
3356
3357 //**********************************************
3358 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
3359 {
3360 return accepts(msg.get_message_id());
3361 }
3362
3363 //**********************************************
3364 template <etl::message_id_t Id>
3365 static ETL_CONSTEXPR bool accepts()
3366 {
3367 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
3368 T5::ID == Id || T6::ID == Id || T7::ID == Id;
3369 }
3370
3371 //**********************************************
3372 template <typename TMessage>
3373 static ETL_CONSTEXPR
3375 accepts()
3376 {
3377 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
3378 T5::ID == TMessage::ID || T6::ID == TMessage::ID || T7::ID == TMessage::ID;
3379 }
3380
3381 enum
3382 {
3385 };
3386
3387 private:
3388
3389 //********************************************
3391 void delete_current_message()
3392 {
3393 if (valid)
3394 {
3395 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
3396
3397
3398 #if ETL_HAS_VIRTUAL_MESSAGES
3399 pmsg->~imessage();
3400 #else
3401 delete_message(pmsg);
3402 #endif
3403 }
3404 }
3405 #include "private/diagnostic_pop.h"
3406
3407 //********************************************
3408 void delete_message(etl::imessage* pmsg)
3409 {
3410 switch (pmsg->get_message_id())
3411 {
3412 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
3413 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
3414 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
3415 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
3416 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
3417 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
3418 case T7::ID: static_cast<const T7*>(pmsg)->~T7(); break;
3419 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
3420 }
3421 }
3422
3423 //********************************************
3424 void add_new_message(const etl::imessage& msg)
3425 {
3426 const size_t id = msg.get_message_id();
3427 void* p = data;
3428
3429 switch (id)
3430 {
3431 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
3432 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
3433 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
3434 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
3435 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
3436 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
3437 case T7::ID: ::new (p) T7(static_cast<const T7&>(msg)); break;
3438 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
3439 }
3440 }
3441
3442 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3443 //********************************************
3444 void add_new_message(etl::imessage&& msg)
3445 {
3446 const size_t id = msg.get_message_id();
3447 void* p = data;
3448
3449 switch (id)
3450 {
3451 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
3452 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
3453 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
3454 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
3455 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
3456 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
3457 case T7::ID: ::new (p) T7(static_cast<T7&&>(msg)); break;
3458 default: break;
3459 }
3460 }
3461 #endif
3462
3464 bool valid;
3465 };
3466
3467 //***************************************************************************
3468 // Specialisation for 6 message types.
3469 //***************************************************************************
3470 template <typename T1, typename T2, typename T3, typename T4,
3471 typename T5, typename T6>
3473 {
3474 public:
3475
3476 //********************************************
3479 : valid(false)
3480 {
3481 }
3482 #include "private/diagnostic_pop.h"
3483
3484 //********************************************
3486 explicit message_packet(const etl::imessage& msg)
3487 {
3488 if (accepts(msg))
3489 {
3490 add_new_message(msg);
3491 valid = true;
3492 }
3493 else
3494 {
3495 valid = false;
3496 }
3497
3498 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3499 }
3500 #include "private/diagnostic_pop.h"
3501
3502 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3503 //********************************************
3505 explicit message_packet(etl::imessage&& msg)
3506 {
3507 if (accepts(msg))
3508 {
3509 add_new_message(etl::move(msg));
3510 valid = true;
3511 }
3512 else
3513 {
3514 valid = false;
3515 }
3516
3517 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3518 }
3519 #include "private/diagnostic_pop.h"
3520 #endif
3521
3522 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
3523 //********************************************
3528 explicit message_packet(TMessage&& /*msg*/)
3529 : valid(true)
3530 {
3531 // Not etl::message_packet, not etl::imessage and in typelist.
3535
3536 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3537 }
3538 #include "private/diagnostic_pop.h"
3539 #else
3540 //********************************************
3542 template <typename TMessage>
3543 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 &&
3544 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
3545 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5, T6>::value, int>::type = 0)
3546 : valid(true)
3547 {
3548 // Not etl::message_packet, not etl::imessage and in typelist.
3552
3553 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3554 }
3555 #include "private/diagnostic_pop.h"
3556 #endif
3557
3558 //**********************************************
3561 : valid(other.is_valid())
3562 {
3563 if (valid)
3564 {
3565 add_new_message(other.get());
3566 }
3567 }
3568 #include "private/diagnostic_pop.h"
3569
3570 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3571 //**********************************************
3574 : valid(other.is_valid())
3575 {
3576 if (valid)
3577 {
3578 add_new_message(etl::move(other.get()));
3579 }
3580 }
3581 #include "private/diagnostic_pop.h"
3582 #endif
3583
3584 //**********************************************
3587 {
3588 delete_current_message();
3589 valid = rhs.is_valid();
3590 if (valid)
3591 {
3592 add_new_message(rhs.get());
3593 }
3594
3595 return *this;
3596 }
3597 #include "private/diagnostic_pop.h"
3598
3599 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3600 //**********************************************
3603 {
3604 delete_current_message();
3605 valid = rhs.is_valid();
3606 if (valid)
3607 {
3608 add_new_message(etl::move(rhs.get()));
3609 }
3610
3611 return *this;
3612 }
3613 #include "private/diagnostic_pop.h"
3614 #endif
3615
3616 //********************************************
3618 {
3619 delete_current_message();
3620 }
3621
3622 //********************************************
3623 etl::imessage& get() ETL_NOEXCEPT
3624 {
3625 return *static_cast<etl::imessage*>(data);
3626 }
3627
3628 //********************************************
3629 const etl::imessage& get() const ETL_NOEXCEPT
3630 {
3631 return *static_cast<const etl::imessage*>(data);
3632 }
3633
3634 //********************************************
3635 bool is_valid() const
3636 {
3637 return valid;
3638 }
3639
3640 //**********************************************
3641 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
3642 {
3643 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
3644 T5::ID == id || T6::ID == id;
3645 }
3646
3647 //**********************************************
3648 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
3649 {
3650 return accepts(msg.get_message_id());
3651 }
3652
3653 //**********************************************
3654 template <etl::message_id_t Id>
3655 static ETL_CONSTEXPR bool accepts()
3656 {
3657 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
3658 T5::ID == Id || T6::ID == Id;
3659 }
3660
3661 //**********************************************
3662 template <typename TMessage>
3663 static ETL_CONSTEXPR
3665 accepts()
3666 {
3667 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
3668 T5::ID == TMessage::ID || T6::ID == TMessage::ID;
3669 }
3670
3671 enum
3672 {
3675 };
3676
3677 private:
3678
3679 //********************************************
3681 void delete_current_message()
3682 {
3683 if (valid)
3684 {
3685 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
3686
3687
3688 #if ETL_HAS_VIRTUAL_MESSAGES
3689 pmsg->~imessage();
3690 #else
3691 delete_message(pmsg);
3692 #endif
3693 }
3694 }
3695 #include "private/diagnostic_pop.h"
3696
3697 //********************************************
3698 void delete_message(etl::imessage* pmsg)
3699 {
3700 switch (pmsg->get_message_id())
3701 {
3702 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
3703 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
3704 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
3705 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
3706 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
3707 case T6::ID: static_cast<const T6*>(pmsg)->~T6(); break;
3708 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
3709 }
3710 }
3711
3712 //********************************************
3713 void add_new_message(const etl::imessage& msg)
3714 {
3715 const size_t id = msg.get_message_id();
3716 void* p = data;
3717
3718 switch (id)
3719 {
3720 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
3721 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
3722 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
3723 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
3724 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
3725 case T6::ID: ::new (p) T6(static_cast<const T6&>(msg)); break;
3726 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
3727 }
3728 }
3729
3730 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3731 //********************************************
3732 void add_new_message(etl::imessage&& msg)
3733 {
3734 const size_t id = msg.get_message_id();
3735 void* p = data;
3736
3737 switch (id)
3738 {
3739 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
3740 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
3741 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
3742 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
3743 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
3744 case T6::ID: ::new (p) T6(static_cast<T6&&>(msg)); break;
3745 default: break;
3746 }
3747 }
3748 #endif
3749
3751 bool valid;
3752 };
3753
3754 //***************************************************************************
3755 // Specialisation for 5 message types.
3756 //***************************************************************************
3757 template <typename T1, typename T2, typename T3, typename T4,
3758 typename T5>
3760 {
3761 public:
3762
3763 //********************************************
3766 : valid(false)
3767 {
3768 }
3769 #include "private/diagnostic_pop.h"
3770
3771 //********************************************
3773 explicit message_packet(const etl::imessage& msg)
3774 {
3775 if (accepts(msg))
3776 {
3777 add_new_message(msg);
3778 valid = true;
3779 }
3780 else
3781 {
3782 valid = false;
3783 }
3784
3785 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3786 }
3787 #include "private/diagnostic_pop.h"
3788
3789 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3790 //********************************************
3792 explicit message_packet(etl::imessage&& msg)
3793 {
3794 if (accepts(msg))
3795 {
3796 add_new_message(etl::move(msg));
3797 valid = true;
3798 }
3799 else
3800 {
3801 valid = false;
3802 }
3803
3804 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
3805 }
3806 #include "private/diagnostic_pop.h"
3807 #endif
3808
3809 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
3810 //********************************************
3815 explicit message_packet(TMessage&& /*msg*/)
3816 : valid(true)
3817 {
3818 // Not etl::message_packet, not etl::imessage and in typelist.
3822
3823 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3824 }
3825 #include "private/diagnostic_pop.h"
3826 #else
3827 //********************************************
3829 template <typename TMessage>
3830 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 &&
3831 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
3832 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4, T5>::value, int>::type = 0)
3833 : valid(true)
3834 {
3835 // Not etl::message_packet, not etl::imessage and in typelist.
3839
3840 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
3841 }
3842 #include "private/diagnostic_pop.h"
3843 #endif
3844
3845 //**********************************************
3848 : valid(other.is_valid())
3849 {
3850 if (valid)
3851 {
3852 add_new_message(other.get());
3853 }
3854 }
3855 #include "private/diagnostic_pop.h"
3856
3857 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3858 //**********************************************
3861 : valid(other.is_valid())
3862 {
3863 if (valid)
3864 {
3865 add_new_message(etl::move(other.get()));
3866 }
3867 }
3868 #include "private/diagnostic_pop.h"
3869 #endif
3870
3871 //**********************************************
3874 {
3875 delete_current_message();
3876 valid = rhs.is_valid();
3877 if (valid)
3878 {
3879 add_new_message(rhs.get());
3880 }
3881
3882 return *this;
3883 }
3884 #include "private/diagnostic_pop.h"
3885
3886 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
3887 //**********************************************
3890 {
3891 delete_current_message();
3892 valid = rhs.is_valid();
3893 if (valid)
3894 {
3895 add_new_message(etl::move(rhs.get()));
3896 }
3897
3898 return *this;
3899 }
3900 #include "private/diagnostic_pop.h"
3901 #endif
3902
3903 //********************************************
3905 {
3906 delete_current_message();
3907 }
3908
3909 //********************************************
3910 etl::imessage& get() ETL_NOEXCEPT
3911 {
3912 return *static_cast<etl::imessage*>(data);
3913 }
3914
3915 //********************************************
3916 const etl::imessage& get() const ETL_NOEXCEPT
3917 {
3918 return *static_cast<const etl::imessage*>(data);
3919 }
3920
3921 //********************************************
3922 bool is_valid() const
3923 {
3924 return valid;
3925 }
3926
3927 //**********************************************
3928 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
3929 {
3930 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id ||
3931 T5::ID == id;
3932 }
3933
3934 //**********************************************
3935 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
3936 {
3937 return accepts(msg.get_message_id());
3938 }
3939
3940 //**********************************************
3941 template <etl::message_id_t Id>
3942 static ETL_CONSTEXPR bool accepts()
3943 {
3944 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id ||
3945 T5::ID == Id;
3946 }
3947
3948 //**********************************************
3949 template <typename TMessage>
3950 static ETL_CONSTEXPR
3952 accepts()
3953 {
3954 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID ||
3955 T5::ID == TMessage::ID;
3956 }
3957
3958 enum
3959 {
3962 };
3963
3964 private:
3965
3966 //********************************************
3968 void delete_current_message()
3969 {
3970 if (valid)
3971 {
3972 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
3973
3974
3975 #if ETL_HAS_VIRTUAL_MESSAGES
3976 pmsg->~imessage();
3977 #else
3978 delete_message(pmsg);
3979 #endif
3980 }
3981 }
3982 #include "private/diagnostic_pop.h"
3983
3984 //********************************************
3985 void delete_message(etl::imessage* pmsg)
3986 {
3987 switch (pmsg->get_message_id())
3988 {
3989 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
3990 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
3991 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
3992 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
3993 case T5::ID: static_cast<const T5*>(pmsg)->~T5(); break;
3994 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
3995 }
3996 }
3997
3998 //********************************************
3999 void add_new_message(const etl::imessage& msg)
4000 {
4001 const size_t id = msg.get_message_id();
4002 void* p = data;
4003
4004 switch (id)
4005 {
4006 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
4007 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
4008 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
4009 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
4010 case T5::ID: ::new (p) T5(static_cast<const T5&>(msg)); break;
4011 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
4012 }
4013 }
4014
4015 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4016 //********************************************
4017 void add_new_message(etl::imessage&& msg)
4018 {
4019 const size_t id = msg.get_message_id();
4020 void* p = data;
4021
4022 switch (id)
4023 {
4024 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
4025 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
4026 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
4027 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
4028 case T5::ID: ::new (p) T5(static_cast<T5&&>(msg)); break;
4029 default: break;
4030 }
4031 }
4032 #endif
4033
4035 bool valid;
4036 };
4037
4038 //***************************************************************************
4039 // Specialisation for 4 message types.
4040 //***************************************************************************
4041 template <typename T1, typename T2, typename T3, typename T4>
4043 {
4044 public:
4045
4046 //********************************************
4049 : valid(false)
4050 {
4051 }
4052 #include "private/diagnostic_pop.h"
4053
4054 //********************************************
4056 explicit message_packet(const etl::imessage& msg)
4057 {
4058 if (accepts(msg))
4059 {
4060 add_new_message(msg);
4061 valid = true;
4062 }
4063 else
4064 {
4065 valid = false;
4066 }
4067
4068 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4069 }
4070 #include "private/diagnostic_pop.h"
4071
4072 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4073 //********************************************
4075 explicit message_packet(etl::imessage&& msg)
4076 {
4077 if (accepts(msg))
4078 {
4079 add_new_message(etl::move(msg));
4080 valid = true;
4081 }
4082 else
4083 {
4084 valid = false;
4085 }
4086
4087 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4088 }
4089 #include "private/diagnostic_pop.h"
4090 #endif
4091
4092 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
4093 //********************************************
4098 explicit message_packet(TMessage&& /*msg*/)
4099 : valid(true)
4100 {
4101 // Not etl::message_packet, not etl::imessage and in typelist.
4105
4106 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4107 }
4108 #include "private/diagnostic_pop.h"
4109 #else
4110 //********************************************
4112 template <typename TMessage>
4113 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 &&
4114 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
4115 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3, T4>::value, int>::type = 0)
4116 : valid(true)
4117 {
4118 // Not etl::message_packet, not etl::imessage and in typelist.
4122
4123 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4124 }
4125 #include "private/diagnostic_pop.h"
4126 #endif
4127
4128 //**********************************************
4131 : valid(other.is_valid())
4132 {
4133 if (valid)
4134 {
4135 add_new_message(other.get());
4136 }
4137 }
4138 #include "private/diagnostic_pop.h"
4139
4140 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4141 //**********************************************
4144 : valid(other.is_valid())
4145 {
4146 if (valid)
4147 {
4148 add_new_message(etl::move(other.get()));
4149 }
4150 }
4151 #include "private/diagnostic_pop.h"
4152 #endif
4153
4154 //**********************************************
4157 {
4158 delete_current_message();
4159 valid = rhs.is_valid();
4160 if (valid)
4161 {
4162 add_new_message(rhs.get());
4163 }
4164
4165 return *this;
4166 }
4167 #include "private/diagnostic_pop.h"
4168
4169 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4170 //**********************************************
4173 {
4174 delete_current_message();
4175 valid = rhs.is_valid();
4176 if (valid)
4177 {
4178 add_new_message(etl::move(rhs.get()));
4179 }
4180
4181 return *this;
4182 }
4183 #include "private/diagnostic_pop.h"
4184 #endif
4185
4186 //********************************************
4188 {
4189 delete_current_message();
4190 }
4191
4192 //********************************************
4193 etl::imessage& get() ETL_NOEXCEPT
4194 {
4195 return *static_cast<etl::imessage*>(data);
4196 }
4197
4198 //********************************************
4199 const etl::imessage& get() const ETL_NOEXCEPT
4200 {
4201 return *static_cast<const etl::imessage*>(data);
4202 }
4203
4204 //********************************************
4205 bool is_valid() const
4206 {
4207 return valid;
4208 }
4209
4210 //**********************************************
4211 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
4212 {
4213 return T1::ID == id || T2::ID == id || T3::ID == id || T4::ID == id;
4214 }
4215
4216 //**********************************************
4217 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
4218 {
4219 return accepts(msg.get_message_id());
4220 }
4221
4222 //**********************************************
4223 template <etl::message_id_t Id>
4224 static ETL_CONSTEXPR bool accepts()
4225 {
4226 return T1::ID == Id || T2::ID == Id || T3::ID == Id || T4::ID == Id;
4227 }
4228
4229 //**********************************************
4230 template <typename TMessage>
4231 static ETL_CONSTEXPR
4233 accepts()
4234 {
4235 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID || T4::ID == TMessage::ID;
4236 }
4237
4238 enum
4239 {
4242 };
4243
4244 private:
4245
4246 //********************************************
4248 void delete_current_message()
4249 {
4250 if (valid)
4251 {
4252 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
4253
4254
4255 #if ETL_HAS_VIRTUAL_MESSAGES
4256 pmsg->~imessage();
4257 #else
4258 delete_message(pmsg);
4259 #endif
4260 }
4261 }
4262 #include "private/diagnostic_pop.h"
4263
4264 //********************************************
4265 void delete_message(etl::imessage* pmsg)
4266 {
4267 switch (pmsg->get_message_id())
4268 {
4269 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
4270 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
4271 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
4272 case T4::ID: static_cast<const T4*>(pmsg)->~T4(); break;
4273 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
4274 }
4275 }
4276
4277 //********************************************
4278 void add_new_message(const etl::imessage& msg)
4279 {
4280 const size_t id = msg.get_message_id();
4281 void* p = data;
4282
4283 switch (id)
4284 {
4285 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
4286 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
4287 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
4288 case T4::ID: ::new (p) T4(static_cast<const T4&>(msg)); break;
4289 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
4290 }
4291 }
4292
4293 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4294 //********************************************
4295 void add_new_message(etl::imessage&& msg)
4296 {
4297 const size_t id = msg.get_message_id();
4298 void* p = data;
4299
4300 switch (id)
4301 {
4302 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
4303 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
4304 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
4305 case T4::ID: ::new (p) T4(static_cast<T4&&>(msg)); break;
4306 default: break;
4307 }
4308 }
4309 #endif
4310
4312 bool valid;
4313 };
4314
4315 //***************************************************************************
4316 // Specialisation for 3 message types.
4317 //***************************************************************************
4318 template <typename T1, typename T2, typename T3>
4320 {
4321 public:
4322
4323 //********************************************
4326 : valid(false)
4327 {
4328 }
4329 #include "private/diagnostic_pop.h"
4330
4331 //********************************************
4333 explicit message_packet(const etl::imessage& msg)
4334 {
4335 if (accepts(msg))
4336 {
4337 add_new_message(msg);
4338 valid = true;
4339 }
4340 else
4341 {
4342 valid = false;
4343 }
4344
4345 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4346 }
4347 #include "private/diagnostic_pop.h"
4348
4349 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4350 //********************************************
4352 explicit message_packet(etl::imessage&& msg)
4353 {
4354 if (accepts(msg))
4355 {
4356 add_new_message(etl::move(msg));
4357 valid = true;
4358 }
4359 else
4360 {
4361 valid = false;
4362 }
4363
4364 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4365 }
4366 #include "private/diagnostic_pop.h"
4367 #endif
4368
4369 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
4370 //********************************************
4375 explicit message_packet(TMessage&& /*msg*/)
4376 : valid(true)
4377 {
4378 // Not etl::message_packet, not etl::imessage and in typelist.
4382
4383 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4384 }
4385 #include "private/diagnostic_pop.h"
4386 #else
4387 //********************************************
4389 template <typename TMessage>
4390 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 &&
4391 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
4392 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2, T3>::value, int>::type = 0)
4393 : valid(true)
4394 {
4395 // Not etl::message_packet, not etl::imessage and in typelist.
4399
4400 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4401 }
4402 #include "private/diagnostic_pop.h"
4403 #endif
4404
4405 //**********************************************
4408 : valid(other.is_valid())
4409 {
4410 if (valid)
4411 {
4412 add_new_message(other.get());
4413 }
4414 }
4415 #include "private/diagnostic_pop.h"
4416
4417 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4418 //**********************************************
4421 : valid(other.is_valid())
4422 {
4423 if (valid)
4424 {
4425 add_new_message(etl::move(other.get()));
4426 }
4427 }
4428 #include "private/diagnostic_pop.h"
4429 #endif
4430
4431 //**********************************************
4434 {
4435 delete_current_message();
4436 valid = rhs.is_valid();
4437 if (valid)
4438 {
4439 add_new_message(rhs.get());
4440 }
4441
4442 return *this;
4443 }
4444 #include "private/diagnostic_pop.h"
4445
4446 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4447 //**********************************************
4450 {
4451 delete_current_message();
4452 valid = rhs.is_valid();
4453 if (valid)
4454 {
4455 add_new_message(etl::move(rhs.get()));
4456 }
4457
4458 return *this;
4459 }
4460 #include "private/diagnostic_pop.h"
4461 #endif
4462
4463 //********************************************
4465 {
4466 delete_current_message();
4467 }
4468
4469 //********************************************
4470 etl::imessage& get() ETL_NOEXCEPT
4471 {
4472 return *static_cast<etl::imessage*>(data);
4473 }
4474
4475 //********************************************
4476 const etl::imessage& get() const ETL_NOEXCEPT
4477 {
4478 return *static_cast<const etl::imessage*>(data);
4479 }
4480
4481 //********************************************
4482 bool is_valid() const
4483 {
4484 return valid;
4485 }
4486
4487 //**********************************************
4488 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
4489 {
4490 return T1::ID == id || T2::ID == id || T3::ID == id;
4491 }
4492
4493 //**********************************************
4494 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
4495 {
4496 return accepts(msg.get_message_id());
4497 }
4498
4499 //**********************************************
4500 template <etl::message_id_t Id>
4501 static ETL_CONSTEXPR bool accepts()
4502 {
4503 return T1::ID == Id || T2::ID == Id || T3::ID == Id;
4504 }
4505
4506 //**********************************************
4507 template <typename TMessage>
4508 static ETL_CONSTEXPR
4510 accepts()
4511 {
4512 return T1::ID == TMessage::ID || T2::ID == TMessage::ID || T3::ID == TMessage::ID;
4513 }
4514
4515 enum
4516 {
4519 };
4520
4521 private:
4522
4523 //********************************************
4525 void delete_current_message()
4526 {
4527 if (valid)
4528 {
4529 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
4530
4531
4532 #if ETL_HAS_VIRTUAL_MESSAGES
4533 pmsg->~imessage();
4534 #else
4535 delete_message(pmsg);
4536 #endif
4537 }
4538 }
4539 #include "private/diagnostic_pop.h"
4540
4541 //********************************************
4542 void delete_message(etl::imessage* pmsg)
4543 {
4544 switch (pmsg->get_message_id())
4545 {
4546 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
4547 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
4548 case T3::ID: static_cast<const T3*>(pmsg)->~T3(); break;
4549 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
4550 }
4551 }
4552
4553 //********************************************
4554 void add_new_message(const etl::imessage& msg)
4555 {
4556 const size_t id = msg.get_message_id();
4557 void* p = data;
4558
4559 switch (id)
4560 {
4561 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
4562 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
4563 case T3::ID: ::new (p) T3(static_cast<const T3&>(msg)); break;
4564 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
4565 }
4566 }
4567
4568 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4569 //********************************************
4570 void add_new_message(etl::imessage&& msg)
4571 {
4572 const size_t id = msg.get_message_id();
4573 void* p = data;
4574
4575 switch (id)
4576 {
4577 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
4578 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
4579 case T3::ID: ::new (p) T3(static_cast<T3&&>(msg)); break;
4580 default: break;
4581 }
4582 }
4583 #endif
4584
4586 bool valid;
4587 };
4588
4589 //***************************************************************************
4590 // Specialisation for 2 message types.
4591 //***************************************************************************
4592 template <typename T1, typename T2>
4594 {
4595 public:
4596
4597 //********************************************
4600 : valid(false)
4601 {
4602 }
4603 #include "private/diagnostic_pop.h"
4604
4605 //********************************************
4607 explicit message_packet(const etl::imessage& msg)
4608 {
4609 if (accepts(msg))
4610 {
4611 add_new_message(msg);
4612 valid = true;
4613 }
4614 else
4615 {
4616 valid = false;
4617 }
4618
4619 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4620 }
4621 #include "private/diagnostic_pop.h"
4622
4623 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4624 //********************************************
4626 explicit message_packet(etl::imessage&& msg)
4627 {
4628 if (accepts(msg))
4629 {
4630 add_new_message(etl::move(msg));
4631 valid = true;
4632 }
4633 else
4634 {
4635 valid = false;
4636 }
4637
4638 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4639 }
4640 #include "private/diagnostic_pop.h"
4641 #endif
4642
4643 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
4644 //********************************************
4649 explicit message_packet(TMessage&& /*msg*/)
4650 : valid(true)
4651 {
4652 // Not etl::message_packet, not etl::imessage and in typelist.
4656
4657 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4658 }
4659 #include "private/diagnostic_pop.h"
4660 #else
4661 //********************************************
4663 template <typename TMessage>
4664 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 &&
4665 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
4666 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1, T2>::value, int>::type = 0)
4667 : valid(true)
4668 {
4669 // Not etl::message_packet, not etl::imessage and in typelist.
4673
4674 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4675 }
4676 #include "private/diagnostic_pop.h"
4677 #endif
4678
4679 //**********************************************
4682 : valid(other.is_valid())
4683 {
4684 if (valid)
4685 {
4686 add_new_message(other.get());
4687 }
4688 }
4689 #include "private/diagnostic_pop.h"
4690
4691 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4692 //**********************************************
4695 : valid(other.is_valid())
4696 {
4697 if (valid)
4698 {
4699 add_new_message(etl::move(other.get()));
4700 }
4701 }
4702 #include "private/diagnostic_pop.h"
4703 #endif
4704
4705 //**********************************************
4708 {
4709 delete_current_message();
4710 valid = rhs.is_valid();
4711 if (valid)
4712 {
4713 add_new_message(rhs.get());
4714 }
4715
4716 return *this;
4717 }
4718 #include "private/diagnostic_pop.h"
4719
4720 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4721 //**********************************************
4724 {
4725 delete_current_message();
4726 valid = rhs.is_valid();
4727 if (valid)
4728 {
4729 add_new_message(etl::move(rhs.get()));
4730 }
4731
4732 return *this;
4733 }
4734 #include "private/diagnostic_pop.h"
4735 #endif
4736
4737 //********************************************
4739 {
4740 delete_current_message();
4741 }
4742
4743 //********************************************
4744 etl::imessage& get() ETL_NOEXCEPT
4745 {
4746 return *static_cast<etl::imessage*>(data);
4747 }
4748
4749 //********************************************
4750 const etl::imessage& get() const ETL_NOEXCEPT
4751 {
4752 return *static_cast<const etl::imessage*>(data);
4753 }
4754
4755 //********************************************
4756 bool is_valid() const
4757 {
4758 return valid;
4759 }
4760
4761 //**********************************************
4762 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
4763 {
4764 return T1::ID == id || T2::ID == id;
4765 }
4766
4767 //**********************************************
4768 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
4769 {
4770 return accepts(msg.get_message_id());
4771 }
4772
4773 //**********************************************
4774 template <etl::message_id_t Id>
4775 static ETL_CONSTEXPR bool accepts()
4776 {
4777 return T1::ID == Id || T2::ID == Id;
4778 }
4779
4780 //**********************************************
4781 template <typename TMessage>
4782 static ETL_CONSTEXPR
4784 accepts()
4785 {
4786 return T1::ID == TMessage::ID || T2::ID == TMessage::ID;
4787 }
4788
4789 enum
4790 {
4793 };
4794
4795 private:
4796
4797 //********************************************
4799 void delete_current_message()
4800 {
4801 if (valid)
4802 {
4803 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
4804
4805
4806 #if ETL_HAS_VIRTUAL_MESSAGES
4807 pmsg->~imessage();
4808 #else
4809 delete_message(pmsg);
4810 #endif
4811 }
4812 }
4813 #include "private/diagnostic_pop.h"
4814
4815 //********************************************
4816 void delete_message(etl::imessage* pmsg)
4817 {
4818 switch (pmsg->get_message_id())
4819 {
4820 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
4821 case T2::ID: static_cast<const T2*>(pmsg)->~T2(); break;
4822 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
4823 }
4824 }
4825
4826 //********************************************
4827 void add_new_message(const etl::imessage& msg)
4828 {
4829 const size_t id = msg.get_message_id();
4830 void* p = data;
4831
4832 switch (id)
4833 {
4834 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
4835 case T2::ID: ::new (p) T2(static_cast<const T2&>(msg)); break;
4836 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
4837 }
4838 }
4839
4840 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4841 //********************************************
4842 void add_new_message(etl::imessage&& msg)
4843 {
4844 const size_t id = msg.get_message_id();
4845 void* p = data;
4846
4847 switch (id)
4848 {
4849 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
4850 case T2::ID: ::new (p) T2(static_cast<T2&&>(msg)); break;
4851 default: break;
4852 }
4853 }
4854 #endif
4855
4857 bool valid;
4858 };
4859
4860 //***************************************************************************
4861 // Specialisation for 1 message type.
4862 //***************************************************************************
4863 template <typename T1>
4865 {
4866 public:
4867
4868 //********************************************
4871 : valid(false)
4872 {
4873 }
4874 #include "private/diagnostic_pop.h"
4875
4876 //********************************************
4878 explicit message_packet(const etl::imessage& msg)
4879 {
4880 if (accepts(msg))
4881 {
4882 add_new_message(msg);
4883 valid = true;
4884 }
4885 else
4886 {
4887 valid = false;
4888 }
4889
4890 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4891 }
4892 #include "private/diagnostic_pop.h"
4893
4894 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4895 //********************************************
4897 explicit message_packet(etl::imessage&& msg)
4898 {
4899 if (accepts(msg))
4900 {
4901 add_new_message(etl::move(msg));
4902 valid = true;
4903 }
4904 else
4905 {
4906 valid = false;
4907 }
4908
4909 ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));
4910 }
4911 #include "private/diagnostic_pop.h"
4912 #endif
4913
4914 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)
4915 //********************************************
4920 explicit message_packet(TMessage&& /*msg*/)
4921 : valid(true)
4922 {
4923 // Not etl::message_packet, not etl::imessage and in typelist.
4927
4928 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4929 }
4930 #include "private/diagnostic_pop.h"
4931 #else
4932 //********************************************
4934 template <typename TMessage>
4935 explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if<!etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::message_packet<T1> >::value &&
4936 !etl::is_same<typename etl::remove_cvref<TMessage>::type, etl::imessage>::value &&
4937 !etl::is_one_of<typename etl::remove_cvref<TMessage>::type, T1>::value, int>::type = 0)
4938 : valid(true)
4939 {
4940 // Not etl::message_packet, not etl::imessage and in typelist.
4944
4945 ETL_STATIC_ASSERT(Enabled, "Message not in packet type list");
4946 }
4947 #include "private/diagnostic_pop.h"
4948 #endif
4949
4950 //**********************************************
4953 : valid(other.is_valid())
4954 {
4955 if (valid)
4956 {
4957 add_new_message(other.get());
4958 }
4959 }
4960 #include "private/diagnostic_pop.h"
4961
4962 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4963 //**********************************************
4966 : valid(other.is_valid())
4967 {
4968 if (valid)
4969 {
4970 add_new_message(etl::move(other.get()));
4971 }
4972 }
4973 #include "private/diagnostic_pop.h"
4974 #endif
4975
4976 //**********************************************
4979 {
4980 delete_current_message();
4981 valid = rhs.is_valid();
4982 if (valid)
4983 {
4984 add_new_message(rhs.get());
4985 }
4986
4987 return *this;
4988 }
4989 #include "private/diagnostic_pop.h"
4990
4991 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
4992 //**********************************************
4995 {
4996 delete_current_message();
4997 valid = rhs.is_valid();
4998 if (valid)
4999 {
5000 add_new_message(etl::move(rhs.get()));
5001 }
5002
5003 return *this;
5004 }
5005 #include "private/diagnostic_pop.h"
5006 #endif
5007
5008 //********************************************
5010 {
5011 delete_current_message();
5012 }
5013
5014 //********************************************
5015 etl::imessage& get() ETL_NOEXCEPT
5016 {
5017 return *static_cast<etl::imessage*>(data);
5018 }
5019
5020 //********************************************
5021 const etl::imessage& get() const ETL_NOEXCEPT
5022 {
5023 return *static_cast<const etl::imessage*>(data);
5024 }
5025
5026 //********************************************
5027 bool is_valid() const
5028 {
5029 return valid;
5030 }
5031
5032 //**********************************************
5033 static ETL_CONSTEXPR bool accepts(etl::message_id_t id)
5034 {
5035 return T1::ID == id;
5036 }
5037
5038 //**********************************************
5039 static ETL_CONSTEXPR bool accepts(const etl::imessage& msg)
5040 {
5041 return accepts(msg.get_message_id());
5042 }
5043
5044 //**********************************************
5045 template <etl::message_id_t Id>
5046 static ETL_CONSTEXPR bool accepts()
5047 {
5048 return T1::ID == Id;
5049 }
5050
5051 //**********************************************
5052 template <typename TMessage>
5053 static ETL_CONSTEXPR
5055 accepts()
5056 {
5057 return T1::ID == TMessage::ID;
5058 }
5059
5060 enum
5061 {
5063 ALIGNMENT = etl::largest<T1>::alignment
5064 };
5065
5066 private:
5067
5068 //********************************************
5070 void delete_current_message()
5071 {
5072 if (valid)
5073 {
5074 etl::imessage* pmsg = static_cast<etl::imessage*>(data);
5075
5076
5077 #if ETL_HAS_VIRTUAL_MESSAGES
5078 pmsg->~imessage();
5079 #else
5080 delete_message(pmsg);
5081 #endif
5082 }
5083 }
5084 #include "private/diagnostic_pop.h"
5085
5086 //********************************************
5087 void delete_message(etl::imessage* pmsg)
5088 {
5089 switch (pmsg->get_message_id())
5090 {
5091 case T1::ID: static_cast<const T1*>(pmsg)->~T1(); break;
5092 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
5093 }
5094 }
5095
5096 //********************************************
5097 void add_new_message(const etl::imessage& msg)
5098 {
5099 const size_t id = msg.get_message_id();
5100 void* p = data;
5101
5102 switch (id)
5103 {
5104 case T1::ID: ::new (p) T1(static_cast<const T1&>(msg)); break;
5105 default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;
5106 }
5107 }
5108
5109 #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)
5110 //********************************************
5111 void add_new_message(etl::imessage&& msg)
5112 {
5113 const size_t id = msg.get_message_id();
5114 void* p = data;
5115
5116 switch (id)
5117 {
5118 case T1::ID: ::new (p) T1(static_cast<T1&&>(msg)); break;
5119 default: break;
5120 }
5121 }
5122 #endif
5123
5125 bool valid;
5126 };
5127#endif
5128}
5129
5130#endif
Definition message.h:73
Definition message_packet.h:393
Definition message.h:56
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition largest.h:367
enable_if
Definition type_traits_generator.h:1186
is_same
Definition type_traits_generator.h:1036
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