Chromium Code Reviews| 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 %} |
| + } |
| } |