| OLD | NEW |
| 1 {%- set mojom_type = struct|get_qualified_name_for_kind %} | 1 {%- set mojom_type = struct|get_qualified_name_for_kind %} |
| 2 | 2 |
| 3 template <> | 3 template <> |
| 4 struct {{export_attribute}} StructTraits<{{mojom_type}}::DataView, | 4 struct {{export_attribute}} StructTraits<{{mojom_type}}::DataView, |
| 5 {{mojom_type}}Ptr> { | 5 {{mojom_type}}Ptr> { |
| 6 static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; } | 6 static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; } |
| 7 static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); } | 7 static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); } |
| 8 | 8 |
| 9 {%- for field in struct.fields %} | 9 {%- for field in struct.fields %} |
| 10 {%- set return_ref = field.kind|is_object_kind or | 10 {%- set return_ref = field.kind|is_object_kind or |
| 11 field.kind|is_any_handle_or_interface_kind %} | 11 field.kind|is_any_handle_or_interface_kind %} |
| 12 {# We want the field accessor to be const whenever possible to allow #} |
| 13 {# structs to be used as map keys. #} |
| 14 {# TODO(tibell): Make this change more precise to deal with e.g. #} |
| 15 {# copyable_pass_by_value type-mapped structs. #} |
| 16 {%- set maybe_const = "" if field.kind|contains_handles else "const" %} |
| 12 {%- if return_ref %} | 17 {%- if return_ref %} |
| 13 static decltype({{mojom_type}}::{{field.name}})& {{field.name}}( | 18 static {{maybe_const}} decltype({{mojom_type}}::{{field.name}})& {{field.name}
}( |
| 14 {{mojom_type}}Ptr& input) { | 19 {{maybe_const}} {{mojom_type}}Ptr& input) { |
| 15 return input->{{field.name}}; | 20 return input->{{field.name}}; |
| 16 } | 21 } |
| 17 {%- else %} | 22 {%- else %} |
| 18 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( | 23 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( |
| 19 const {{mojom_type}}Ptr& input) { | 24 const {{mojom_type}}Ptr& input) { |
| 20 return input->{{field.name}}; | 25 return input->{{field.name}}; |
| 21 } | 26 } |
| 22 {%- endif %} | 27 {%- endif %} |
| 23 {%- endfor %} | 28 {%- endfor %} |
| 24 | 29 |
| 25 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output); | 30 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output); |
| 26 }; | 31 }; |
| OLD | NEW |