Embedded Template Library
1.0
Loading...
Searching...
No Matches
fsm_cpp03_generator.h
1
/******************************************************************************
2
The MIT License(MIT)
3
4
Embedded Template Library.
5
https://github.com/ETLCPP/etl
6
https://www.etlcpp.com
7
8
Copyright(c) 2026 John Wellbelove
9
10
Permission is hereby granted, free of charge, to any person obtaining a copy
11
of this software and associated documentation files(the "Software"), to deal
12
in the Software without restriction, including without limitation the rights
13
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14
copies of the Software, and to permit persons to whom the Software is
15
furnished to do so, subject to the following conditions :
16
17
The above copyright notice and this permission notice shall be included in all
18
copies or substantial portions of the Software.
19
20
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
SOFTWARE.
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
37
import cog
38
################################################
39
# The first definition for all of the events.
40
################################################
41
cog.outl("//***************************************************************************")
42
cog.outl("// The definition for all %s message types." % Handlers)
43
cog.outl("//***************************************************************************")
44
cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_,")
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
cog.outl(" typename T%s = void>" % Handlers)
52
cog.outl("class fsm_state : public ifsm_state")
53
cog.outl("{")
54
cog.outl("public:")
55
cog.outl("")
56
cog.outl(" static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_;")
57
cog.outl("")
58
cog.outl(" fsm_state()")
59
cog.outl(" : ifsm_state(STATE_ID)")
60
cog.outl(" {")
61
cog.outl(" }")
62
cog.outl("")
63
cog.outl("protected:")
64
cog.outl("")
65
cog.outl(" ~fsm_state()")
66
cog.outl(" {")
67
cog.outl(" }")
68
cog.outl("")
69
cog.outl(" TContext& get_fsm_context() const")
70
cog.outl(" {")
71
cog.outl(" return static_cast<TContext&>(ifsm_state::get_fsm_context());")
72
cog.outl(" }")
73
cog.outl("")
74
cog.outl("private:")
75
cog.outl("")
76
cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)")
77
cog.outl(" {")
78
cog.outl(" etl::fsm_state_id_t new_state_id;")
79
cog.outl(" etl::message_id_t event_id = message.get_message_id();")
80
cog.outl("")
81
cog.outl(" switch (event_id)")
82
cog.outl(" {")
83
for 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;")
87
cog.out(" default:")
88
cog.out(" new_state_id = p_parent ? p_parent->process_event(message) : static_cast<TDerived*>(this)->on_event_unknown(message);")
89
cog.outl(" break;")
90
cog.outl(" }")
91
cog.outl("")
92
cog.outl(" return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(message) : No_State_Change);")
93
cog.outl(" }")
94
cog.outl("};")
95
96
####################################
97
# All of the other specialisations.
98
####################################
99
for 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
####################################
172
cog.outl("")
173
cog.outl("//***************************************************************************")
174
cog.outl("// Specialisation for 0 message types.")
175
cog.outl("//***************************************************************************")
176
cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_>")
177
cog.out("class fsm_state<TContext, TDerived, STATE_ID_,")
178
for t in range(1, int(Handlers)):
179
cog.out(" void,")
180
if t % 16 == 0:
181
cog.outl("")
182
cog.out(" ")
183
cog.outl(" void> : public ifsm_state")
184
cog.outl("{")
185
cog.outl("public:")
186
cog.outl("")
187
cog.outl(" static ETL_CONSTANT etl::fsm_state_id_t STATE_ID = STATE_ID_;")
188
cog.outl("")
189
cog.outl(" fsm_state()")
190
cog.outl(" : ifsm_state(STATE_ID)")
191
cog.outl(" {")
192
cog.outl(" }")
193
cog.outl("")
194
cog.outl("protected:")
195
cog.outl("")
196
cog.outl(" ~fsm_state()")
197
cog.outl(" {")
198
cog.outl(" }")
199
cog.outl("")
200
cog.outl(" TContext& get_fsm_context() const")
201
cog.outl(" {")
202
cog.outl(" return static_cast<TContext&>(ifsm_state::get_fsm_context());")
203
cog.outl(" }")
204
cog.outl("private:")
205
cog.outl("")
206
cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)")
207
cog.outl(" {")
208
cog.outl(" return p_parent ? p_parent->process_event(message) : static_cast<TDerived*>(this)->on_event_unknown(message);")
209
cog.outl(" }")
210
cog.outl("};")
211
212
cog.outl("")
213
cog.outl("template <typename TContext, typename TDerived, etl::fsm_state_id_t STATE_ID_,")
214
cog.out(" ")
215
for n in range(1, int(Handlers)):
216
cog.out(" typename T%s," % n)
217
if n % 4 == 0:
218
cog.outl("")
219
cog.out(" ")
220
cog.outl(" typename T%s>" % Handlers)
221
cog.out("ETL_CONSTANT etl::fsm_state_id_t fsm_state<TContext, TDerived, STATE_ID_,")
222
for n in range(1, int(Handlers)):
223
cog.out(" T%s," % n)
224
cog.outl(" T%s>::STATE_ID;" % Handlers)
225
]]]*/
226
/*[[[end]]]*/
include
etl
generators
fsm_cpp03_generator.h
Generated on
for Embedded Template Library by
1.15.0