9 """! Represents on DaStGen2 object, i.e. one data model
11 A data model has attributes and it is tied to aspects which inject some
12 technical behaviour that is cross-cutting.
19 has_nondefault_constructor=True,
20 embed_attributes_into_data_store=False,
24 Construct the data model
29 public_fields: C++ string
30 This will be used to add public fields to the class, and each
31 attribute can feed into this string. However, you can also
36 @param full_qualified_name Full qualified name
37 Please pass in in C++ convention i.e. with :: separating the namespaces.
57 Check first whether attribute already exists. If it does, replace it.
63 if att._name == attribute._name:
76 This is a pretty simplistic routine:
78 1. Inform the aspect object about the model by invoking set_model()
79 2. Add the aspect to the list of used aspects
82 aspect.set_model(self)
85 _Header_Template_Without_Data_Store =
"""
87// Generated by DaStGen2 (C) 2020 Tobias Weinzierl
89// For DaStGen's copyright, visit www.peano-framework.org. These generated files
90// however are not subject of copyright, i.e. feel free to add your copyright in
102 struct {UNQUALIFIED_CLASS_NAME};
106struct {FULL_QUALIFIED_CLASS_NAME} {{
110 {UNQUALIFIED_CLASS_NAME}() {{}}
111 {UNQUALIFIED_CLASS_NAME}{CONSTRUCTOR_ARGUMENTS};
116{ASPECT_METHOD_DECLARATIONS}
117 std::string toString() const;
120{ATTRIBUTE_DECLARATIONS}
128 _Header_Template_With_Data_Store =
"""
130// Generated by DaStGen2 (C) 2020 Tobias Weinzierl
132// For DaStGen's copyright, visit www.peano-framework.org. These generated files
133// however are not subject of copyright, i.e. feel free to add your copyright in
143 struct {UNQUALIFIED_CLASS_NAME};
147struct {FULL_QUALIFIED_CLASS_NAME} {{
151 {UNQUALIFIED_CLASS_NAME}() {{}}
152 {UNQUALIFIED_CLASS_NAME}{CONSTRUCTOR_ARGUMENTS};
156{ASPECT_METHOD_DECLARATIONS}
157 std::string toString() const;
161{ATTRIBUTE_DECLARATIONS}
166 DataStore _dataStore;
173 Generates the list of constructor arguments needed to fully
174 instantiate an object of the class the datamodel generates.
181 or attribute._is_const_static
182 or attribute._is_constexpr
183 or attribute._is_const
186 for entry
in attribute.get_constructor_arguments():
190 result += entry[1] +
" _" + entry[0]
195 use_default_constructor =
True
197 use_default_constructor = (
198 use_default_constructor
and attribute.use_default_copy_constructor()
200 return use_default_constructor
204 writes the header file for your data model.
207 d[
"ATTRIBUTE_INCLUDES"] =
""
209 d[
"ATTRIBUTE_INCLUDES"] += attribute.get_includes()
211 d[
"UNQUALIFIED_CLASS_NAME"] = dastgen2.get_unqualified_class_name(
215 d[
"OPEN_NAMESPACES"] =
""
216 d[
"CLOSE_NAMESPACES"] =
""
218 d[
"SETTER_GETTER_DECLARATIONS"] =
""
220 d[
"OPEN_NAMESPACES"] +=
"namespace " + i +
"{\n"
221 d[
"CLOSE_NAMESPACES"] +=
"}\n"
225 d[
"PUBLIC_FIELDS"] += attribute.get_public_fields()
227 d[
"ATTRIBUTE_DECLARATIONS"] =
""
229 d[
"ATTRIBUTE_DECLARATIONS"] += attribute.get_attribute_declaration_string()
231 d[
"METHOD_DECLARATIONS"] =
""
233 if attribute.ifdefs != []:
234 d[
"METHOD_DECLARATIONS"] += dastgen2.construct_ifdef_string(
237 for method
in attribute.get_methods(
240 d[
"METHOD_DECLARATIONS"] +=
" "
241 if attribute.expose_in_header_file:
242 d[
"METHOD_DECLARATIONS"] +=
" inline "
243 d[
"METHOD_DECLARATIONS"] += method[1] +
" " + method[0] +
";\n"
244 if attribute.ifdefs != []:
245 d[
"METHOD_DECLARATIONS"] +=
"#endif \n"
247 d[
"ASPECT_ATTRIBUTES"] =
""
248 d[
"ASPECT_METHOD_DECLARATIONS"] =
""
251 d[
"ASPECT_INCLUDES"] =
""
254 d[
"ASPECT_ATTRIBUTES"] += i.get_attributes() +
"\n"
255 d[
"ASPECT_METHOD_DECLARATIONS"] += (
258 include = i.get_include()
260 filtered_includes =
""
261 for line
in include.split(
"\n"):
262 if not(
"tarch" in d[
"FULL_QUALIFIED_CLASS_NAME"]
and line.startswith(
'#include "peano4')):
263 filtered_includes += line +
"\n"
265 d[
"ASPECT_INCLUDES"] += filtered_includes+
"\n"
268 d[
"METHOD_DECLARATIONS"] += (
273 +
"& copy) = default;"
276 d[
"METHOD_DECLARATIONS"] += (
284 if full_qualified_filename.find(
"/") != -1:
285 path = full_qualified_filename[0 : full_qualified_filename.rfind(
"/")]
286 if not os.path.exists(path):
288 with open(full_qualified_filename,
"w")
as output:
295 output.write(
"\n\n\n")
300 In this generation business, I faced multiple issues with initialisation
301 lists: where are comma if some fields are not defined, which fields can
302 I copy directly, and which ones do I have to copy manually, and so forth.
317 or attribute._is_const_static
318 or attribute._is_constexpr
319 or attribute._is_const
324 if attribute.ifdefs != []:
325 output.write(dastgen2.construct_ifdef_string(attribute.ifdefs))
328 + attribute._name[0].title()
329 + attribute._name[1:].split(
"[")[0]
331 + attribute._name.split(
"[")[0]
334 if attribute.ifdefs != []:
335 output.write(
"#endif \n")
342 output.write(
" std::ostringstream out;\n")
343 output.write(
' out << "(";\n')
345 if attribute.ifdefs != []:
346 output.write(dastgen2.construct_ifdef_string(attribute.ifdefs))
348 output.write(
""" out << ","; \n""")
353 + attribute.get_to_string()
356 if attribute.ifdefs != []:
357 output.write(
"#endif \n")
359 output.write(
' out << ")";\n')
360 output.write(
" return out.str();\n")
361 output.write(
"}\n\n\n")
375 or attribute._is_const_static
376 or attribute._is_constexpr
377 or attribute._is_const
381 if attribute.ifdefs != []:
382 output.write(dastgen2.construct_ifdef_string(attribute.ifdefs))
383 uppercase_name = attribute.name[0].upper() + attribute.name[1:]
385 " set" + uppercase_name +
"( copy.get" + uppercase_name +
"() );\n"
387 if attribute.ifdefs != []:
388 output.write(
"#endif \n")
389 output.write(
"}\n\n\n")
394 Generate getter/setter functions.
396 Generate all the setters and getters and use get_methods() to
397 construct them for the individual attributes.
400 File object that will be written to.
402 is_cpp_file: Boolean.
403 True if the output is intended to be the .cpp file. False if it's
408 if attribute.expose_in_header_file != is_cpp_file:
409 if attribute.ifdefs != []:
410 output.write(dastgen2.construct_ifdef_string(attribute.ifdefs))
411 for method
in attribute.get_methods(
422 output.write(attribute.get_method_body(method[0]))
423 output.write(
"}\n\n\n")
424 if attribute.ifdefs != []:
425 output.write(
"#endif \n\n\n")
429 writes the implementation (.cpp) file for your data model.
431 with open(full_qualified_filename,
"w")
as output:
450 if hasattr(aspect,
"implementation_file_includes"):
451 output.write( aspect.implementation_file_includes )
455 output.write(
"\n\n\n")
459 output.write(
"\n\n\n")
462 output.write(
"\n\n\n")
465 output.write(
"\n\n\n")
472 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.
add_aspect(self, aspect)
Add a new aspect.
__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
full_qualified_name(self)
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 model.
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)