Embedded Template Library 1.0
Loading...
Searching...
No Matches
fsm_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 and below.
35//*************************************************************************************************
36/*[[[cog
37import cog
38################################################
39# The first definition for all of the events.
40################################################
41cog.outl("//***************************************************************************")
42cog.outl("// The definition for all %s message types." % Handlers)
43cog.outl("//***************************************************************************")
44cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_,")
45cog.out(" ")
46for 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(" ")
51cog.outl(" typename T%s = void>" % Handlers)
52cog.outl("class fsm_state : public ifsm_state")
53cog.outl("{")
54cog.outl("public:")
55cog.outl("")
56cog.outl(" static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_;")
57cog.outl("")
58cog.outl(" fsm_state()")
59cog.outl(" : ifsm_state(STATE_ID)")
60cog.outl(" {")
61cog.outl(" }")
62cog.outl("")
63cog.outl("protected:")
64cog.outl("")
65cog.outl(" ~fsm_state()")
66cog.outl(" {")
67cog.outl(" }")
68cog.outl("")
69cog.outl(" TContext& get_fsm_context() const")
70cog.outl(" {")
71cog.outl(" return static_cast<TContext&>(ifsm_state::get_fsm_context());")
72cog.outl(" }")
73cog.outl("")
74cog.outl("private:")
75cog.outl("")
76cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)")
77cog.outl(" {")
78cog.outl(" etl::fsm_state_id_t new_state_id;")
79cog.outl(" etl::message_id_t event_id = message.get_message_id();")
80cog.outl("")
81cog.outl(" switch (event_id)")
82cog.outl(" {")
83for n in range(1, int(Handlers) + 1):
84 cog.out(" case T%d::ID:" % n)
85 cog.out(" new_state_id = static_cast<TDerived*>(this)->on_event(static_cast<const T%d&>(message));" % n)
86 cog.outl(" break;")
87cog.out(" default:")
88cog.out(" new_state_id = p_parent ? p_parent->process_event(message) : static_cast<TDerived*>(this)->on_event_unknown(message);")
89cog.outl(" break;")
90cog.outl(" }")
91cog.outl("")
92cog.outl(" return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(message) : No_State_Change);")
93cog.outl(" }")
94cog.outl("};")
95
96####################################
97# All of the other specialisations.
98####################################
99for n in range(int(Handlers) - 1, 0, -1):
100 cog.outl("")
101 cog.outl("//***************************************************************************")
102 if n == 1:
103 cog.outl("// Specialisation for %d message type." % n)
104 else:
105 cog.outl("// Specialisation for %d message types." % n)
106 cog.outl("//***************************************************************************")
107 cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_,")
108 cog.out(" ")
109 for t in range(1, n):
110 cog.out(" typename T%d," % t)
111 if t % 4 == 0:
112 cog.outl("")
113 cog.out(" ")
114 cog.outl(" typename T%d>" % n)
115 cog.out("class fsm_state<TContext, TDerived, STATE_ID_,")
116 for t in range(1, n + 1):
117 cog.out(" T%d," % t)
118 if t % 16 == 0:
119 cog.outl("")
120 cog.out(" ")
121 for t in range(n + 1, int(Handlers)):
122 cog.out(" void,")
123 if t % 16 == 0:
124 cog.outl("")
125 cog.out(" ")
126 cog.outl(" void> : public ifsm_state")
127 cog.outl("{")
128 cog.outl("public:")
129 cog.outl("")
130 cog.outl(" static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_;")
131 cog.outl("")
132 cog.outl(" fsm_state()")
133 cog.outl(" : ifsm_state(STATE_ID)")
134 cog.outl(" {")
135 cog.outl(" }")
136 cog.outl("")
137 cog.outl("protected:")
138 cog.outl("")
139 cog.outl(" ~fsm_state()")
140 cog.outl(" {")
141 cog.outl(" }")
142 cog.outl("")
143 cog.outl(" TContext& get_fsm_context() const")
144 cog.outl(" {")
145 cog.outl(" return static_cast<TContext&>(ifsm_state::get_fsm_context());")
146 cog.outl(" }")
147 cog.outl("")
148 cog.outl("private:")
149 cog.outl("")
150 cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)")
151 cog.outl(" {")
152 cog.outl(" etl::fsm_state_id_t new_state_id;")
153 cog.outl(" etl::message_id_t event_id = message.get_message_id();")
154 cog.outl("")
155 cog.outl(" switch (event_id)")
156 cog.outl(" {")
157 for n in range(1, n + 1):
158 cog.out(" case T%d::ID:" % n)
159 cog.out(" new_state_id = static_cast<TDerived*>(this)->on_event(static_cast<const T%d&>(message));" % n)
160 cog.outl(" break;")
161 cog.out(" default:")
162 cog.out(" new_state_id = p_parent ? p_parent->process_event(message) : static_cast<TDerived*>(this)->on_event_unknown(message);")
163 cog.outl(" break;")
164 cog.outl(" }")
165 cog.outl("")
166 cog.outl(" return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(message) : No_State_Change);")
167 cog.outl(" }")
168 cog.outl("};")
169####################################
170# Specialisation for zero messages.
171####################################
172cog.outl("")
173cog.outl("//***************************************************************************")
174cog.outl("// Specialisation for 0 message types.")
175cog.outl("//***************************************************************************")
176cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_>")
177cog.out("class fsm_state<TContext, TDerived, STATE_ID_,")
178for t in range(1, int(Handlers)):
179 cog.out(" void,")
180if t % 16 == 0:
181 cog.outl("")
182 cog.out(" ")
183cog.outl(" void> : public ifsm_state")
184cog.outl("{")
185cog.outl("public:")
186cog.outl("")
187cog.outl(" static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_;")
188cog.outl("")
189cog.outl(" fsm_state()")
190cog.outl(" : ifsm_state(STATE_ID)")
191cog.outl(" {")
192cog.outl(" }")
193cog.outl("")
194cog.outl("protected:")
195cog.outl("")
196cog.outl(" ~fsm_state()")
197cog.outl(" {")
198cog.outl(" }")
199cog.outl("")
200cog.outl(" TContext& get_fsm_context() const")
201cog.outl(" {")
202cog.outl(" return static_cast<TContext&>(ifsm_state::get_fsm_context());")
203cog.outl(" }")
204cog.outl("private:")
205cog.outl("")
206cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)")
207cog.outl(" {")
208cog.outl(" return p_parent ? p_parent->process_event(message) : static_cast<TDerived*>(this)->on_event_unknown(message);")
209cog.outl(" }")
210cog.outl("};")
211
212cog.outl("")
213cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_,")
214cog.out(" ")
215for n in range(1, int(Handlers)):
216 cog.out(" typename T%s," % n)
217 if n % 4 == 0:
218 cog.outl("")
219 cog.out(" ")
220cog.outl(" typename T%s>" % Handlers)
221cog.out("ETL_CONSTANT etl::fsm_state_id_t fsm_state<TContext, TDerived, STATE_ID_,")
222for n in range(1, int(Handlers)):
223 cog.out(" T%s," % n)
224cog.outl(" T%s>::STATE_ID;" % Handlers)
225]]]*/
226/*[[[end]]]*/