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

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_declaration.tmpl

Issue 2199043002: Mojo C++ bindings: inline struct data view field getters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@84_counter
Patch Set: . Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_definition.tmpl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_declaration.tmpl
index 7ba07147ba79bb3b33b5f00355c8e5b41656a42b..575a331769a8c2078b2490b93b99b9023505d602 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_declaration.tmpl
@@ -4,33 +4,48 @@ class {{struct.name}}DataView {
{{struct.name}}DataView(
internal::{{struct.name}}_Data* data,
- mojo::internal::SerializationContext* context);
+ mojo::internal::SerializationContext* context)
+{%- if struct|requires_context_for_data_view %}
+ : data_(data), context_(context) {}
+{%- else %}
+ : data_(data) {}
+{%- endif %}
bool is_null() const { return !data_; }
{%- for pf in struct.packed.packed_fields_in_ordinal_order %}
{%- set kind = pf.field.kind %}
{%- set name = pf.field.name %}
-{%- if kind|is_object_kind %}
+{%- if kind|is_union_kind %}
void Get{{name|under_to_camel}}DataView(
{{kind|cpp_data_view_type}}* output);
-{%- if kind|is_union_kind %}
- bool Read{{name|under_to_camel}}({{kind|cpp_wrapper_type}}* output);
-
+ bool Read{{name|under_to_camel}}({{kind|cpp_wrapper_type}}* output) {
+{%- if pf.min_version != 0 %}
+ auto pointer = data_->header_.version >= {{pf.min_version}}
+ ? &data_->{{name}} : nullptr;
{%- else %}
+ auto pointer = &data_->{{name}};
+{%- endif %}
+ return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>(
+ pointer, output, context_);
+}
+
+{%- elif kind|is_object_kind %}
+ void Get{{name|under_to_camel}}DataView(
+ {{kind|cpp_data_view_type}}* output);
+
template <typename UserType>
bool Read{{name|under_to_camel}}(UserType* output) {
-{%- if pf.min_version != 0 %}
+{%- if pf.min_version != 0 %}
auto pointer = data_->header_.version >= {{pf.min_version}}
? data_->{{name}}.Get() : nullptr;
-{%- else %}
+{%- else %}
auto pointer = data_->{{name}}.Get();
-{%- endif %}
+{%- endif %}
return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>(
pointer, output, context_);
}
-{%- endif %}
{%- elif kind|is_enum_kind %}
template <typename UserType>
@@ -45,17 +60,43 @@ class {{struct.name}}DataView {
data_value, output);
}
- {{kind|get_qualified_name_for_kind}} {{name}}() const;
+ {{kind|get_qualified_name_for_kind}} {{name}}() const {
+{%- if pf.min_version != 0 %}
+ if (data_->header_.version < {{pf.min_version}})
+ return {{kind|get_qualified_name_for_kind}}{};
+{%- endif %}
+ return static_cast<{{kind|get_qualified_name_for_kind}}>(data_->{{name}});
+ }
{%- elif kind|is_any_handle_or_interface_kind %}
- {{kind|cpp_wrapper_type}} Take{{name|under_to_camel}}();
+ {{kind|cpp_wrapper_type}} Take{{name|under_to_camel}}() {
+ {{kind|cpp_wrapper_type}} result;
+{%- if pf.min_version != 0 %}
+ if (data_->header_.version < {{pf.min_version}})
+ return result;
+{%- endif %}
+ bool ret =
+ mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>(
+ &data_->{{name}}, &result, context_);
+ DCHECK(ret);
+ return result;
+ }
{%- else %}
- {{kind|cpp_wrapper_type}} {{name}}() const;
+ {{kind|cpp_wrapper_type}} {{name}}() const {
+{%- if pf.min_version != 0 %}
+ if (data_->header_.version < {{pf.min_version}})
+ return {{kind|cpp_wrapper_type}}{};
+{%- endif %}
+ return data_->{{name}};
+ }
+
{%- endif %}
{%- endfor %}
private:
internal::{{struct.name}}_Data* data_ = nullptr;
+{%- if struct|requires_context_for_data_view %}
mojo::internal::SerializationContext* context_ = nullptr;
+{%- endif %}
};
« no previous file with comments | « no previous file | mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_definition.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698