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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
1 class {{export_attribute}} {{struct.name}} { 1 class {{export_attribute}} {{struct.name}} {
2 public: 2 public:
3 using DataView = {{struct.name}}DataView; 3 using DataView = {{struct.name}}DataView;
4 using Data_ = internal::{{struct.name}}_Data; 4 using Data_ = internal::{{struct.name}}_Data;
5 5
6 {#--- Enums #} 6 {#--- Enums #}
7 {%- for enum in struct.enums -%} 7 {%- for enum in struct.enums -%}
8 using {{enum.name}} = {{enum|get_name_for_kind(flatten_nested_kind=True)}}; 8 using {{enum.name}} = {{enum|get_name_for_kind(flatten_nested_kind=True)}};
9 {%- endfor %} 9 {%- endfor %}
10 10
11 {#--- Constants #} 11 {#--- Constants #}
12 {%- for constant in struct.constants %} 12 {%- for constant in struct.constants %}
13 static {{constant|format_constant_declaration(nested=True)}}; 13 static {{constant|format_constant_declaration(nested=True)}};
14 {%- endfor %} 14 {%- endfor %}
15 15
16 static {{struct.name}}Ptr New(); 16 template <typename... Args>
17 static {{struct.name}}Ptr New(Args&&... args) {
18 return {{struct.name}}Ptr(
19 base::in_place,
20 std::forward<Args>(args)...);
21 }
17 22
18 template <typename U> 23 template <typename U>
19 static {{struct.name}}Ptr From(const U& u) { 24 static {{struct.name}}Ptr From(const U& u) {
20 return mojo::TypeConverter<{{struct.name}}Ptr, U>::Convert(u); 25 return mojo::TypeConverter<{{struct.name}}Ptr, U>::Convert(u);
21 } 26 }
22 27
23 template <typename U> 28 template <typename U>
24 U To() const { 29 U To() const {
25 return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this); 30 return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this);
26 } 31 }
27 32
28 {{struct.name}}(); 33 {% for constructor in struct|struct_constructors %}
34 {% if constructor.params|length == 1 %}explicit {% endif %}{{struct.name}}(
35 {%- for field in constructor.params %}
36 {%- set type = field.kind|cpp_wrapper_param_type %}
37 {%- set name = field.name %}
38 {{type}} {{name}}
39 {%- if not loop.last -%},{%- endif %}
40 {%- endfor %});
41 {% endfor %}
29 ~{{struct.name}}(); 42 ~{{struct.name}}();
30 43
31 // Clone() is a template so it is only instantiated if it is used. Thus, the 44 // Clone() is a template so it is only instantiated if it is used. Thus, the
32 // bindings generator does not need to know whether Clone() or copy 45 // bindings generator does not need to know whether Clone() or copy
33 // constructor/assignment are available for members. 46 // constructor/assignment are available for members.
34 template <typename StructPtrType = {{struct.name}}Ptr> 47 template <typename StructPtrType = {{struct.name}}Ptr>
35 {{struct.name}}Ptr Clone() const; 48 {{struct.name}}Ptr Clone() const;
36 49
37 // Equals() is a template so it is only instantiated if it is used. Thus, the 50 // Equals() is a template so it is only instantiated if it is used. Thus, the
38 // bindings generator does not need to know whether Equals() or == operator 51 // bindings generator does not need to know whether Equals() or == operator
(...skipping 30 matching lines...) Expand all
69 {%- set name = field.name %} 82 {%- set name = field.name %}
70 {{type}} {{name}}; 83 {{type}} {{name}};
71 {%- endfor %} 84 {%- endfor %}
72 85
73 {%- if struct|contains_move_only_members %} 86 {%- if struct|contains_move_only_members %}
74 private: 87 private:
75 DISALLOW_COPY_AND_ASSIGN({{struct.name}}); 88 DISALLOW_COPY_AND_ASSIGN({{struct.name}});
76 {%- endif %} 89 {%- endif %}
77 }; 90 };
78 91
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698