8 """! Represents on DaStGen2 object, i.e. one data model.
10 full_qualified_name Full qualified name. Please pass in in C++ convention i.e. with
11 :: separating the namespaces.
18 has_nondefault_constructor=True,
19 embed_attributes_into_data_store=False,
23 Construct the data modell
25 public_fields: C++ string
26 This will be used to add public fields to the class, and each
27 attribute can feed into this string. However, you can also
48 Check first whether attribute already exists. If it does, replace it.
54 if att._name == attribute._name:
63 aspect.set_model(self)
66 _Header_Template_Without_Data_Store =
"""
68// Generated by DaStGen2 (C) 2020 Tobias Weinzierl
70// For DaStGen's copyright, visit www.peano-framework.org. These generated files
71// however are not subject of copyright, i.e. feel free to add your copyright in
83 struct {UNQUALIFIED_CLASS_NAME};
87struct {FULL_QUALIFIED_CLASS_NAME} {{
91 {UNQUALIFIED_CLASS_NAME}() {{}}
92 {UNQUALIFIED_CLASS_NAME}{CONSTRUCTOR_ARGUMENTS};
97{ASPECT_METHOD_DECLARATIONS}
98 std::string toString() const;
101{ATTRIBUTE_DECLARATIONS}
109 _Header_Template_With_Data_Store =
"""
111// Generated by DaStGen2 (C) 2020 Tobias Weinzierl
113// For DaStGen's copyright, visit www.peano-framework.org. These generated files
114// however are not subject of copyright, i.e. feel free to add your copyright in
124 struct {UNQUALIFIED_CLASS_NAME};
128struct {FULL_QUALIFIED_CLASS_NAME} {{
132 {UNQUALIFIED_CLASS_NAME}() {{}}
133 {UNQUALIFIED_CLASS_NAME}{CONSTRUCTOR_ARGUMENTS};
137{ASPECT_METHOD_DECLARATIONS}
138 std::string toString() const;
142{ATTRIBUTE_DECLARATIONS}
147 DataStore _dataStore;
154 Generates the list of constructor arguments needed to fully
155 instantiate an object of the class the datamodel generates.
162 or attribute._is_const_static
163 or attribute._is_constexpr
164 or attribute._is_const
167 for entry
in attribute.get_constructor_arguments():
171 result += entry[1] +
" _" + entry[0]
176 use_default_constructor =
True
178 use_default_constructor = (
179 use_default_constructor
and attribute.use_default_copy_constructor()
181 return use_default_constructor
185 writes the header file for your data model.
188 d[
"ATTRIBUTE_INCLUDES"] =
""
190 d[
"ATTRIBUTE_INCLUDES"] += attribute.get_includes()
192 d[
"UNQUALIFIED_CLASS_NAME"] = dastgen2.get_unqualified_class_name(
196 d[
"OPEN_NAMESPACES"] =
""
197 d[
"CLOSE_NAMESPACES"] =
""
199 d[
"SETTER_GETTER_DECLARATIONS"] =
""
201 d[
"OPEN_NAMESPACES"] +=
"namespace " + i +
"{\n"
202 d[
"CLOSE_NAMESPACES"] +=
"}\n"
206 d[
"PUBLIC_FIELDS"] += attribute.get_public_fields()
208 d[
"ATTRIBUTE_DECLARATIONS"] =
""
210 d[
"ATTRIBUTE_DECLARATIONS"] += attribute.get_attribute_declaration_string()
212 d[
"METHOD_DECLARATIONS"] =
""
214 if attribute.ifdefs != []:
215 d[
"METHOD_DECLARATIONS"] += dastgen2.construct_ifdef_string(
218 for method
in attribute.get_methods(
221 d[
"METHOD_DECLARATIONS"] +=
" "
222 if attribute.expose_in_header_file:
223 d[
"METHOD_DECLARATIONS"] +=
" inline "
224 d[
"METHOD_DECLARATIONS"] += method[1] +
" " + method[0] +
";\n"
225 if attribute.ifdefs != []:
226 d[
"METHOD_DECLARATIONS"] +=
"#endif \n"
228 d[
"ASPECT_ATTRIBUTES"] =
""
229 d[
"ASPECT_METHOD_DECLARATIONS"] =
""
232 d[
"ASPECT_INCLUDES"] =
""
235 d[
"ASPECT_ATTRIBUTES"] += i.get_attributes() +
"\n"
236 d[
"ASPECT_METHOD_DECLARATIONS"] += (
239 include = i.get_include()
241 filtered_includes =
""
242 for line
in include.split(
"\n"):
243 if not(
"tarch" in d[
"FULL_QUALIFIED_CLASS_NAME"]
and line.startswith(
'#include "peano4')):
244 filtered_includes += line +
"\n"
246 d[
"ASPECT_INCLUDES"] += filtered_includes+
"\n"
249 d[
"METHOD_DECLARATIONS"] += (
254 +
"& copy) = default;"
257 d[
"METHOD_DECLARATIONS"] += (
265 if full_qualified_filename.find(
"/") != -1:
266 path = full_qualified_filename[0 : full_qualified_filename.rfind(
"/")]
267 if not os.path.exists(path):
269 with open(full_qualified_filename,
"w")
as output:
276 output.write(
"\n\n\n")
281 In this generation business, I faced multiple issues with initialisation
282 lists: where are comma if some fields are not defined, which fields can
283 I copy directly, and which ones do I have to copy manually, and so forth.
298 or attribute._is_const_static
299 or attribute._is_constexpr
300 or attribute._is_const
305 if attribute.ifdefs != []:
306 output.write(dastgen2.construct_ifdef_string(attribute.ifdefs))
309 + attribute._name[0].title()
310 + attribute._name[1:].split(
"[")[0]
312 + attribute._name.split(
"[")[0]
315 if attribute.ifdefs != []:
316 output.write(
"#endif \n")
323 output.write(
" std::ostringstream out;\n")
324 output.write(
' out << "(";\n')
326 if attribute.ifdefs != []:
327 output.write(dastgen2.construct_ifdef_string(attribute.ifdefs))
329 output.write(
""" out << ","; \n""")
334 + attribute.get_to_string()
337 if attribute.ifdefs != []:
338 output.write(
"#endif \n")
340 output.write(
' out << ")";\n')
341 output.write(
" return out.str();\n")
342 output.write(
"}\n\n\n")
356 or attribute._is_const_static
357 or attribute._is_constexpr
358 or attribute._is_const
362 if attribute.ifdefs != []:
363 output.write(dastgen2.construct_ifdef_string(attribute.ifdefs))
364 uppercase_name = attribute.name[0].upper() + attribute.name[1:]
366 " set" + uppercase_name +
"( copy.get" + uppercase_name +
"() );\n"
368 if attribute.ifdefs != []:
369 output.write(
"#endif \n")
370 output.write(
"}\n\n\n")
375 Generate getter/setter functions.
377 Generate all the setters and getters and use get_methods() to
378 construct them for the individual attributes.
381 File object that will be written to.
383 is_cpp_file: Boolean.
384 True if the output is intended to be the .cpp file. False if it's
389 if attribute.expose_in_header_file != is_cpp_file:
390 if attribute.ifdefs != []:
391 output.write(dastgen2.construct_ifdef_string(attribute.ifdefs))
392 for method
in attribute.get_methods(
403 output.write(attribute.get_method_body(method[0]))
404 output.write(
"}\n\n\n")
405 if attribute.ifdefs != []:
406 output.write(
"#endif \n\n\n")
410 writes the implementation (.cpp) file for your data model.
412 with open(full_qualified_filename,
"w")
as output:
431 if hasattr(aspect,
"implementation_file_includes"):
432 output.write( aspect.implementation_file_includes )
436 output.write(
"\n\n\n")
440 output.write(
"\n\n\n")
443 output.write(
"\n\n\n")
446 output.write(
"\n\n\n")
453 i.expose_in_header_file =
True
Represents on DaStGen2 object, i.e.
_embed_attributes_into_data_store
write_implementation_file(self, full_qualified_filename)
writes the implementation (.cpp) file for your data model.
__use_default_copy_constructor(self)
_get_constructor_arguments(self)
Generates the list of constructor arguments needed to fully instantiate an object of the class the da...
__generate_constructor_definition(self, output)
In this generation business, I faced multiple issues with initialisation lists: where are comma if so...
expose_all_attributes_in_header_file(self)
__generate_accessors(self, output, is_cpp_file)
Generate getter/setter functions.
add_attribute(self, attribute)
has_nondefault_constructor
str _Header_Template_With_Data_Store
write_header_file(self, full_qualified_filename)
writes the header file for your data model.
__generate_toString_definition(self, output)
__init__(self, full_qualified_name, has_nondefault_constructor=True, embed_attributes_into_data_store=False)
Construct the data modell.
set_full_qualified_name(self, full_qualified_name)
str _Header_Template_Without_Data_Store
add_or_replace_attribute(self, attribute)
Check first whether attribute already exists.
__generate_explicit_copy_constructor(self, output)