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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/union_serialization_declaration.tmpl

Issue 2253293002: Mojo C++ bindings: change the first template parameter of StructTraits and UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@91_extra
Patch Set: rebase Created 4 years, 3 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 {%- set mojom_type = union|get_qualified_name_for_kind %} 1 {%- set mojom_type = union|get_qualified_name_for_kind %}
2 {%- set data_type = union|get_qualified_name_for_kind(internal=True) %} 2 {%- set data_type = union|get_qualified_name_for_kind(internal=True) %}
3 3
4 template <> 4 template <>
5 struct {{export_attribute}} UnionTraits<{{mojom_type}}, {{mojom_type}}Ptr> { 5 struct {{export_attribute}} UnionTraits<{{mojom_type}}::DataView,
6 {{mojom_type}}Ptr> {
6 static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; } 7 static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; }
7 static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); } 8 static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); }
8 9
9 static {{mojom_type}}::Tag GetTag(const {{mojom_type}}Ptr& input) { 10 static {{mojom_type}}::Tag GetTag(const {{mojom_type}}Ptr& input) {
10 return input->which(); 11 return input->which();
11 } 12 }
12 13
13 {%- for field in union.fields %} 14 {%- for field in union.fields %}
14 {%- set return_ref = field.kind|is_object_kind or 15 {%- set return_ref = field.kind|is_object_kind or
15 field.kind|is_any_handle_or_interface_kind %} 16 field.kind|is_any_handle_or_interface_kind %}
16 {%- if return_ref %} 17 {%- if return_ref %}
17 static decltype(std::declval<{{mojom_type}}>().get_{{field.name}}()) 18 static decltype(std::declval<{{mojom_type}}>().get_{{field.name}}())
18 {{field.name}}({{mojom_type}}Ptr& input) { 19 {{field.name}}({{mojom_type}}Ptr& input) {
19 return input->get_{{field.name}}(); 20 return input->get_{{field.name}}();
20 } 21 }
21 {%- else %} 22 {%- else %}
22 static decltype(std::declval<{{mojom_type}}>().get_{{field.name}}()) 23 static decltype(std::declval<{{mojom_type}}>().get_{{field.name}}())
23 {{field.name}}(const {{mojom_type}}Ptr& input) { 24 {{field.name}}(const {{mojom_type}}Ptr& input) {
24 return input->get_{{field.name}}(); 25 return input->get_{{field.name}}();
25 } 26 }
26 {%- endif %} 27 {%- endif %}
27 {%- endfor %} 28 {%- endfor %}
28 29
29 static bool Read({{mojom_type}}DataView input, {{mojom_type}}Ptr* output); 30 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output);
30 }; 31 };
31 32
32 namespace internal { 33 namespace internal {
33 34
34 template <typename MaybeConstUserType> 35 template <typename MaybeConstUserType>
35 struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> { 36 struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> {
36 using UserType = typename std::remove_const<MaybeConstUserType>::type; 37 using UserType = typename std::remove_const<MaybeConstUserType>::type;
37 using Traits = UnionTraits<{{mojom_type}}, UserType>; 38 using Traits = UnionTraits<{{mojom_type}}::DataView, UserType>;
38 39
39 static size_t PrepareToSerialize(MaybeConstUserType& input, 40 static size_t PrepareToSerialize(MaybeConstUserType& input,
40 bool inlined, 41 bool inlined,
41 SerializationContext* context) { 42 SerializationContext* context) {
42 size_t size = inlined ? 0 : sizeof({{data_type}}); 43 size_t size = inlined ? 0 : sizeof({{data_type}});
43 44
44 if (CallIsNullIfExists<Traits>(input)) 45 if (CallIsNullIfExists<Traits>(input))
45 return size; 46 return size;
46 47
47 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context); 48 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 155
155 CustomContextHelper<Traits>::TearDown(input, custom_context); 156 CustomContextHelper<Traits>::TearDown(input, custom_context);
156 } 157 }
157 158
158 static bool Deserialize({{data_type}}* input, 159 static bool Deserialize({{data_type}}* input,
159 UserType* output, 160 UserType* output,
160 SerializationContext* context) { 161 SerializationContext* context) {
161 if (!input || input->is_null()) 162 if (!input || input->is_null())
162 return CallSetToNullIfExists<Traits>(output); 163 return CallSetToNullIfExists<Traits>(output);
163 164
164 {{mojom_type}}DataView data_view(input, context); 165 {{mojom_type}}::DataView data_view(input, context);
165 return Traits::Read(data_view, output); 166 return Traits::Read(data_view, output);
166 } 167 }
167 }; 168 };
168 169
169 } // namespace internal 170 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698