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

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

Issue 2031823002: Mojo C++ bindings: more consistent Clone() and Equals(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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_template_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_template_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_template_definition.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..c8716452f36ef1367e6aaaa6c4d37589c4ab85e0
--- /dev/null
+++ b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_template_definition.tmpl
@@ -0,0 +1,41 @@
+template <typename UnionPtrType>
+{{union.name}}Ptr {{union.name}}::Clone() const {
+ // Use UnionPtrType to prevent the compiler from trying to compile this
+ // without being asked.
+ UnionPtrType rv(New());
+ switch (tag_) {
+{%- for field in union.fields %}
+ case Tag::{{field.name|upper}}:
+{%- if field.kind|is_object_kind or field.kind|is_any_handle_kind or
+ field.kind|is_interface_kind or field.kind|is_associated_kind %}
+ rv->set_{{field.name}}(mojo::internal::Clone(*data_.{{field.name}}));
+{%- else %}
+ rv->set_{{field.name}}(mojo::internal::Clone(data_.{{field.name}}));
+{%- endif %}
+ break;
+{%- endfor %}
+ };
+ return rv;
+}
+
+template <typename T,
+ typename std::enable_if<std::is_same<
+ T, {{union.name}}>::value>::type*>
+bool {{union.name}}::Equals(const T& other) const {
+ if (tag_ != other.which())
+ return false;
+
+ switch (tag_) {
+{%- for field in union.fields %}
+ case Tag::{{field.name|upper}}:
+{%- if field.kind|is_object_kind or field.kind|is_any_handle_kind or
+ field.kind|is_interface_kind or field.kind|is_associated_kind %}
+ return mojo::internal::Equals(*(data_.{{field.name}}), *(other.data_.{{field.name}}));
+{%- else %}
+ return mojo::internal::Equals(data_.{{field.name}}, other.data_.{{field.name}});
+{%- endif %}
+{%- endfor %}
+ };
+
+ return false;
+}

Powered by Google App Engine
This is Rietveld 408576698