@@ -16,13 +16,11 @@ static void write_constexpr_id(
16
16
T id,
17
17
std::string_view indentation
18
18
) {
19
- ctx.write (
19
+ ctx.writef (
20
+ " {}static constexpr auto id = static_cast<{}>({});\n " ,
20
21
indentation,
21
- " static constexpr auto id = static_cast<" ,
22
22
id_type_name,
23
- " >(" ,
24
- static_cast <int32_t >(id),
25
- " );\n "
23
+ static_cast <int32_t >(id)
26
24
);
27
25
}
28
26
@@ -84,30 +82,32 @@ static void write_fields(
84
82
auto field_type = ecsact_meta_field_type (compo_id, field_id);
85
83
auto field_name = ecsact_meta_field_name (compo_id, field_id);
86
84
87
- ctx.write (indentation);
88
- ctx.write (cpp_field_type_name (field_type));
89
- ctx.write (" " s, field_name);
85
+ ctx.writef (
86
+ " {}{} {}" ,
87
+ indentation,
88
+ cpp_field_type_name (field_type),
89
+ field_name
90
+ );
90
91
91
92
if (field_type.length > 1 ) {
92
- ctx.write (" [" , field_type.length , " ] " );
93
+ ctx.writef (" [{}] " , field_type.length );
93
94
}
94
- ctx.write (" ;\n " );
95
+ ctx.writef (" ;\n " );
95
96
}
96
97
97
- ctx.write (
98
+ ctx.writef (
99
+ " {}auto operator<=>(const {}&) const = default;\n " ,
98
100
indentation,
99
- " auto operator<=>(const " ,
100
- cpp_identifier (full_name),
101
- " &) const = default;\n "
101
+ cpp_identifier (full_name)
102
102
);
103
103
}
104
104
105
105
static void write_system_impl_decl (
106
106
ecsact::codegen_plugin_context& ctx,
107
107
std::string_view indentation
108
108
) {
109
- ctx.write (indentation, " struct context;\n " );
110
- ctx.write (indentation, " static void impl(context&);\n " );
109
+ ctx.writef ( " {} struct context;\n " , indentation );
110
+ ctx.writef ( " {} static void impl(context&);\n " , indentation );
111
111
}
112
112
113
113
static void write_system_struct (
@@ -121,18 +121,18 @@ static void write_system_struct(
121
121
122
122
std::string sys_name = ecsact_meta_system_name (sys_id);
123
123
if (!sys_name.empty ()) {
124
- ctx.write (indentation, " struct " s, sys_name, " { \n " s );
124
+ ctx.writef ( " {} struct {} {{ \n " , indentation, sys_name );
125
125
write_constexpr_id (ctx, " ecsact_system_id" , sys_id, indentation + " \t " );
126
126
for (auto child_system_id : get_child_system_ids (sys_id)) {
127
127
write_system_struct (ctx, child_system_id, indentation + " \t " );
128
128
}
129
129
write_system_impl_decl (ctx, indentation + " \t " );
130
- ctx.write (indentation, " } ;\n " s );
130
+ ctx.writef ( " {}}} ;\n " , indentation );
131
131
} else {
132
- ctx.write (indentation, " struct " s, anonymous_system_name (sys_id), " { \n " );
132
+ ctx.writef ( " {} struct {} {{ \n " , indentation, anonymous_system_name (sys_id));
133
133
write_constexpr_id (ctx, " ecsact_system_id" , sys_id, indentation + " \t " );
134
- ctx.write (indentation, " \t struct context;\n " );
135
- ctx.write (indentation, " } ;\n " s );
134
+ ctx.writef ( " {} \t struct context;\n " , indentation );
135
+ ctx.writef ( " {}}} ;\n " , indentation );
136
136
137
137
for (auto child_system_id : get_child_system_ids (sys_id)) {
138
138
write_system_struct (ctx, child_system_id, indentation);
@@ -175,74 +175,71 @@ void ecsact_codegen_plugin(
175
175
176
176
ecsact::codegen_plugin_context ctx{package_id, 0 , write_fn, report_fn};
177
177
178
- ctx.write (GENERATED_FILE_DISCLAIMER);
179
- ctx.write (" #pragma once\n\n " );
178
+ ctx.writef (GENERATED_FILE_DISCLAIMER);
179
+ ctx.writef (" #pragma once\n\n " );
180
180
181
- ctx.write (" #include <cstdint>\n " );
182
- ctx.write (" #include <compare>\n " );
183
- ctx.write (" #include \" ecsact/runtime/common.h\"\n " );
184
- ctx.write (" \n " );
181
+ ctx.writef (" #include <cstdint>\n " );
182
+ ctx.writef (" #include <compare>\n " );
183
+ ctx.writef (" #include \" ecsact/runtime/common.h\"\n " );
184
+ ctx.writef (" \n " );
185
185
186
186
const auto namespace_str =
187
187
cpp_identifier (ecsact_meta_package_name (ctx.package_id ));
188
188
189
- ctx.write (" namespace " s, namespace_str, " { \n\n " s );
189
+ ctx.writef (" namespace {} {{ \n\n " , namespace_str );
190
190
191
191
for (auto enum_id : get_enum_ids (ctx.package_id )) {
192
- ctx.write (" enum class " s , ecsact_meta_enum_name (enum_id), " { " );
192
+ ctx.writef (" enum class {} {{ " , ecsact_meta_enum_name (enum_id));
193
193
++ctx.indentation ;
194
- ctx.write (" \n " );
194
+ ctx.writef (" \n " );
195
195
196
196
for (auto & enum_value : get_enum_values (enum_id)) {
197
- ctx.write (enum_value. name , " = " , enum_value.value , " , \n " );
197
+ ctx.writef ( " {} = {}, \n " , enum_value.name , enum_value. value );
198
198
}
199
- ctx.write ( " };" );
199
+ ctx.writef ( " } };" );
200
200
--ctx.indentation ;
201
201
}
202
202
203
203
for (auto comp_id : get_component_ids (ctx.package_id )) {
204
204
auto compo_id = ecsact_id_cast<ecsact_composite_id>(comp_id);
205
- ctx.write (" struct " s, ecsact_meta_component_name (comp_id), " {\n " s);
206
- ctx.write (" \t static constexpr bool transient = false;\n " );
207
- ctx.write (
208
- " \t static constexpr bool has_assoc_fields = " ,
209
- has_assoc_fields (comp_id) ? " true" : " false" ,
210
- " ;\n "
205
+ ctx.writef (" struct {} {{\n " , ecsact_meta_component_name (comp_id));
206
+ ctx.writef (" \t static constexpr bool transient = false;\n " );
207
+ ctx.writef (
208
+ " \t static constexpr bool has_assoc_fields = {};\n " ,
209
+ has_assoc_fields (comp_id) ? " true" : " false"
211
210
);
212
211
write_constexpr_id (ctx, " ecsact_component_id" , comp_id, " \t " );
213
212
write_fields (ctx, compo_id, " \t " s);
214
- ctx.write (" };\n " s );
213
+ ctx.writef (" }} ;\n " );
215
214
}
216
215
217
216
for (auto comp_id : get_transient_ids (ctx.package_id )) {
218
217
auto compo_id = ecsact_id_cast<ecsact_composite_id>(comp_id);
219
- ctx.write (" struct " s, ecsact_meta_transient_name (comp_id), " {\n " s);
220
- ctx.write (" \t static constexpr bool transient = true;\n " );
221
- ctx.write (
222
- " \t static constexpr bool has_assoc_fields = " ,
223
- has_assoc_fields (comp_id) ? " true" : " false" ,
224
- " ;\n "
218
+ ctx.writef (" struct {} {{\n " , ecsact_meta_transient_name (comp_id));
219
+ ctx.writef (" \t static constexpr bool transient = true;\n " );
220
+ ctx.writef (
221
+ " \t static constexpr bool has_assoc_fields = {};\n " ,
222
+ has_assoc_fields (comp_id) ? " true" : " false"
225
223
);
226
224
write_constexpr_id (ctx, " ecsact_transient_id" , comp_id, " \t " );
227
225
write_fields (ctx, compo_id, " \t " s);
228
- ctx.write (" };\n " s );
226
+ ctx.writef (" }} ;\n " );
229
227
}
230
228
231
229
for (auto action_id : get_action_ids (ctx.package_id )) {
232
230
auto compo_id = ecsact_id_cast<ecsact_composite_id>(action_id);
233
- ctx.write (" struct " s, ecsact_meta_action_name (action_id), " {\n " s);
234
- ctx.write (
235
- " \t static constexpr bool has_assoc_fields = " ,
236
- has_assoc_fields (action_id) ? " true" : " false" ,
237
- " ;\n "
231
+ ctx.writef (" struct {} {{\n " , ecsact_meta_action_name (action_id));
232
+ ctx.writef (
233
+ " \t static constexpr bool has_assoc_fields = {};\n " ,
234
+ has_assoc_fields (action_id) ? " true" : " false"
238
235
);
239
236
write_constexpr_id (ctx, " ecsact_action_id" , compo_id, " \t " );
240
237
for (auto child_system_id : get_child_system_ids (action_id)) {
241
238
write_system_struct (ctx, child_system_id, " \t " );
242
239
}
243
240
write_system_impl_decl (ctx, " \t " );
244
241
write_fields (ctx, compo_id, " \t " );
245
- ctx.write (" };\n " s );
242
+ ctx.writef (" }} ;\n " );
246
243
}
247
244
248
245
for (auto sys_id : get_system_ids (ctx.package_id )) {
@@ -253,5 +250,5 @@ void ecsact_codegen_plugin(
253
250
write_system_struct (ctx, sys_id, " " );
254
251
}
255
252
256
- ctx.write (" \n }// namespace " s , namespace_str, " \n " s );
253
+ ctx.writef (" \n }} // namespace {} \n " , namespace_str);
257
254
}
0 commit comments