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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.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 // static 1 // static
2 {{struct.name}}Ptr {{struct.name}}::New() { 2 {{struct.name}}Ptr {{struct.name}}::New() {
3 {{struct.name}}Ptr rv; 3 {{struct.name}}Ptr rv;
4 mojo::internal::StructHelper<{{struct.name}}>::Initialize(&rv); 4 mojo::internal::StructHelper<{{struct.name}}>::Initialize(&rv);
5 return rv; 5 return rv;
6 } 6 }
7 7
8 {{struct.name}}::{{struct.name}}() 8 {{struct.name}}::{{struct.name}}()
9 {%- for field in struct.fields %} 9 {%- for field in struct.fields %}
10 {% if loop.first %}:{% else %} {% endif %} {{field.name}}({{field|default_va lue}}){% if not loop.last %},{% endif %} 10 {% if loop.first %}:{% else %} {% endif %} {{field.name}}({{field|default_va lue}}){% if not loop.last %},{% endif %}
11 {%- endfor %} { 11 {%- endfor %} {
12 } 12 }
13 13
14 {{struct.name}}::~{{struct.name}}() { 14 {{struct.name}}::~{{struct.name}}() {
15 } 15 }
16 16
17 {% if struct|is_cloneable_kind %} 17 {% if struct|is_cloneable_kind %}
18 {{struct.name}}Ptr {{struct.name}}::Clone() const { 18 {{struct.name}}Ptr {{struct.name}}::Clone() const {
19 {{struct.name}}Ptr rv(New()); 19 {{struct.name}}Ptr rv(New());
20 {%- for field in struct.fields %} 20 {%- for field in struct.fields %}
21 {%- if field.kind|is_object_kind and not field.kind|is_string_kind %} 21 {%- if field.kind|is_object_kind and not field.kind|is_string_kind %}
22 rv->{{field.name}} = {{field.name}}.Clone(); 22 rv->{{field.name}} = {{field.name}}.Clone();
23 {%- else %} 23 {%- else %}
24 rv->{{field.name}} = {{field.name}}; 24 rv->{{field.name}} = {{field.name}};
25 {%- endif %} 25 {%- endif %}
26 {%- endfor %} 26 {%- endfor %}
27 return rv; 27 return rv;
28 } 28 }
29 {% endif %} 29 {% endif %}
30
31 {{struct.name}}_Reader::{{struct.name}}_Reader(
32 internal::{{struct.name}}_Data* data,
33 mojo::internal::SerializationContext* context)
34 : data_(data), context_(context) { }
35
36 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
37 {%- set name = pf.field.name -%}
38 {%- set kind = pf.field.kind %}
39 {%- if kind|is_nullable_kind %}
40 bool {{struct.name}}_Reader::has_{{name}}() const {
41 {%- if kind|is_union_kind %}
42 return !data_->{{name}}.is_null();
43 {%- elif kind|is_object_kind %}
44 return data_->{{name}}.ptr != nullptr;
45 {%- elif kind|is_interface_kind %}
46 return data_->{{name}}.handle.is_valid();
47 {%- elif kind|is_interface_request_kind %}
48 return data_->{{name}}.is_valid();
49 {%- elif kind|is_associated_interface_kind %}
50 return data_->{{name}}.interface_id == mojo::internal::kInvalidInterfaceId;
51 {%- elif kind|is_associated_interface_request_kind %}
52 return data_->{{name}} == mojo::internal::kInvalidInterfaceId;
53 {%- elif kind|is_any_handle_kind %}
54 return data_->{{name}}.is_valid();
55 {%- else %}
56 return !!data_->{{name}};
57 {%- endif %}
58 }
59 {%- endif %}
60 {%- if kind|is_struct_kind and not kind|is_native_only_kind %}
61 {{kind|get_name_for_kind}}_Reader {{struct.name}}_Reader::{{name}}() const {
62 return {{kind|get_name_for_kind}}_Reader(data_->{{name}}.ptr, context_);
63 }
64 {%- elif kind|is_string_kind %}
65 base::StringPiece {{struct.name}}_Reader::{{name}}() const {
66 DCHECK(data_->{{name}}.ptr);
67 return base::StringPiece(data_->{{name}}.ptr->storage(),
68 data_->{{name}}.ptr->size());
69 }
70 {%- endif %}
71 {%- endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698