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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Remove left-over import Created 4 years, 3 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 {%- 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 {%- set const = "" if field.kind|contains_handles else "const" %}
yzshen1 2016/09/20 23:44:40 Does it make sense to name this variable "maybe_co
tibell 2016/09/21 07:10:53 Done.
yzshen1 2016/09/21 23:17:52 It would require adding new attribute in typemap c
tibell 2016/09/22 05:17:23 Done.
12 {%- if return_ref %} 15 {%- if return_ref %}
13 static decltype({{mojom_type}}::{{field.name}})& {{field.name}}( 16 static {{const}} decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
14 {{mojom_type}}Ptr& input) { 17 {{const}} {{mojom_type}}Ptr& input) {
15 return input->{{field.name}}; 18 return input->{{field.name}};
16 } 19 }
17 {%- else %} 20 {%- else %}
18 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( 21 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}(
19 const {{mojom_type}}Ptr& input) { 22 const {{mojom_type}}Ptr& input) {
20 return input->{{field.name}}; 23 return input->{{field.name}};
21 } 24 }
22 {%- endif %} 25 {%- endif %}
23 {%- endfor %} 26 {%- endfor %}
24 27
25 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output); 28 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output);
26 }; 29 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698