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

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

Issue 2226853002: Mojo C++ bindings: add support for UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@85_10_inline_more
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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_declaration.tmpl
index b4d627a72fd9c6b20df98ccc6a595363b8a0c7d9..b191fe6d97c6ee53acc1d546ebd791986fca63ec 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_declaration.tmpl
@@ -38,8 +38,18 @@ class {{export_attribute}} {{union.name}} {
}
{% for field in union.fields %}
- bool is_{{field.name}}() const;
- {{field.kind|cpp_union_getter_return_type}} get_{{field.name}}() const;
+ bool is_{{field.name}}() const { return tag_ == Tag::{{field.name|upper}}; }
+
+ {{field.kind|cpp_union_getter_return_type}} get_{{field.name}}() const {
+ DCHECK(tag_ == Tag::{{field.name|upper}});
+{%- if field.kind|is_object_kind or
+ field.kind|is_any_handle_or_interface_kind %}
+ return *(data_.{{field.name}});
+{%- else %}
+ return data_.{{field.name}};
+{%- endif %}
+ }
+
void set_{{field.name}}({{field.kind|cpp_wrapper_param_type}} {{field.name}});
{%- endfor %}

Powered by Google App Engine
This is Rietveld 408576698