Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 {{struct.name}}Ptr rv; | |
| 19 mojo::internal::StructHelper<{{struct.name}}>::Initialize( | |
| 20 &rv, std::forward<Args>(args)...); | |
| 21 return rv; | |
| 22 } | |
| 17 | 23 |
| 18 template <typename U> | 24 template <typename U> |
| 19 static {{struct.name}}Ptr From(const U& u) { | 25 static {{struct.name}}Ptr From(const U& u) { |
| 20 return mojo::TypeConverter<{{struct.name}}Ptr, U>::Convert(u); | 26 return mojo::TypeConverter<{{struct.name}}Ptr, U>::Convert(u); |
| 21 } | 27 } |
| 22 | 28 |
| 23 template <typename U> | 29 template <typename U> |
| 24 U To() const { | 30 U To() const { |
| 25 return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this); | 31 return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this); |
| 26 } | 32 } |
| 27 | 33 |
| 28 {{struct.name}}(); | 34 {% 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.
| |
| 35 {% 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.
| |
| 36 {%- set fields = struct.fields[:num_params] %} | |
| 37 {%- for field in fields %} | |
| 38 {%- set type = field.kind|cpp_wrapper_param_type %} | |
| 39 {%- set name = field.name %} | |
| 40 {{type}} {{name}} | |
| 41 {%- if not loop.last -%},{%- endif %} | |
| 42 {%- endfor %}); | |
| 43 {% endfor %} | |
| 29 ~{{struct.name}}(); | 44 ~{{struct.name}}(); |
| 30 | 45 |
| 31 // Clone() is a template so it is only instantiated if it is used. Thus, the | 46 // 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 | 47 // bindings generator does not need to know whether Clone() or copy |
| 33 // constructor/assignment are available for members. | 48 // constructor/assignment are available for members. |
| 34 template <typename StructPtrType = {{struct.name}}Ptr> | 49 template <typename StructPtrType = {{struct.name}}Ptr> |
| 35 {{struct.name}}Ptr Clone() const; | 50 {{struct.name}}Ptr Clone() const; |
| 36 | 51 |
| 37 // Equals() is a template so it is only instantiated if it is used. Thus, the | 52 // 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 | 53 // bindings generator does not need to know whether Equals() or == operator |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 69 {%- set name = field.name %} | 84 {%- set name = field.name %} |
| 70 {{type}} {{name}}; | 85 {{type}} {{name}}; |
| 71 {%- endfor %} | 86 {%- endfor %} |
| 72 | 87 |
| 73 {%- if struct|contains_move_only_members %} | 88 {%- if struct|contains_move_only_members %} |
| 74 private: | 89 private: |
| 75 DISALLOW_COPY_AND_ASSIGN({{struct.name}}); | 90 DISALLOW_COPY_AND_ASSIGN({{struct.name}}); |
| 76 {%- endif %} | 91 {%- endif %} |
| 77 }; | 92 }; |
| 78 | 93 |
| OLD | NEW |