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

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

Issue 1968623002: Mojo C++ bindings: expose public <struct>DataView and StringDataView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@25_totally_new
Patch Set: 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..be7043a4f51a9b842fb8c9ac4f44b98bdc9c7e5f
--- /dev/null
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_declaration.tmpl
@@ -0,0 +1,41 @@
+class {{struct.name}}DataView {
+ public:
+ {{struct.name}}DataView(
+ internal::{{struct.name}}_Data* data,
+ mojo::internal::SerializationContext* context);
+
+ // Whether the data represents a null struct.
+ // Note: Must not access the following methods if is_null() returns true.
+ 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_struct_kind or kind|is_array_kind or kind|is_string_kind %}
+ template <typename UserType>
+ bool Read{{name|under_to_camel}}(UserType* value) {
+ DCHECK(!is_null());
+
+{%- if pf.min_version != 0 %}
+ auto pointer = data_->header_.version >= {{pf.min_version}}
+ ? data_->{{name}}.ptr : nullptr;
+{%- else %}
+ auto pointer = data_->{{name}}.ptr;
+{%- endif %}
+ return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>(
+ pointer, value, context_);
+ }
+{%- elif kind|is_map_kind or kind|is_union_kind %}
+ bool Read{{name|under_to_camel}}({{kind|cpp_wrapper_type}}* value);
+{%- elif kind|is_interface_kind or kind|is_any_handle_kind or
+ kind|is_associated_kind %}
+ {{kind|cpp_wrapper_type}} Take{{name|under_to_camel}}();
+{%- else %}
+ {{kind|cpp_wrapper_type}} {{name}}() const;
+{%- endif %}
+{%- endfor %}
+ private:
+ internal::{{struct.name}}_Data* data_;
+ mojo::internal::SerializationContext* context_;
+};
+

Powered by Google App Engine
This is Rietveld 408576698