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

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

Issue 2694843003: Add field-initializing factory static methods to generated mojo unions. (Closed)
Patch Set: Created 3 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/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 8b7cf9e6b1dc75485ff26d6184dd777a29cd0163..4a768a9f8585ffb37317d01ffe4869db9e54ece9 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
@@ -4,7 +4,20 @@ class {{export_attribute}} {{union.name}} {
using Data_ = internal::{{union.name}}_Data;
using Tag = Data_::{{union.name}}_Tag;
- static {{union.name}}Ptr New();
+ static {{union.name}}Ptr New() {
+ return {{union.name}}Ptr(base::in_place);
+ }
+
+{%- for field in union.fields %}
+ // Construct an instance holding |{{field.name}}|.
+ static {{union.name}}Ptr
+ New{{field.name|under_to_camel}}(
+ {{field.kind|cpp_wrapper_param_type}} {{field.name}}) {
+ auto result = {{union.name}}Ptr(base::in_place);
+ result->set_{{field.name}}(std::move({{field.name}}));
+ return result;
+ }
+{%- endfor %}
template <typename U>
static {{union.name}}Ptr From(const U& u) {
@@ -58,7 +71,6 @@ class {{export_attribute}} {{union.name}} {
{%- endfor %}
private:
- friend class mojo::internal::UnionAccessor<{{union.name}}>;
union Union_ {
Union_() {}
~Union_() {}
@@ -72,8 +84,6 @@ class {{export_attribute}} {{union.name}} {
{%- endif %}
{%- endfor %}
};
- void SwitchActive(Tag new_active);
- void SetActive(Tag new_active);
void DestroyActive();
Tag tag_;
Union_ data_;

Powered by Google App Engine
This is Rietveld 408576698