11 Represents one attribute.
13 This is the superclass of all attributes tied
19 classifies attribute qualifiers.
32 qualifier=Qualifier.NONE,
34 expose_in_header_file=False,
39 This is a plain string which has to follow the C++ naming conventions, i.e.
40 it is case-sensitive and may not contain any special characters besides the
41 underscore. If also has to be unique within the enclosing data model.
42 However, this uniqueness is a C++ constraint. A DaStGen model can hold the
43 same attribute multiple times, as long as their ifdefs are different and
44 hence mask them out, i.e. ensure that only version is "active" at any
48 A set of strings which have to hold at compile time to determine if this
49 attribute does exist or not.
51 qualifier: self.Qualifier
52 An additional qualifier.
55 Initial value. The type depends on underlying type. But you can always pass
56 in a string that evaluates to the correct type.
58 expose_in_header_file: Boolean
59 Flag that determines if an attribute's setters and getters should have an
60 implementation within the header or if the generated C++ code should strictly
61 separate declaration and definition and stick the latter into a separate
62 implementation and hence object file.
78 ": You need to provide an initialisation value for a const attribute",
100 Return string that is to be embedded into the public part of the class
101 definition. Most attributes don't add anything here, but some (alike
102 enumerations) need to.
108 def get_methods(self, _full_qualified_class_name, for_declaration=True):
111 Return sequence of methods that are defined for this attribute. Each
112 entry is a tuple. Its first entry is the signature of the function
113 (not including the semicolon), the second entry is the return type.
115 for_declaration: Boolean
116 if True, assume we want method names for function declaration, not
117 definition. Some generators might - for example - add additional
118 annotations for the declaration such as Clang attributes. The
119 most frequently used use case for this flag is the static
120 annotation. To make a function a class function, you have to
121 declare it as static. But the definition does not allow you to
122 repeat that static keyword again.
130 If this routine returns False, the generator will create a copy
131 constructor copying each attribute over via a setter/getter
140 Return list of tuple of arguments for the constructor. The first
141 tuple entry is the name, the second one the type. By default,
142 I take them from the plain C attributes, but you can alter
152 Return list of n-tuples. The tuple can either host two, three or
153 four entries. The list itself may contain arbitrary many tuples, as
154 one attribute logically can map onto multiple technical attributes.
155 For example, when declaring an array, also declare an integer variable
156 containing its length.
158 for_constructor: bool
159 whether the return value of this function is intended for use
160 in the constructor method of the DataModel. If true, will omit
161 (optionally provided) initialization values in the attribute
167 The first triple entry always is the name, the second one the type.
168 Type has to be plain C.
172 The first triple entry always is the name, the second one the type.
173 Type has to be plain C. The third entry is a C++ attribute, i.e.
174 a string embedded into [[...]].
178 The first triple entry always is the name, the second one the type.
179 Type has to be plain C. The third entry is a C++ attribute, i.e.
180 a string embedded into [[...]].
181 The fourth attribute is a list of ifdef symbols that have to be
182 defined to use this attribute. The list of
183 symbols is concatenated with an and. You can return an empty list.
184 All symbol definitions can also be expressions such sa DEBUG>0
187 Please note that these latter ifdefs are something completely
188 different than the base class ifdefs. The base class ifdefs are
189 to be used if you want to switch attributes on and off. The
190 attributes here are used to switch between realisation variants.
195 Arrays can be modelled by adding a cardinality ("[15]" for example)
196 to the first triple entry, i.e. the name.
199 assert False,
"abstract function should not be called"
205 For MPI for example, I need to know the first attribute. If you map
206 your attribute onto multiple data types, it is one type that represents the whole thing.
213 Construct the string used for variable declaration using the
214 output of get_plain_C_attributes(self). This is a list of tuples,
215 each tuple containing two, three, or four entries.
217 See get_plain_C_attributes(self) for more details.
221 decString += construct_ifdef_string(self.
ifdefs)
227 if len(subattribute) == 4:
228 decString += construct_ifdef_string(subattribute[3])
238 decString +=
"#endif\n"
239 elif len(subattribute) == 3:
249 elif len(subattribute) == 2:
250 decString +=
" " + subattribute[1] +
" " + subattribute[0] +
";\n"
252 raise IndexError(
"wrong number of attribute tuples")
255 decString +=
"#endif \n"
261 Generate the accessor name used throughout dastgen2 to
262 create variables, function names, etc.
264 accessor_name = self.
_name[0].capitalize() + self.
_name[1:]
271 I hand in the method signature (see get_methods()) and wanna get
272 the whole implementation.
275 assert False,
"not implemented"
282 I expect that there's at least one setter/getter pair
291 Return native (built-in) MPI datatype. Return None if there's no
292 direct mapping. The actual result is not a string only, but a list
293 of tuples from native type to cardinality.
302 Return string representation of attribute. Should be something
303 that can be streamed via << into a sstream. So the result has
304 to be of type string.
classifies attribute qualifiers.
Represents one attribute.
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
get_attribute_declaration_string(self)
Construct the string used for variable declaration using the output of get_plain_C_attributes(self).
get_public_fields(self)
Return string that is to be embedded into the public part of the class definition.
get_constructor_arguments(self)
Return list of tuple of arguments for the constructor.
get_native_MPI_type(self)
Return native (built-in) MPI datatype.
use_default_copy_constructor(self)
If this routine returns False, the generator will create a copy constructor copying each attribute ov...
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
get_accessor_name(self)
Generate the accessor name used throughout dastgen2 to create variables, function names,...
get_first_plain_C_attribute(self)
For MPI for example, I need to know the first attribute.
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
get_to_string(self)
Return string representation of attribute.
__init__(self, name, ifdefs=[], qualifier=Qualifier.NONE, initval=None, expose_in_header_file=False)
name: String This is a plain string which has to follow the C++ naming conventions,...
name(self)
I expect that there's at least one setter/getter pair.