diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-03 13:58:52 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-03 16:08:58 +0200 |
commit | 4130a7209150e9796c869bbd64a6ccc32fab9053 (patch) | |
tree | 2cfd006be9c004f32e228a675930862480096cfd /build-aux/qmi-codegen/VariableArray.py | |
parent | b2cc17350269abd8320ba96f88705e3e836a342d (diff) | |
download | external_libqmi-4130a7209150e9796c869bbd64a6ccc32fab9053.zip external_libqmi-4130a7209150e9796c869bbd64a6ccc32fab9053.tar.gz external_libqmi-4130a7209150e9796c869bbd64a6ccc32fab9053.tar.bz2 |
qmi-codegen: let variables decide how the getter/setter methods pass them
And change the structs to be passed by reference.
Diffstat (limited to 'build-aux/qmi-codegen/VariableArray.py')
-rw-r--r-- | build-aux/qmi-codegen/VariableArray.py | 102 |
1 files changed, 94 insertions, 8 deletions
diff --git a/build-aux/qmi-codegen/VariableArray.py b/build-aux/qmi-codegen/VariableArray.py index 68674ed..3ffc9ad 100644 --- a/build-aux/qmi-codegen/VariableArray.py +++ b/build-aux/qmi-codegen/VariableArray.py @@ -144,42 +144,128 @@ class VariableArray(Variable): """ - GArrays are ref-counted, so we can just provide a new ref to the array. + Variable declaration """ - def emit_copy(self, f, line_prefix, variable_name_from, variable_name_to): + def build_variable_declaration(self, line_prefix, variable_name): + translations = { 'lp' : line_prefix, + 'name' : variable_name } + + template = ( + '${lp}GArray *${name};\n') + return string.Template(template).substitute(translations) + + + """ + Getter for the array type + """ + def build_getter_declaration(self, line_prefix, variable_name): + translations = { 'lp' : line_prefix, + 'name' : variable_name } + + template = ( + '${lp}GArray **${name},\n') + return string.Template(template).substitute(translations) + + + """ + Documentation for the getter + """ + def build_getter_documentation(self, line_prefix, variable_name): + translations = { 'lp' : line_prefix, + 'public_array_element_format' : self.array_element.public_format, + 'name' : variable_name } + + template = ( + '${lp}@${name}: a placeholder for the output #GArray of #${public_array_element_format} elements, or #NULL if not required. Do not free it, it is owned by @self.\n') + return string.Template(template).substitute(translations) + + + """ + Builds the array getter implementation + """ + def build_getter_implementation(self, line_prefix, variable_name_from, variable_name_to, to_is_reference): translations = { 'lp' : line_prefix, 'from' : variable_name_from, 'to' : variable_name_to } + if to_is_reference: + template = ( + '${lp}if (${to})\n' + '${lp} *${to} = ${from};\n') + return string.Template(template).substitute(translations) + else: + template = ( + '${lp}${to} = ${from};\n') + return string.Template(template).substitute(translations) + + + """ + Setter for the array type + """ + def build_setter_declaration(self, line_prefix, variable_name): + translations = { 'lp' : line_prefix, + 'name' : variable_name } + + template = ( + '${lp}GArray *${name},\n') + return string.Template(template).substitute(translations) + + + """ + Documentation for the setter + """ + def build_setter_documentation(self, line_prefix, variable_name): + translations = { 'lp' : line_prefix, + 'public_array_element_format' : self.array_element.public_format, + 'name' : variable_name } + template = ( + '${lp}@${name}: a #GArray of #${public_array_element_format} elements. A new reference to @{name} will be taken.\n') + return string.Template(template).substitute(translations) + + + """ + Builds the array setter implementation + """ + def build_setter_implementation(self, line_prefix, variable_name_from, variable_name_to): + translations = { 'lp' : line_prefix, + 'from' : variable_name_from, + 'to' : variable_name_to } + + template = ( + '${lp}if (${to})\n' + '${lp} g_array_unref (${to});\n' '${lp}${to} = g_array_ref (${from});\n') - f.write(string.Template(template).substitute(translations)) + return string.Template(template).substitute(translations) """ FIXME: we should only dispose the members of the array if the refcount of the array reached zero. Use g_array_set_clear_func() for that. """ - def emit_dispose(self, f, line_prefix, variable_name): + def build_dispose(self, line_prefix, variable_name): translations = { 'lp' : line_prefix, 'variable_name' : variable_name } + built = '' + if self.array_element.needs_dispose == True: template = ( '${lp}{\n' '${lp} guint i;\n' '\n' '${lp} for (i = 0; i < ${variable_name}->len; i++) {\n') - f.write(string.Template(template).substitute(translations)) + built += string.Template(template).substitute(translations) - self.array_element.emit_dispose(f, line_prefix, 'g_array_index (' + variable_name + ',' + self.array_element.public_format + ', i)') + built += self.array_element.build_dispose(line_prefix, 'g_array_index (' + variable_name + ',' + self.array_element.public_format + ', i)') template = ( '${lp} }\n' '${lp}}') - f.write(string.Template(template).substitute(translations)) + built += string.Template(template).substitute(translations) template = ( '${lp}g_array_unref (${variable_name});\n') - f.write(string.Template(template).substitute(translations)) + built += string.Template(template).substitute(translations) + return built |