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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/module.h.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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 {%- if variant -%} 5 {%- if variant -%}
6 {%- set variant_path = "%s-%s"|format(module.path, variant) -%} 6 {%- set variant_path = "%s-%s"|format(module.path, variant) -%}
7 {%- else -%} 7 {%- else -%}
8 {%- set variant_path = module.path -%} 8 {%- set variant_path = module.path -%}
9 {%- endif -%} 9 {%- endif -%}
10 10
(...skipping 12 matching lines...) Expand all
23 23
24 {%- macro namespace_end() %} 24 {%- macro namespace_end() %}
25 {%- if variant %} 25 {%- if variant %}
26 } // namespace {{variant}} 26 } // namespace {{variant}}
27 {%- endif %} 27 {%- endif %}
28 {%- for namespace in namespaces_as_array|reverse %} 28 {%- for namespace in namespaces_as_array|reverse %}
29 } // namespace {{namespace}} 29 } // namespace {{namespace}}
30 {%- endfor %} 30 {%- endfor %}
31 {%- endmacro %} 31 {%- endmacro %}
32 32
33 {%- macro data_view_traits(kind) %}
34 namespace mojo {
35 namespace internal {
36 template <>
37 struct DataViewTraits<{{kind|get_qualified_name_for_kind}}DataView> {
38 using MojomType = {{kind|get_qualified_name_for_kind}}Ptr;
39 };
40 } // namespace internal
41 } // namespace mojo
42 {%- endmacro %}
43
44 #ifndef {{header_guard}} 33 #ifndef {{header_guard}}
45 #define {{header_guard}} 34 #define {{header_guard}}
46 35
47 #include <stdint.h> 36 #include <stdint.h>
48 37
49 #include <type_traits> 38 #include <type_traits>
50 #include <utility> 39 #include <utility>
51 40
52 #include "base/callback.h" 41 #include "base/callback.h"
53 #include "base/optional.h" 42 #include "base/optional.h"
54 #include "mojo/public/cpp/bindings/array_data_view.h"
55 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" 43 #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
56 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 44 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
57 #include "mojo/public/cpp/bindings/associated_interface_request.h" 45 #include "mojo/public/cpp/bindings/associated_interface_request.h"
58 #include "mojo/public/cpp/bindings/interface_ptr.h" 46 #include "mojo/public/cpp/bindings/interface_ptr.h"
59 #include "mojo/public/cpp/bindings/interface_request.h" 47 #include "mojo/public/cpp/bindings/interface_request.h"
60 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" 48 #include "mojo/public/cpp/bindings/lib/control_message_handler.h"
61 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" 49 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
62 #include "mojo/public/cpp/bindings/lib/serialization.h" 50 #include "mojo/public/cpp/bindings/lib/serialization.h"
63 #include "mojo/public/cpp/bindings/lib/union_accessor.h" 51 #include "mojo/public/cpp/bindings/lib/union_accessor.h"
64 #include "mojo/public/cpp/bindings/map.h" 52 #include "mojo/public/cpp/bindings/map.h"
65 #include "mojo/public/cpp/bindings/map_data_view.h"
66 #include "mojo/public/cpp/bindings/message_filter.h" 53 #include "mojo/public/cpp/bindings/message_filter.h"
67 #include "mojo/public/cpp/bindings/native_struct.h" 54 #include "mojo/public/cpp/bindings/native_struct.h"
68 #include "mojo/public/cpp/bindings/native_struct_data_view.h"
69 #include "mojo/public/cpp/bindings/no_interface.h" 55 #include "mojo/public/cpp/bindings/no_interface.h"
70 #include "mojo/public/cpp/bindings/string_data_view.h"
71 #include "mojo/public/cpp/bindings/struct_ptr.h" 56 #include "mojo/public/cpp/bindings/struct_ptr.h"
72 #include "mojo/public/cpp/bindings/struct_traits.h" 57 #include "mojo/public/cpp/bindings/struct_traits.h"
73 #include "mojo/public/cpp/bindings/union_traits.h" 58 #include "mojo/public/cpp/bindings/union_traits.h"
74 #include "{{module.path}}-shared.h" 59 #include "{{module.path}}-shared.h"
75 {%- for import in imports %} 60 {%- for import in imports %}
76 {%- if variant %} 61 {%- if variant %}
77 #include "{{"%s-%s.h"|format(import.module.path, variant)}}" 62 #include "{{"%s-%s.h"|format(import.module.path, variant)}}"
78 {%- else %} 63 {%- else %}
79 #include "{{import.module.path}}.h" 64 #include "{{import.module.path}}.h"
80 {%- endif %} 65 {%- endif %}
(...skipping 18 matching lines...) Expand all
99 84
100 {{namespace_begin()}} 85 {{namespace_begin()}}
101 86
102 {#--- Enums #} 87 {#--- Enums #}
103 {%- if variant %} 88 {%- if variant %}
104 {%- for enum in enums %} 89 {%- for enum in enums %}
105 using {{enum.name}} = {{enum.name}}; // Alias for definition in the parent name space. 90 using {{enum.name}} = {{enum.name}}; // Alias for definition in the parent name space.
106 {%- endfor %} 91 {%- endfor %}
107 {%- endif %} 92 {%- endif %}
108 93
109
110 {#--- Constants #} 94 {#--- Constants #}
111 {%- for constant in module.constants %} 95 {%- for constant in module.constants %}
112 {#- To be consistent with constants defined inside interfaces, only make 96 {#- To be consistent with constants defined inside interfaces, only make
113 integral types compile-time constants. #} 97 integral types compile-time constants. #}
114 {%- if constant.kind|is_integral_kind %} 98 {%- if constant.kind|is_integral_kind %}
115 const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_val ue}}; 99 const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_val ue}};
116 {%- else %} 100 {%- else %}
117 extern const {{constant.kind|cpp_pod_type}} {{constant.name}}; 101 extern const {{constant.kind|cpp_pod_type}} {{constant.name}};
118 {%- endif %} 102 {%- endif %}
119 {%- endfor %} 103 {%- endfor %}
120 104
121 {#--- Interface Forward Declarations -#} 105 {#--- Interface Forward Declarations -#}
122 {% for interface in interfaces %} 106 {% for interface in interfaces %}
123 class {{interface.name}}; 107 class {{interface.name}};
124 using {{interface.name}}Ptr = mojo::InterfacePtr<{{interface.name}}>; 108 using {{interface.name}}Ptr = mojo::InterfacePtr<{{interface.name}}>;
125 using {{interface.name}}PtrInfo = mojo::InterfacePtrInfo<{{interface.name}}>; 109 using {{interface.name}}PtrInfo = mojo::InterfacePtrInfo<{{interface.name}}>;
126 using {{interface.name}}Request = mojo::InterfaceRequest<{{interface.name}}>; 110 using {{interface.name}}Request = mojo::InterfaceRequest<{{interface.name}}>;
127 using {{interface.name}}AssociatedPtr = 111 using {{interface.name}}AssociatedPtr =
128 mojo::AssociatedInterfacePtr<{{interface.name}}>; 112 mojo::AssociatedInterfacePtr<{{interface.name}}>;
129 using {{interface.name}}AssociatedPtrInfo = 113 using {{interface.name}}AssociatedPtrInfo =
130 mojo::AssociatedInterfacePtrInfo<{{interface.name}}>; 114 mojo::AssociatedInterfacePtrInfo<{{interface.name}}>;
131 using {{interface.name}}AssociatedRequest = 115 using {{interface.name}}AssociatedRequest =
132 mojo::AssociatedInterfaceRequest<{{interface.name}}>; 116 mojo::AssociatedInterfaceRequest<{{interface.name}}>;
133 {% endfor %} 117 {% endfor %}
134 118
135 {#--- Struct Forward Declarations -#} 119 {#--- Struct Forward Declarations -#}
136 {% for struct in structs %} 120 {% for struct in structs %}
137 {%- if struct|is_native_only_kind %} 121 {%- if struct|is_native_only_kind %}
138 using {{struct.name}} = mojo::NativeStruct; 122 using {{struct.name}} = mojo::NativeStruct;
139 using {{struct.name}}DataView = mojo::NativeStructDataView;
140 using {{struct.name}}Ptr = mojo::NativeStructPtr; 123 using {{struct.name}}Ptr = mojo::NativeStructPtr;
141 {%- else %} 124 {%- else %}
142 class {{struct.name}}; 125 class {{struct.name}};
143 class {{struct.name}}DataView;
144 {%- if struct|should_inline %} 126 {%- if struct|should_inline %}
145 using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>; 127 using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>;
146 {%- else %} 128 {%- else %}
147 using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>; 129 using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>;
148 {%- endif %} 130 {%- endif %}
149 {%- endif %} 131 {%- endif %}
150 {% endfor %} 132 {% endfor %}
151 133
152 {#--- Union Forward Declarations -#} 134 {#--- Union Forward Declarations -#}
153 {% for union in unions %} 135 {% for union in unions %}
154 class {{union.name}}; 136 class {{union.name}};
155 class {{union.name}}DataView;
156 {% if union|should_inline_union %} 137 {% if union|should_inline_union %}
157 typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr; 138 typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr;
158 {% else %} 139 {% else %}
159 typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr; 140 typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr;
160 {% endif %} 141 {% endif %}
161 {%- endfor %} 142 {%- endfor %}
162 143
163 {#--- Interfaces -#} 144 {#--- Interfaces -#}
164 {% for interface in interfaces %} 145 {% for interface in interfaces %}
165 {% include "interface_declaration.tmpl" %} 146 {% include "interface_declaration.tmpl" %}
(...skipping 19 matching lines...) Expand all
185 {% include "interface_response_validator_declaration.tmpl" %} 166 {% include "interface_response_validator_declaration.tmpl" %}
186 {%- endfor %} 167 {%- endfor %}
187 168
188 {#--- NOTE: Unions and non-inlined structs may have pointers to inlined structs, 169 {#--- NOTE: Unions and non-inlined structs may have pointers to inlined structs,
189 so we need to fully define inlined structs ahead of the others. #} 170 so we need to fully define inlined structs ahead of the others. #}
190 171
191 {#--- Inlined structs #} 172 {#--- Inlined structs #}
192 {% for struct in structs %} 173 {% for struct in structs %}
193 {% if struct|should_inline and not struct|is_native_only_kind %} 174 {% if struct|should_inline and not struct|is_native_only_kind %}
194 {% include "wrapper_class_declaration.tmpl" %} 175 {% include "wrapper_class_declaration.tmpl" %}
195 {% include "struct_data_view_declaration.tmpl" %}
196
197 {{namespace_end()}}
198 {{data_view_traits(struct)}}
199 {{namespace_begin()}}
200
201 {% endif %} 176 {% endif %}
202 {%- endfor %} 177 {%- endfor %}
203 178
204 {#--- Unions must be declared before non-inlined structs because they can be 179 {#--- Unions must be declared before non-inlined structs because they can be
205 members of structs. #} 180 members of structs. #}
206 {#--- Unions #} 181 {#--- Unions #}
207 {% for union in unions %} 182 {% for union in unions %}
208 {% include "wrapper_union_class_declaration.tmpl" %} 183 {% include "wrapper_union_class_declaration.tmpl" %}
209 {% include "union_data_view_declaration.tmpl" %}
210
211 {{namespace_end()}}
212 {{data_view_traits(union)}}
213 {{namespace_begin()}}
214
215 {%- endfor %} 184 {%- endfor %}
216 185
217 {#--- Non-inlined structs #} 186 {#--- Non-inlined structs #}
218 {% for struct in structs %} 187 {% for struct in structs %}
219 {% if not struct|should_inline and not struct|is_native_only_kind %} 188 {% if not struct|should_inline and not struct|is_native_only_kind %}
220 {% include "wrapper_class_declaration.tmpl" %} 189 {% include "wrapper_class_declaration.tmpl" %}
221 {% include "struct_data_view_declaration.tmpl" %}
222
223 {{namespace_end()}}
224 {{data_view_traits(struct)}}
225 {{namespace_begin()}}
226
227 {% endif %} 190 {% endif %}
228 {%- endfor %} 191 {%- endfor %}
229 192
230 {%- for union in unions %} 193 {%- for union in unions %}
231 {% include "wrapper_union_class_template_definition.tmpl" %} 194 {% include "wrapper_union_class_template_definition.tmpl" %}
232 {% include "union_data_view_definition.tmpl" %}
233 {%- endfor %} 195 {%- endfor %}
234 196
235 {%- for struct in structs %} 197 {%- for struct in structs %}
236 {%- if not struct|is_native_only_kind %} 198 {%- if not struct|is_native_only_kind %}
237 {% include "wrapper_class_template_definition.tmpl" %} 199 {% include "wrapper_class_template_definition.tmpl" %}
238 {% include "struct_data_view_definition.tmpl" %}
239 {%- endif %} 200 {%- endif %}
240 {%- endfor %} 201 {%- endfor %}
241 202
242 {{namespace_end()}} 203 {{namespace_end()}}
243 204
244 namespace mojo { 205 namespace mojo {
245 206
246 {#--- Struct Serialization Helpers -#} 207 {#--- Struct Serialization Helpers -#}
247 {% for struct in structs %} 208 {% for struct in structs %}
248 {%- if not struct|is_native_only_kind %} 209 {%- if not struct|is_native_only_kind %}
249 {% include "struct_serialization_declaration.tmpl" %} 210 {% include "struct_traits_declaration.tmpl" %}
250 {%- endif %} 211 {%- endif %}
251 {%- endfor %} 212 {%- endfor %}
252 213
253 {#--- Union Serialization Helpers -#} 214 {#--- Union Serialization Helpers -#}
254 {% if unions %} 215 {% if unions %}
255 {%- for union in unions %} 216 {%- for union in unions %}
256 {% include "union_serialization_declaration.tmpl" %} 217 {% include "union_traits_declaration.tmpl" %}
257 {%- endfor %} 218 {%- endfor %}
258 {%- endif %} 219 {%- endif %}
259 220
260 } // namespace mojo 221 } // namespace mojo
261 222
262 #endif // {{header_guard}} 223 #endif // {{header_guard}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698