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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/module-shared.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 {%- set header_guard = "%s_SHARED_H_"|format( 5 {%- set header_guard = "%s_SHARED_H_"|format(
6 module.path|upper|replace("/","_")|replace(".","_")| 6 module.path|upper|replace("/","_")|replace(".","_")|
7 replace("-", "_")) %} 7 replace("-", "_")) %}
8 8
9 {%- macro mojom_type_traits(kind) %}
10 template <>
11 struct MojomTypeTraits<{{kind|get_qualified_name_for_kind}}DataView> {
12 using Data = {{kind|get_qualified_name_for_kind(internal=True)}};
13 {%- if kind|is_union_kind %}
14 using DataAsArrayElement = Data;
15 static const MojomTypeCategory category = MojomTypeCategory::UNION;
16 {%- else %}
17 using DataAsArrayElement = Pointer<Data>;
18 static const MojomTypeCategory category = MojomTypeCategory::STRUCT;
19 {%- endif %}
20 };
21 {%- endmacro %}
22
23 {%- macro namespace_begin() %}
24 {%- for namespace in namespaces_as_array %}
25 namespace {{namespace}} {
26 {%- endfor %}
27 {%- endmacro %}
28
29 {%- macro namespace_end() %}
30 {%- for namespace in namespaces_as_array|reverse %}
31 } // namespace {{namespace}}
32 {%- endfor %}
33 {%- endmacro %}
34
9 #ifndef {{header_guard}} 35 #ifndef {{header_guard}}
10 #define {{header_guard}} 36 #define {{header_guard}}
11 37
12 #include <stdint.h> 38 #include <stdint.h>
13 39
14 #include <functional> 40 #include <functional>
15 #include <ostream> 41 #include <ostream>
16 #include <type_traits> 42 #include <type_traits>
17 #include <utility> 43 #include <utility>
18 44
45 #include "mojo/public/cpp/bindings/array_data_view.h"
19 #include "mojo/public/cpp/bindings/enum_traits.h" 46 #include "mojo/public/cpp/bindings/enum_traits.h"
20 #include "mojo/public/cpp/bindings/lib/serialization_forward.h" 47 #include "mojo/public/cpp/bindings/interface_data_view.h"
48 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
49 #include "mojo/public/cpp/bindings/lib/serialization.h"
50 #include "mojo/public/cpp/bindings/map_data_view.h"
21 #include "mojo/public/cpp/bindings/native_enum.h" 51 #include "mojo/public/cpp/bindings/native_enum.h"
52 #include "mojo/public/cpp/bindings/native_struct_data_view.h"
53 #include "mojo/public/cpp/bindings/string_data_view.h"
22 #include "{{module.path}}-shared-internal.h" 54 #include "{{module.path}}-shared-internal.h"
23 {%- for import in imports %} 55 {%- for import in imports %}
24 #include "{{import.module.path}}-shared.h" 56 #include "{{import.module.path}}-shared.h"
25 {%- endfor %} 57 {%- endfor %}
26 58
27 {%- for namespace in namespaces_as_array %} 59 {{namespace_begin()}}
28 namespace {{namespace}} { 60
29 {%- endfor %} 61 {#--- Struct Forward Declarations -#}
62 {%- for struct in structs %}
63 {%- if struct|is_native_only_kind %}
64 using {{struct.name}}DataView = mojo::NativeStructDataView;
65 {%- else %}
66 class {{struct.name}}DataView;
67 {%- endif %}
68 {% endfor %}
69
70 {#--- Union Forward Declarations -#}
71 {%- for union in unions %}
72 class {{union.name}}DataView;
73 {%- endfor %}
74
75 {{namespace_end()}}
76
77 namespace mojo {
78 namespace internal {
79
80 {%- for struct in structs %}
81 {%- if not struct|is_native_only_kind %}
82 {{mojom_type_traits(struct)}}
83 {%- endif %}
84 {%- endfor %}
85
86 {%- for union in unions %}
87 {{mojom_type_traits(union)}}
88 {%- endfor %}
89
90 } // namespace internal
91 } // namespace mojo
92
93 {{namespace_begin()}}
30 94
31 {#--- Enums #} 95 {#--- Enums #}
32 {%- from "enum_macros.tmpl" import enum_decl%} 96 {%- from "enum_macros.tmpl" import enum_decl%}
33 {%- for enum in all_enums %} 97 {%- for enum in all_enums %}
34 {%- if enum|is_native_only_kind %} 98 {%- if enum|is_native_only_kind %}
35 using {{enum.name}} = mojo::NativeEnum; 99 using {{enum.name}} = mojo::NativeEnum;
36 {%- else %} 100 {%- else %}
37 {{enum_decl(enum)}} 101 {{enum_decl(enum)}}
38 {%- endif %} 102 {%- endif %}
39 {%- endfor %} 103 {%- endfor %}
40 104
41 {%- for namespace in namespaces_as_array|reverse %} 105 {#--- Interfaces #}
42 } // namespace {{namespace}} 106 {%- if interfaces %}
107 // Interface base classes. They are used for type safety check.
108 {%- endif %}
109 {%- for interface in interfaces %}
110 class {{interface.name}}InterfaceBase {};
111
112 using {{interface.name}}PtrDataView =
113 mojo::InterfacePtrDataView<{{interface.name}}InterfaceBase>;
114 using {{interface.name}}RequestDataView =
115 mojo::InterfaceRequestDataView<{{interface.name}}InterfaceBase>;
116 using {{interface.name}}AssociatedPtrInfoDataView =
117 mojo::AssociatedInterfacePtrInfoDataView<{{interface.name}}InterfaceBase>;
118 using {{interface.name}}AssociatedRequestDataView =
119 mojo::AssociatedInterfaceRequestDataView<{{interface.name}}InterfaceBase>;
120
121 {%- endfor %}
122
123 {#--- Structs #}
124 {%- for struct in structs %}
125 {%- if not struct|is_native_only_kind %}
126 {% include "struct_data_view_declaration.tmpl" %}
127 {%- endif %}
128 {%- endfor %}
129
130 {#--- Interface parameter definitions #}
131 {%- for interface in interfaces %}
132 {%- for method in interface.methods %}
133 {%- set struct = method.param_struct %}
134 {% include "struct_data_view_declaration.tmpl" %}
135 {%- if method.response_parameters != None %}
136 {%- set struct = method.response_param_struct %}
137 {% include "struct_data_view_declaration.tmpl" %}
138 {%- endif %}
43 {%- endfor %} 139 {%- endfor %}
140 {%- endfor %}
141
142 {#--- Unions #}
143 {%- for union in unions %}
144 {% include "union_data_view_declaration.tmpl" %}
145 {%- endfor %}
146
147 {{namespace_end()}}
44 148
45 namespace std { 149 namespace std {
46 150
47 {%- from "enum_macros.tmpl" import enum_hash %} 151 {%- from "enum_macros.tmpl" import enum_hash %}
48 {%- for enum in all_enums %} 152 {%- for enum in all_enums %}
49 {%- if not enum|is_native_only_kind %} 153 {%- if not enum|is_native_only_kind %}
50 {{enum_hash(enum)}} 154 {{enum_hash(enum)}}
51 {%- endif %} 155 {%- endif %}
52 {%- endfor %} 156 {%- endfor %}
53 157
54 } // namespace std 158 } // namespace std
55 159
56 namespace mojo { 160 namespace mojo {
57 161
58 {#--- Enum Serialization Helpers -#} 162 {#--- Enum Serialization Helpers -#}
59 {%- for enum in all_enums %} 163 {%- for enum in all_enums %}
60 {%- if not enum|is_native_only_kind %} 164 {%- if not enum|is_native_only_kind %}
61 {% include "enum_serialization_declaration.tmpl" %} 165 {% include "enum_serialization_declaration.tmpl" %}
62 {%- endif %} 166 {%- endif %}
63 {%- endfor %} 167 {%- endfor %}
64 168
169 {#--- Struct Serialization Helpers -#}
170 {% for struct in structs %}
171 {%- if not struct|is_native_only_kind %}
172 {% include "struct_serialization_declaration.tmpl" %}
173 {%- endif %}
174 {%- endfor %}
175
176 {#--- Union Serialization Helpers -#}
177 {% if unions %}
178 {%- for union in unions %}
179 {% include "union_serialization_declaration.tmpl" %}
180 {%- endfor %}
181 {%- endif %}
182
65 } // namespace mojo 183 } // namespace mojo
66 184
185 {{namespace_begin()}}
186
187 {%- for struct in structs %}
188 {%- if not struct|is_native_only_kind %}
189 {% include "struct_data_view_definition.tmpl" %}
190 {%- endif %}
191 {%- endfor %}
192
193 {%- for interface in interfaces %}
194 {%- for method in interface.methods %}
195 {%- set struct = method.param_struct %}
196 {% include "struct_data_view_definition.tmpl" %}
197 {%- if method.response_parameters != None %}
198 {%- set struct = method.response_param_struct %}
199 {% include "struct_data_view_definition.tmpl" %}
200 {%- endif %}
201 {%- endfor %}
202 {%- endfor %}
203
204 {%- for union in unions %}
205 {% include "union_data_view_definition.tmpl" %}
206 {%- endfor %}
207
208 {{namespace_end()}}
209
67 #endif // {{header_guard}} 210 #endif // {{header_guard}}
68 211
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698