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

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

Issue 2247083003: Mojo C++ bindings: extract code shared by different variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
11 {%- set header_guard = "%s_H_"|format( 11 {%- set header_guard = "%s_H_"|format(
12 variant_path|upper|replace("/","_")|replace(".","_")| 12 variant_path|upper|replace("/","_")|replace(".","_")|
13 replace("-", "_")) %} 13 replace("-", "_")) %}
14 14
15 {%- from "enum_macros.tmpl" import enum_decl %}
16 {%- from "enum_macros.tmpl" import enum_stream_operator %}
17 {%- from "enum_macros.tmpl" import is_known_enum_value %}
18 {%- from "enum_macros.tmpl" import enum_hash %}
19
20 {%- macro namespace_begin() %} 15 {%- macro namespace_begin() %}
21 {%- for namespace in namespaces_as_array %} 16 {%- for namespace in namespaces_as_array %}
22 namespace {{namespace}} { 17 namespace {{namespace}} {
23 {%- endfor %} 18 {%- endfor %}
24 {%- if variant %} 19 {%- if variant %}
25 namespace {{variant}} { 20 namespace {{variant}} {
26 {%- endif %} 21 {%- endif %}
27 {%- endmacro %} 22 {%- endmacro %}
28 23
29 {%- macro namespace_end() %} 24 {%- macro namespace_end() %}
(...skipping 14 matching lines...) Expand all
44 }; 39 };
45 } // namespace internal 40 } // namespace internal
46 } // namespace mojo 41 } // namespace mojo
47 {%- endmacro %} 42 {%- endmacro %}
48 43
49 #ifndef {{header_guard}} 44 #ifndef {{header_guard}}
50 #define {{header_guard}} 45 #define {{header_guard}}
51 46
52 #include <stdint.h> 47 #include <stdint.h>
53 48
54 #include <functional>
55 #include <ostream>
56 #include <type_traits> 49 #include <type_traits>
57 #include <utility> 50 #include <utility>
58 51
59 #include "base/callback.h" 52 #include "base/callback.h"
60 #include "base/optional.h" 53 #include "base/optional.h"
61 #include "mojo/public/cpp/bindings/array_data_view.h" 54 #include "mojo/public/cpp/bindings/array_data_view.h"
62 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" 55 #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
63 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 56 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
64 #include "mojo/public/cpp/bindings/associated_interface_request.h" 57 #include "mojo/public/cpp/bindings/associated_interface_request.h"
65 #include "mojo/public/cpp/bindings/interface_ptr.h" 58 #include "mojo/public/cpp/bindings/interface_ptr.h"
66 #include "mojo/public/cpp/bindings/interface_request.h" 59 #include "mojo/public/cpp/bindings/interface_request.h"
67 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" 60 #include "mojo/public/cpp/bindings/lib/control_message_handler.h"
68 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" 61 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
69 #include "mojo/public/cpp/bindings/lib/serialization.h" 62 #include "mojo/public/cpp/bindings/lib/serialization.h"
63 #include "mojo/public/cpp/bindings/lib/union_accessor.h"
70 #include "mojo/public/cpp/bindings/map.h" 64 #include "mojo/public/cpp/bindings/map.h"
71 #include "mojo/public/cpp/bindings/map_data_view.h" 65 #include "mojo/public/cpp/bindings/map_data_view.h"
72 #include "mojo/public/cpp/bindings/message_filter.h" 66 #include "mojo/public/cpp/bindings/message_filter.h"
73 #include "mojo/public/cpp/bindings/native_enum.h"
74 #include "mojo/public/cpp/bindings/native_struct.h" 67 #include "mojo/public/cpp/bindings/native_struct.h"
75 #include "mojo/public/cpp/bindings/native_struct_data_view.h" 68 #include "mojo/public/cpp/bindings/native_struct_data_view.h"
76 #include "mojo/public/cpp/bindings/no_interface.h" 69 #include "mojo/public/cpp/bindings/no_interface.h"
77 #include "mojo/public/cpp/bindings/string_data_view.h" 70 #include "mojo/public/cpp/bindings/string_data_view.h"
78 #include "mojo/public/cpp/bindings/struct_ptr.h" 71 #include "mojo/public/cpp/bindings/struct_ptr.h"
79 #include "mojo/public/cpp/bindings/struct_traits.h" 72 #include "mojo/public/cpp/bindings/struct_traits.h"
80 #include "mojo/public/cpp/bindings/union_traits.h" 73 #include "mojo/public/cpp/bindings/union_traits.h"
81 #include "{{variant_path}}-internal.h" 74 #include "{{module.path}}-shared.h"
82 {%- for import in imports %} 75 {%- for import in imports %}
83 {%- if variant %} 76 {%- if variant %}
84 #include "{{"%s-%s.h"|format(import.module.path, variant)}}" 77 #include "{{"%s-%s.h"|format(import.module.path, variant)}}"
85 {%- else %} 78 {%- else %}
86 #include "{{import.module.path}}.h" 79 #include "{{import.module.path}}.h"
87 {%- endif %} 80 {%- endif %}
88 {%- endfor %} 81 {%- endfor %}
89 {%- if not for_blink %} 82 {%- if not for_blink %}
90 #include "mojo/public/cpp/bindings/array.h" 83 #include "mojo/public/cpp/bindings/array.h"
91 #include "mojo/public/cpp/bindings/string.h" 84 #include "mojo/public/cpp/bindings/string.h"
92 {%- else %} 85 {%- else %}
93 #include "mojo/public/cpp/bindings/wtf_array.h" 86 #include "mojo/public/cpp/bindings/wtf_array.h"
94 #include "mojo/public/cpp/bindings/wtf_map.h" 87 #include "mojo/public/cpp/bindings/wtf_map.h"
95 #include "third_party/WebKit/Source/wtf/Optional.h" 88 #include "third_party/WebKit/Source/wtf/Optional.h"
96 #include "third_party/WebKit/Source/wtf/text/WTFString.h" 89 #include "third_party/WebKit/Source/wtf/text/WTFString.h"
97 {%- endif %} 90 {%- endif %}
98 91
99 {%- for header in extra_public_headers %} 92 {%- for header in extra_public_headers %}
100 #include "{{header}}" 93 #include "{{header}}"
101 {%- endfor %} 94 {%- endfor %}
102 95
103 {%- if export_header %} 96 {%- if export_header %}
104 #include "{{export_header}}" 97 #include "{{export_header}}"
105 {%- endif %} 98 {%- endif %}
106 99
107 {#--- Enums #}
108 {%- if enums %}
109 {{namespace_begin()}}
110 {%- for enum in enums %}
111 {%- if enum|is_native_only_kind %}
112 using {{enum.name}} = mojo::NativeEnum;
113 {%- else %}
114 {{enum_decl(enum)}}
115 {{enum_stream_operator(enum)}}
116 {{is_known_enum_value(enum)}}
117 {%- endif %}
118 {%- endfor %}
119 {{namespace_end()}}
120
121 namespace std {
122
123 {%- for enum in enums %}
124 {%- if not enum|is_native_only_kind %}
125 {{enum_hash(enum)}}
126 {%- endif %}
127 {%- endfor %}
128
129 } // namespace std
130 {%- endif %}
131
132 {{namespace_begin()}} 100 {{namespace_begin()}}
133 101
102 {#--- Enums #}
103 {%- if variant %}
104 {%- for enum in enums %}
105 using {{enum.name}} = {{enum.name}}; // Alias for definition in the parent name space.
106 {%- endfor %}
107 {%- endif %}
108
109
134 {#--- Constants #} 110 {#--- Constants #}
135 {%- for constant in module.constants %} 111 {%- for constant in module.constants %}
136 {#- To be consistent with constants defined inside interfaces, only make 112 {#- To be consistent with constants defined inside interfaces, only make
137 integral types compile-time constants. #} 113 integral types compile-time constants. #}
138 {%- if constant.kind|is_integral_kind %} 114 {%- if constant.kind|is_integral_kind %}
139 const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_val ue}}; 115 const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|constant_val ue}};
140 {%- else %} 116 {%- else %}
141 extern const {{constant.kind|cpp_pod_type}} {{constant.name}}; 117 extern const {{constant.kind|cpp_pod_type}} {{constant.name}};
142 {%- endif %} 118 {%- endif %}
143 {%- endfor %} 119 {%- endfor %}
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 {% if union|should_inline_union %} 156 {% if union|should_inline_union %}
181 typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr; 157 typedef mojo::InlinedStructPtr<{{union.name}}> {{union.name}}Ptr;
182 {% else %} 158 {% else %}
183 typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr; 159 typedef mojo::StructPtr<{{union.name}}> {{union.name}}Ptr;
184 {% endif %} 160 {% endif %}
185 {%- endfor %} 161 {%- endfor %}
186 162
187 {#--- Interfaces -#} 163 {#--- Interfaces -#}
188 {% for interface in interfaces %} 164 {% for interface in interfaces %}
189 {% include "interface_declaration.tmpl" %} 165 {% include "interface_declaration.tmpl" %}
190
191 {%- if interface.enums %}
192 {{namespace_end()}}
193 namespace std {
194
195 {%- for enum in interface.enums %}
196 {%- if not enum|is_native_only_kind %}
197 {{enum_hash(enum)}}
198 {%- endif %}
199 {%- endfor %}
200
201 } // namespace std
202 {{namespace_begin()}}
203 {%- endif %}
204
205 {%- for enum in interface.enums %}
206 {%- if not enum|is_native_only_kind %}
207 {{enum_stream_operator(enum)}}
208 {{is_known_enum_value(enum)}}
209 {%- endif %}
210 {%- endfor %}
211 {%- endfor %} 166 {%- endfor %}
212 167
213 {#--- Interface Proxies -#} 168 {#--- Interface Proxies -#}
214 {% for interface in interfaces %} 169 {% for interface in interfaces %}
215 {% include "interface_proxy_declaration.tmpl" %} 170 {% include "interface_proxy_declaration.tmpl" %}
216 {%- endfor %} 171 {%- endfor %}
217 172
218 {#--- Interface Stubs -#} 173 {#--- Interface Stubs -#}
219 {% for interface in interfaces %} 174 {% for interface in interfaces %}
220 {% include "interface_stub_declaration.tmpl" %} 175 {% include "interface_stub_declaration.tmpl" %}
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 {%- for union in unions %} 230 {%- for union in unions %}
276 {% include "wrapper_union_class_template_definition.tmpl" %} 231 {% include "wrapper_union_class_template_definition.tmpl" %}
277 {% include "union_data_view_definition.tmpl" %} 232 {% include "union_data_view_definition.tmpl" %}
278 {%- endfor %} 233 {%- endfor %}
279 234
280 {%- for struct in structs %} 235 {%- for struct in structs %}
281 {%- if not struct|is_native_only_kind %} 236 {%- if not struct|is_native_only_kind %}
282 {% include "wrapper_class_template_definition.tmpl" %} 237 {% include "wrapper_class_template_definition.tmpl" %}
283 {% include "struct_data_view_definition.tmpl" %} 238 {% include "struct_data_view_definition.tmpl" %}
284 {%- endif %} 239 {%- endif %}
285
286 {%- if struct.enums %}
287 {{namespace_end()}}
288 namespace std {
289
290 {%- for enum in struct.enums %}
291 {%- if not enum|is_native_only_kind %}
292 {{enum_hash(enum)}}
293 {%- endif %}
294 {%- endfor %}
295
296 } // namespace std
297 {{namespace_begin()}}
298 {%- endif %}
299
300 {%- for enum in struct.enums %}
301 {%- if not enum|is_native_only_kind %}
302 {{enum_stream_operator(enum)}}
303 {{is_known_enum_value(enum)}}
304 {%- endif %}
305 {%- endfor %}
306 {%- endfor %} 240 {%- endfor %}
307 241
308 {{namespace_end()}} 242 {{namespace_end()}}
309 243
310 namespace mojo { 244 namespace mojo {
311 245
312 {#--- Enum Serialization Helpers -#}
313 {%- for enum in enums %}
314 {%- if not enum|is_native_only_kind %}
315 {% include "enum_serialization_declaration.tmpl" %}
316 {%- endif %}
317 {%- endfor %}
318
319 {%- for struct in structs %}
320 {%- for enum in struct.enums %}
321 {%- if not enum|is_native_only_kind %}
322 {% include "enum_serialization_declaration.tmpl" %}
323 {%- endif %}
324 {%- endfor %}
325 {%- endfor %}
326
327 {%- for interface in interfaces %}
328 {%- for enum in interface.enums %}
329 {%- if not enum|is_native_only_kind %}
330 {% include "enum_serialization_declaration.tmpl" %}
331 {%- endif %}
332 {%- endfor %}
333 {%- endfor %}
334
335 {#--- Struct Serialization Helpers -#} 246 {#--- Struct Serialization Helpers -#}
336 {% for struct in structs %} 247 {% for struct in structs %}
337 {%- if not struct|is_native_only_kind %} 248 {%- if not struct|is_native_only_kind %}
338 {% include "struct_serialization_declaration.tmpl" %} 249 {% include "struct_serialization_declaration.tmpl" %}
339 {%- endif %} 250 {%- endif %}
340 {%- endfor %} 251 {%- endfor %}
341 252
342 {#--- Union Serialization Helpers -#} 253 {#--- Union Serialization Helpers -#}
343 {% if unions %} 254 {% if unions %}
344 {%- for union in unions %} 255 {%- for union in unions %}
345 {% include "union_serialization_declaration.tmpl" %} 256 {% include "union_serialization_declaration.tmpl" %}
346 {%- endfor %} 257 {%- endfor %}
347 {%- endif %} 258 {%- endif %}
348 259
349 } // namespace mojo 260 } // namespace mojo
350 261
351 #endif // {{header_guard}} 262 #endif // {{header_guard}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698