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