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

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

Issue 1966933002: Mojo C++ bindings: switch the existing usage of StructTraits to use the new data view interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@26_reader
Patch Set: typeid() is not allowed :/ Created 4 years, 7 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 {% from "enum_macros.tmpl" import enum_decl -%} 1 {% from "enum_macros.tmpl" import enum_decl -%}
2 2
3 class {{struct.name}} { 3 class {{struct.name}} {
4 public: 4 public:
5 using Data_ = internal::{{struct.name}}_Data; 5 using Data_ = internal::{{struct.name}}_Data;
6 6
7 // TODO(yzshen): Remove Reader.
8 using Reader = {{struct.name}}_Reader;
9
10 {#--- Enums #} 7 {#--- Enums #}
11 {%- for enum in struct.enums -%} 8 {%- for enum in struct.enums -%}
12 {{enum_decl(enum)|indent(2)}} 9 {{enum_decl(enum)|indent(2)}}
13 {%- endfor %} 10 {%- endfor %}
14 11
15 {#--- Constants #} 12 {#--- Constants #}
16 {%- for constant in struct.constants %} 13 {%- for constant in struct.constants %}
17 {%- if constant.kind|is_integral_kind %} 14 {%- if constant.kind|is_integral_kind %}
18 static const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|con stant_value}}; 15 static const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|con stant_value}};
19 {%- else %} 16 {%- else %}
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 51 }
55 52
56 {#--- Struct members #} 53 {#--- Struct members #}
57 {% for field in struct.fields %} 54 {% for field in struct.fields %}
58 {%- set type = field.kind|cpp_wrapper_type %} 55 {%- set type = field.kind|cpp_wrapper_type %}
59 {%- set name = field.name %} 56 {%- set name = field.name %}
60 {{type}} {{name}}; 57 {{type}} {{name}};
61 {%- endfor %} 58 {%- endfor %}
62 }; 59 };
63 60
64 {# TODO(yzshen): Redo the Reader interface. #}
65 {# NOTE: Generated Reader instances are intentionally cheap to copy and devoid
66 of heap allocations. They should stay this way. #}
67 // TODO(yzshen): Remove this.
68 class {{struct.name}}_Reader {
69 public:
70 {{struct.name}}_Reader(internal::{{struct.name}}_Data* data,
71 mojo::internal::SerializationContext* context);
72
73 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
74 {%- set kind = pf.field.kind -%}
75 {%- set name = pf.field.name -%}
76 {%- if kind|is_nullable_kind %}
77 bool has_{{name}}() const;
78 {%- endif %}
79 {%- if kind|is_struct_kind and not kind|is_native_only_kind %}
80 {{kind|get_name_for_kind}}_Reader {{name}}() const;
81 {%- elif kind|is_string_kind %}
82 base::StringPiece {{name}}() const;
83 {%- elif kind|is_union_kind %}
84 // TODO(rockot): Support reading unions. ({{name}}() omitted)
85 {%- elif kind|is_object_kind %}
86 // TODO(rockot): Support reading other object kinds. ({{name}}() omitted)
87 {%- elif kind|is_any_handle_kind %}
88 // TODO(rockot): Support reading handles. ({{name}}() omitted)
89 {%- elif kind|is_interface_kind %}
90 // TODO(rockot): Support reading interfaces. ({{name}}() omitted)
91 {%- elif kind|is_interface_request_kind %}
92 // TODO(rockot): Support reading interface requests. ({{name}}() omitted)
93 {%- elif kind|is_associated_kind %}
94 // TODO(rockot): Support reading associated kinds. ({{name}}() omitted)
95 {%- elif kind|is_enum_kind %}
96 {{kind|cpp_result_type}} {{name}}() const {
97 return static_cast<{{kind|cpp_result_type}}>(data_->{{name}});
98 }
99 {%- else %}
100 {{kind|cpp_result_type}} {{name}}() const { return data_->{{name}}; }
101 {%- endif %}
102 {%- endfor %}
103
104 private:
105 internal::{{struct.name}}_Data* data_;
106 mojo::internal::SerializationContext* context_;
107 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698