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

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

Issue 1065653006: Array and map members for unions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 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/union_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
index 3e6b0ade989afa0cc76c9ba643cedfaf8aca8521..f3a7a0425fcac94dda69bfa8b304ad7c6f2a432e 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
@@ -57,10 +57,36 @@ void {{class_name}}::set_null() {
void {{class_name}}::EncodePointersAndHandles(
std::vector<mojo::Handle>* handles) {
- // TODO(azani): Implement pointers and handles.
+ switch (tag) {
+{%- for field in union.fields %}
+ case {{enum_name}}::{{field.name|upper}}: {
+{%- if field.kind|is_object_kind and not field.kind|is_union_kind %}
+ mojo::internal::Encode(
+ reinterpret_cast<{{field.kind|cpp_field_type}}*>(&data),
yzshen1 2015/04/21 07:25:22 is it better to use &data.f_{{field.name}} instead
azani 2015/04/21 17:43:33 Maybe it's a bit more readable if we include the f
+ handles);
+{%- elif field.kind|is_any_handle_kind %}
+ mojo::internal::EncodeHandle(&data.f_{{field.name}}, handles);
yzshen1 2015/04/21 07:25:23 wrong indent.
azani 2015/04/21 17:43:33 Done.
+{%- endif %}
+ return;
+ }
+{%- endfor %}
+ }
}
void {{class_name}}::DecodePointersAndHandles(
std::vector<mojo::Handle>* handles) {
- // TODO(azani): Implement pointers and handles.
+ switch (tag) {
+{%- for field in union.fields %}
+ case {{enum_name}}::{{field.name|upper}}: {
+{%- if field.kind|is_object_kind and not field.kind|is_union_kind %}
+ mojo::internal::Decode(
+ reinterpret_cast<{{field.kind|cpp_field_type}}*>(&data),
yzshen1 2015/04/21 07:25:22 is it better to use &data.f_{{field.name}} instead
azani 2015/04/21 17:43:33 Done.
+ handles);
+{%- elif field.kind|is_any_handle_kind %}
+ mojo::internal::DecodeHandle(&data.f_{{field.name}}, handles);
+{%- endif %}
+ return;
+ }
+{%- endfor %}
+ }
}

Powered by Google App Engine
This is Rietveld 408576698