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

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: 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..4dbf29c5de4301e53f904d7d7f2b784af24fbe86 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,13 @@ 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) {
+ {{struct.name}}Ptr rv;
+ mojo::internal::StructHelper<{{struct.name}}>::Initialize(
+ &rv, std::forward<Args>(args)...);
+ return rv;
+ }
template <typename U>
static {{struct.name}}Ptr From(const U& u) {
@@ -25,7 +31,16 @@ class {{export_attribute}} {{struct.name}} {
return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this);
}
- {{struct.name}}();
+{% for num_params in range(struct|num_constructor_params) %}
yzshen1 2017/02/13 17:45:53 I feel that it may be sufficient to have the defau
Sam McNally 2017/02/14 02:32:24 I prefer keeping the flexibility. With only those
yzshen1 2017/02/14 17:21:52 I see. That makes sense. Have you considered the
Sam McNally 2017/02/15 06:35:49 I tried that approach; it causes the caller to con
yzshen1 2017/02/15 17:25:42 Thanks for getting these numbers! It is understand
Sam McNally 2017/02/20 09:08:58 Done.
+ {% if num_params == 1 %}explicit {% endif %}{{struct.name}}(
yzshen1 2017/02/13 17:45:53 style nit: usually for the in-line case we only ha
Sam McNally 2017/02/14 02:32:24 Done.
+{%- set fields = struct.fields[:num_params] %}
+{%- for field in fields %}
+{%- 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