Chromium Code Reviews| 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 |