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

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.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_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
index 1f3ec1e2b1b8bca08314cd58275bf74b0f0a16d1..9e6e46f19e66cc6021ebf26d77eae107333c49f1 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
@@ -13,7 +13,12 @@ class {{export_attribute}} {{struct.name}} {
static {{constant|format_constant_declaration(nested=True)}};
{%- endfor %}
- static {{struct.name}}Ptr New();
+ template <typename... Args>
+ static {{struct.name}}Ptr New(Args&&... args) {
+ return {{struct.name}}Ptr(
+ base::in_place,
+ std::forward<Args>(args)...);
+ }
template <typename U>
static {{struct.name}}Ptr From(const U& u) {
@@ -25,7 +30,15 @@ class {{export_attribute}} {{struct.name}} {
return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this);
}
- {{struct.name}}();
+{% for constructor in struct|struct_constructors %}
+ {% if constructor.params|length == 1 %}explicit {% endif %}{{struct.name}}(
+{%- for field in constructor.params %}
+{%- set type = field.kind|cpp_wrapper_param_type %}
+{%- set name = field.name %}
+ {{type}} {{name}}
+{%- if not loop.last -%},{%- endif %}
+{%- endfor %});
+{% endfor %}
~{{struct.name}}();
// Clone() is a template so it is only instantiated if it is used. Thus, the

Powered by Google App Engine
This is Rietveld 408576698