Index: mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_definition.tmpl |
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_definition.tmpl |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ecea7e9ad9da7dfb6f020cb6179cb8a037921edf |
--- /dev/null |
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_data_view_definition.tmpl |
@@ -0,0 +1,120 @@ |
+{{struct.name}}DataView::{{struct.name}}DataView( |
+ internal::{{struct.name}}_Data* data, |
+ mojo::internal::SerializationContext* context) |
+ : data_(data), context_(context) {} |
+ |
+{%- 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 %} |
+{#- Does nothing. They are already defined in the class declaration. #} |
+{%- elif kind|is_map_kind %} |
+bool {{struct.name}}DataView::Read{{name|under_to_camel}}( |
+ {{kind|cpp_wrapper_type}}* 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_union_kind %} |
+bool {{struct.name}}DataView::Read{{name|under_to_camel}}( |
+ {{kind|cpp_wrapper_type}}* value) { |
+ DCHECK(!is_null()); |
+{%- 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, value, context_); |
+} |
+ |
+{%- elif kind|is_interface_kind %} |
+{{kind|cpp_wrapper_type}} {{struct.name}}DataView::Take{{name|under_to_camel}}() { |
+ DCHECK(!is_null()); |
+ |
+ {{kind|cpp_wrapper_type}} result; |
+{%- if pf.min_version != 0 %} |
+ if (data_->header_.version < {{pf.min_version}}) |
+ return result; |
+{%- endif %} |
+ mojo::internal::InterfaceDataToPointer(&data_->{{name}}, &result, context_); |
+ return result; |
+} |
+ |
+{%- elif kind|is_interface_request_kind %} |
+{{kind|cpp_wrapper_type}} {{struct.name}}DataView::Take{{name|under_to_camel}}() { |
+ DCHECK(!is_null()); |
+ |
+ {{kind|cpp_wrapper_type}} result; |
+{%- if pf.min_version != 0 %} |
+ if (data_->header_.version < {{pf.min_version}}) |
+ return result; |
+{%- endif %} |
+ result.Bind(context_->handles.TakeHandleAs<mojo::MessagePipeHandle>( |
+ data_->{{name}})); |
+ return result; |
+} |
+ |
+{%- elif kind|is_any_handle_kind %} |
+{{kind|cpp_wrapper_type}} {{struct.name}}DataView::Take{{name|under_to_camel}}() { |
+ DCHECK(!is_null()); |
+ |
+{%- if pf.min_version != 0 %} |
+ if (data_->header_.version < {{pf.min_version}}) |
+ return {{kind|cpp_wrapper_type}}(); |
+{%- endif %} |
+ |
+ return context_->handles.TakeHandleAs< |
+ {{kind|cpp_wrapper_type}}::RawHandleType>(data_->{{name}}); |
+} |
+ |
+{%- elif kind|is_associated_interface_kind %} |
+{{kind|cpp_wrapper_type}} {{struct.name}}DataView::Take{{name|under_to_camel}}() { |
+ DCHECK(!is_null()); |
+ |
+ {{kind|cpp_wrapper_type}} result; |
+{%- if pf.min_version != 0 %} |
+ if (data_->header_.version < {{pf.min_version}}) |
+ return result; |
+{%- endif %} |
+ mojo::internal::AssociatedInterfaceDataToPtrInfo(&data_->{{name}}, &result, |
+ context_->router.get()); |
+ return result; |
+} |
+ |
+{%- elif kind|is_associated_interface_request_kind %} |
+{{kind|cpp_wrapper_type}} {{struct.name}}DataView::Take{{name|under_to_camel}}() { |
+ DCHECK(!is_null()); |
+ |
+ {{kind|cpp_wrapper_type}} result; |
+{%- if pf.min_version != 0 %} |
+ if (data_->header_.version < {{pf.min_version}}) |
+ return result; |
+{%- endif %} |
+ mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( |
+ &result, |
+ context_->router->CreateLocalEndpointHandle( |
+ mojo::internal::FetchAndReset(&data_->{{name}}))); |
+ return result; |
+} |
+ |
+{%- else %} |
+{{kind|cpp_wrapper_type}} {{struct.name}}DataView::{{name}}() const { |
+ DCHECK(!is_null()); |
+{%- if pf.min_version != 0 %} |
+ if (data_->header_.version < {{pf.min_version}}) |
+ return {{kind|cpp_wrapper_type}}{}; |
+{%- endif %} |
+ return static_cast<{{kind|cpp_wrapper_type}}>(data_->{{name}}); |
+} |
+{%- endif %} |
+{%- endfor %} |
+ |