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

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

Issue 2259283003: Mojo C++ bindings: share DataView class between chromium and blink variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@92_change_traits_param
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
Index: mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
index 5a5b9d6ea41d64603f2869198b5755cc61fa572f..8e08d6a2d575eefd2bae6fe05d0468d144e1c297 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
@@ -1,37 +1,13 @@
{%- import "struct_macros.tmpl" as struct_macros %}
-{%- set mojom_type = struct|get_qualified_name_for_kind %}
+{%- set data_view = struct|get_qualified_name_for_kind ~ "DataView" %}
{%- set data_type = struct|get_qualified_name_for_kind(internal=True) %}
-template <>
-struct {{export_attribute}} StructTraits<{{mojom_type}}::DataView, {{mojom_type}}Ptr> {
- static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; }
- static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); }
-
-{%- for field in struct.fields %}
-{%- set return_ref = field.kind|is_object_kind or
- field.kind|is_any_handle_or_interface_kind %}
-{%- if return_ref %}
- static decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
- {{mojom_type}}Ptr& input) {
- return input->{{field.name}};
- }
-{%- else %}
- static decltype({{mojom_type}}::{{field.name}}) {{field.name}}(
- const {{mojom_type}}Ptr& input) {
- return input->{{field.name}};
- }
-{%- endif %}
-{%- endfor %}
-
- static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output);
-};
-
namespace internal {
template <typename MaybeConstUserType>
-struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> {
+struct Serializer<{{data_view}}, MaybeConstUserType> {
using UserType = typename std::remove_const<MaybeConstUserType>::type;
- using Traits = StructTraits<{{mojom_type}}::DataView, UserType>;
+ using Traits = StructTraits<{{data_view}}, UserType>;
static size_t PrepareToSerialize(MaybeConstUserType& input,
SerializationContext* context) {
@@ -73,7 +49,7 @@ struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> {
if (!input)
return CallSetToNullIfExists<Traits>(output);
- {{mojom_type}}::DataView data_view(input, context);
+ {{data_view}} data_view(input, context);
return Traits::Read(data_view, output);
}
};

Powered by Google App Engine
This is Rietveld 408576698