Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl

Issue 2689513003: Add field-initializing constructors to generated mojo structs. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl
index e6d04268520aa5f0f0a77a4c4e14839711d1c5ed..e75543f14eb3cee51949ab24509796225847e8d9 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl
@@ -1,18 +1,23 @@
-// static
-{{struct.name}}Ptr {{struct.name}}::New() {
- {{struct.name}}Ptr rv;
- mojo::internal::StructHelper<{{struct.name}}>::Initialize(&rv);
- return rv;
-}
-
-{{struct.name}}::{{struct.name}}()
-{%- for field in struct.fields %}
- {% if loop.first %}:{% else %} {% endif %} {{field.name}}({{field|default_value}}){% if not loop.last %},{% endif %}
-{%- endfor %} {
-}
-
-{{struct.name}}::~{{struct.name}}() {
-}
+{% for constructor in struct|struct_constructors %}
+{{struct.name}}::{{struct.name}}(
+{%- for field in constructor.params %}
+{%- set type = field.kind|cpp_wrapper_param_type %}
+{%- set name = field.name %}
+ {{type}} {{name}}_in
+{%- if not loop.last -%},{%- endif %}
+{%- endfor %})
+{%- for field, is_parameter in constructor.fields %}
+{%- set name = field.name %}
+ {% if loop.first %}:{% else %} {% endif %} {{name}}(
+{%- if is_parameter -%}
+std::move({{name}}_in)
+{%- else -%}
+{{ field|default_value }}
+{%- endif -%}
+){% if not loop.last %},{% endif %}
+{%- endfor %} {}
+{% endfor %}
+{{struct.name}}::~{{struct.name}}() = default;
{%- if struct|is_hashable %}
size_t {{struct.name}}::Hash(size_t seed) const {

Powered by Google App Engine
This is Rietveld 408576698