Embedded Template Library 1.0
Loading...
Searching...
No Matches
message_router_cpp03_generator.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// For C++03/98.
35//*************************************************************************************************
36/*[[[cog
37 import cog
38 ################################################
39 # The first definition for all of the messages.
40 ################################################
41 cog.outl("//***************************************************************************")
42 cog.outl("// The definition for all %s message types." % Handlers)
43 cog.outl("//***************************************************************************")
44 cog.outl("template <typename TDerived,")
45 cog.out(" ")
46 for n in range(1, int(Handlers)):
47 cog.out("typename T%s = void," % n)
48 if n % 4 == 0:
49 cog.outl("")
50 cog.out(" ")
51 else:
52 cog.out(" ")
53 cog.outl("typename T%s = void>" % int(Handlers))
54 cog.out("class message_router")
55 cog.outl(" : public imessage_router")
56 cog.outl("{")
57 cog.outl("public:")
58 cog.outl("")
59 cog.out(" typedef etl::message_packet<")
60 for n in range(1, int(Handlers)):
61 cog.out("T%s, " % n)
62 cog.outl("T%s> message_packet;" % int(Handlers))
63 cog.outl("")
64
65 cog.outl("#if ETL_USING_CPP11")
66 cog.out(" using message_types = etl::type_list<")
67 for n in range(1, int(Handlers)):
68 cog.out("T%s, " % n)
69 cog.outl("T%s>;" % int(Handlers))
70 cog.outl("#endif")
71 cog.outl("")
72
73 cog.outl(" //**********************************************")
74 cog.outl(" message_router(etl::message_router_id_t id_)")
75 cog.outl(" : imessage_router(id_)")
76 cog.outl(" {")
77 cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
78 cog.outl(" }")
79 cog.outl("")
80 cog.outl(" //**********************************************")
81 cog.outl(" message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)")
82 cog.outl(" : imessage_router(id_, successor_)")
83 cog.outl(" {")
84 cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
85 cog.outl(" }")
86 cog.outl("")
87 cog.outl(" //**********************************************")
88 cog.outl(" message_router()")
89 cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER)")
90 cog.outl(" {")
91 cog.outl(" }")
92 cog.outl("")
93 cog.outl(" //**********************************************")
94 cog.outl(" message_router(etl::imessage_router& successor_)")
95 cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)")
96 cog.outl(" {")
97 cog.outl(" }")
98 cog.outl("")
99 cog.outl(" //**********************************************")
100 cog.outl(" using etl::imessage_router::receive;")
101 cog.outl("")
102 cog.outl(" void receive(const etl::imessage& msg) ETL_OVERRIDE")
103 cog.outl(" {")
104 cog.outl(" const etl::message_id_t id = msg.get_message_id();")
105 cog.outl("")
106 cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
107 cog.outl(" switch (id)")
108 cog.outl(" {")
109 for n in range(1, int(Handlers) + 1):
110 cog.out(" case T%d::ID:" % n)
111 cog.out(" static_cast<TDerived*>(this)->on_receive(static_cast<const T%d&>(msg));" % n)
112 cog.outl(" break;")
113 cog.outl(" default:")
114 cog.outl(" {")
115 cog.outl(" if (has_successor())")
116 cog.outl(" {")
117 cog.outl(" get_successor().receive(msg);")
118 cog.outl(" }")
119 cog.outl(" else")
120 cog.outl(" {")
121 cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
122 cog.outl(" }")
123 cog.outl(" break;")
124 cog.outl(" }")
125 cog.outl(" }")
126 cog.outl("#include \"etl/private/diagnostic_pop.h\"")
127 cog.outl(" }")
128 cog.outl("")
129 cog.outl(" template <typename TMessage>")
130 cog.out(" typename etl::enable_if<etl::is_message<TMessage>::value && etl::is_one_of<TMessage, ")
131 for n in range(1, int(Handlers)):
132 cog.out("T%s, " % n)
133 cog.outl("T%s>::value, void>::type" % int(Handlers))
134 cog.outl(" receive(const TMessage& msg)")
135 cog.outl(" {")
136 cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
137 cog.outl(" static_cast<TDerived*>(this)->on_receive(msg);")
138 cog.outl("#include \"etl/private/diagnostic_pop.h\"")
139 cog.outl(" }")
140 cog.outl("")
141 cog.outl(" template <typename TMessage>")
142 cog.out(" typename etl::enable_if<etl::is_message<TMessage>::value && !etl::is_one_of<TMessage, ")
143 for n in range(1, int(Handlers)):
144 cog.out("T%s, " % n)
145 cog.outl("T%s>::value, void>::type" % int(Handlers))
146 cog.outl(" receive(const TMessage& msg)")
147 cog.outl(" {")
148 cog.outl(" if (has_successor())")
149 cog.outl(" {")
150 cog.outl(" get_successor().receive(msg);")
151 cog.outl(" }")
152 cog.outl(" else")
153 cog.outl(" {")
154 cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
155 cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
156 cog.outl("#include \"etl/private/diagnostic_pop.h\"")
157 cog.outl(" }")
158 cog.outl(" }")
159 cog.outl("")
160 cog.outl(" //**********************************************")
161 cog.outl(" using imessage_router::accepts;")
162 cog.outl("")
163 cog.outl(" bool accepts(etl::message_id_t id) const ETL_OVERRIDE")
164 cog.outl(" {")
165 cog.outl(" switch (id)")
166 cog.outl(" {")
167 cog.out(" ")
168 for n in range(1, int(Handlers) + 1):
169 cog.out(" case T%d::ID:" % n)
170 if n % 8 == 0:
171 cog.outl("")
172 cog.out(" ")
173 cog.outl(" return true;")
174 cog.outl(" default:")
175 cog.outl(" {")
176 cog.outl(" if (has_successor())")
177 cog.outl(" {")
178 cog.outl(" return get_successor().accepts(id);")
179 cog.outl(" }")
180 cog.outl(" else")
181 cog.outl(" {")
182 cog.outl(" return false;")
183 cog.outl(" }")
184 cog.outl(" }")
185 cog.outl(" }")
186 cog.outl(" }")
187 cog.outl("")
188 cog.outl(" //********************************************")
189 cog.outl(" ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE")
190 cog.outl(" {")
191 cog.outl(" return false;")
192 cog.outl(" }")
193 cog.outl("")
194 cog.outl(" //********************************************")
195 cog.outl(" bool is_producer() const ETL_OVERRIDE")
196 cog.outl(" {")
197 cog.outl(" return true;")
198 cog.outl(" }")
199 cog.outl("")
200 cog.outl(" //********************************************")
201 cog.outl(" bool is_consumer() const ETL_OVERRIDE")
202 cog.outl(" {")
203 cog.outl(" return true;")
204 cog.outl(" }")
205 cog.outl("};")
206
207 ####################################
208 # All of the other specialisations.
209 ####################################
210 for n in range(int(Handlers) - 1, 0, -1):
211 cog.outl("")
212 cog.outl("//***************************************************************************")
213 if n == 1:
214 cog.outl("// Specialisation for %d message type." % n)
215 else:
216 cog.outl("// Specialisation for %d message types." % n)
217 cog.outl("//***************************************************************************")
218 cog.outl("template <typename TDerived,")
219 cog.out(" ")
220 for t in range(1, n):
221 cog.out("typename T%d," % t)
222 if t % 4 == 0:
223 cog.outl("")
224 cog.out(" ")
225 else:
226 cog.out(" ")
227 cog.outl("typename T%d>" % n)
228 cog.out("class message_router<TDerived, ")
229 for t in range(1, n + 1):
230 cog.out("T%d, " % t)
231 if t % 16 == 0:
232 cog.outl("")
233 cog.out(" ")
234 for t in range(n + 1, int(Handlers)):
235 cog.out("void, ")
236 if t % 16 == 0:
237 cog.outl("")
238 cog.out(" ")
239 cog.outl("void>")
240 cog.outl(" : public imessage_router")
241 cog.outl("{")
242 cog.outl("public:")
243 cog.outl("")
244 cog.out(" typedef etl::message_packet<")
245 for t in range(1, n):
246 cog.out("T%s, " % t)
247 cog.outl(" T%s> message_packet;" % n)
248 cog.outl("")
249
250 cog.outl("#if ETL_USING_CPP11")
251 cog.out(" using message_types = etl::type_list<")
252 for t in range(1, n):
253 cog.out("T%s, " % t)
254 cog.outl("T%s>;" % n)
255 cog.outl("#endif")
256 cog.outl("")
257
258 cog.outl(" //**********************************************")
259 cog.outl(" message_router(etl::message_router_id_t id_)")
260 cog.outl(" : imessage_router(id_)")
261 cog.outl(" {")
262 cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
263 cog.outl(" }")
264 cog.outl("")
265 cog.outl(" //**********************************************")
266 cog.outl(" message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)")
267 cog.outl(" : imessage_router(id_, successor_)")
268 cog.outl(" {")
269 cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
270 cog.outl(" }")
271 cog.outl("")
272 cog.outl(" //**********************************************")
273 cog.outl(" message_router()")
274 cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER)")
275 cog.outl(" {")
276 cog.outl(" }")
277 cog.outl("")
278 cog.outl(" //**********************************************")
279 cog.outl(" message_router(etl::imessage_router& successor_)")
280 cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)")
281 cog.outl(" {")
282 cog.outl(" }")
283 cog.outl("")
284 cog.outl(" //**********************************************")
285 cog.outl(" using etl::imessage_router::receive;")
286 cog.outl("")
287 cog.outl(" void receive(const etl::imessage& msg) ETL_OVERRIDE")
288 cog.outl(" {")
289 cog.outl(" const etl::message_id_t id = msg.get_message_id();")
290 cog.outl("")
291 cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
292 cog.outl(" switch (id)")
293 cog.outl(" {")
294 for t in range(1, n + 1):
295 cog.out(" case T%d::ID:" % t)
296 cog.out(" static_cast<TDerived*>(this)->on_receive(static_cast<const T%d&>(msg));" % t)
297 cog.outl(" break;")
298 cog.outl(" default:")
299 cog.outl(" {")
300 cog.outl(" if (has_successor())")
301 cog.outl(" {")
302 cog.outl(" get_successor().receive(msg);")
303 cog.outl(" }")
304 cog.outl(" else")
305 cog.outl(" {")
306 cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
307 cog.outl(" }")
308 cog.outl(" break;")
309 cog.outl(" }")
310 cog.outl(" }")
311 cog.outl("#include \"etl/private/diagnostic_pop.h\"")
312 cog.outl(" }")
313 cog.outl("")
314 cog.outl(" template <typename TMessage>")
315 cog.out(" typename etl::enable_if<etl::is_message<TMessage>::value && etl::is_one_of<TMessage, ")
316 for t in range(1, n):
317 cog.out("T%s, " % t)
318 cog.outl("T%s>::value, void>::type" % n)
319 cog.outl(" receive(const TMessage& msg)")
320 cog.outl(" {")
321 cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
322 cog.outl(" static_cast<TDerived*>(this)->on_receive(msg);")
323 cog.outl("#include \"etl/private/diagnostic_pop.h\"")
324 cog.outl(" }")
325 cog.outl("")
326 cog.outl(" template <typename TMessage>")
327 cog.out(" typename etl::enable_if<etl::is_message<TMessage>::value && !etl::is_one_of<TMessage, ")
328 for t in range(1, n):
329 cog.out("T%s, " % t)
330 cog.outl("T%s>::value, void>::type" % n)
331 cog.outl(" receive(const TMessage& msg)")
332 cog.outl(" {")
333 cog.outl(" if (has_successor())")
334 cog.outl(" {")
335 cog.outl(" get_successor().receive(msg);")
336 cog.outl(" }")
337 cog.outl(" else")
338 cog.outl(" {")
339 cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"")
340 cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
341 cog.outl("#include \"etl/private/diagnostic_pop.h\"")
342 cog.outl(" }")
343 cog.outl(" }")
344 cog.outl("")
345 cog.outl("")
346 cog.outl(" //**********************************************")
347 cog.outl(" using imessage_router::accepts;")
348 cog.outl("")
349 cog.outl(" bool accepts(etl::message_id_t id) const ETL_OVERRIDE")
350 cog.outl(" {")
351 cog.outl(" switch (id)")
352 cog.outl(" {")
353 cog.out(" ")
354 for t in range(1, n + 1):
355 cog.out(" case T%d::ID:" % t)
356 if t % 8 == 0:
357 cog.outl("")
358 if t != n:
359 cog.out(" ")
360 cog.outl("")
361 cog.outl(" return true;")
362 cog.outl(" default:")
363 cog.outl(" {")
364 cog.outl(" if (has_successor())")
365 cog.outl(" {")
366 cog.outl(" return get_successor().accepts(id);")
367 cog.outl(" }")
368 cog.outl(" else")
369 cog.outl(" {")
370 cog.outl(" return false;")
371 cog.outl(" }")
372 cog.outl(" }")
373 cog.outl(" }")
374 cog.outl(" }")
375 cog.outl("")
376 cog.outl(" //********************************************")
377 cog.outl(" ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE")
378 cog.outl(" {")
379 cog.outl(" return false;")
380 cog.outl(" }")
381 cog.outl("")
382 cog.outl(" //********************************************")
383 cog.outl(" bool is_producer() const ETL_OVERRIDE")
384 cog.outl(" {")
385 cog.outl(" return true;")
386 cog.outl(" }")
387 cog.outl("")
388 cog.outl(" //********************************************")
389 cog.outl(" bool is_consumer() const ETL_OVERRIDE")
390 cog.outl(" {")
391 cog.outl(" return true;")
392 cog.outl(" }")
393 cog.outl("};")
394]]]*/
395/*[[[end]]]*/
396
397//***************************************************************************
398// Specialisation for 0 message types.
399//***************************************************************************
400template <typename TDerived>
401class message_router<TDerived, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void>
402 : public imessage_router
403{
404public:
405
406 typedef etl::message_packet<> message_packet;
407
408#if ETL_USING_CPP11
409 using message_types = etl::type_list<>;
410#endif
411
412 //**********************************************
413 message_router(etl::message_router_id_t id_)
414 : imessage_router(id_)
415 {
416 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
417 }
418
419 //**********************************************
420 message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)
421 : imessage_router(id_, successor_)
422 {
423 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
424 }
425
426 //**********************************************
427 message_router()
428 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
429 {
430 }
431
432 //**********************************************
433 message_router(etl::imessage_router& successor_)
434 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
435 {
436 }
437
438 //**********************************************
439 using etl::imessage_router::receive;
440
441 void receive(const etl::imessage& msg) ETL_OVERRIDE
442 {
444 if (has_successor())
445 {
446 get_successor().receive(msg);
447 }
449 }
450
451 //**********************************************
452 using imessage_router::accepts;
453
454 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
455 {
456 if (has_successor())
457 {
458 return get_successor().accepts(id);
459 }
460 else
461 {
462 return false;
463 }
464 }
465
466 //********************************************
467 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
468 {
469 return false;
470 }
471
472 //********************************************
473 bool is_producer() const ETL_OVERRIDE
474 {
475 return true;
476 }
477
478 //********************************************
479 bool is_consumer() const ETL_OVERRIDE
480 {
481 return true;
482 }
483};
This is the base of all message routers.
Definition message_router.h:138
Definition message.h:75
Definition message_packet.h:42
Router id is out of the legal range.
Definition message_router.h:69
#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