OLD | NEW |
1 class {{union.name}} { | 1 class {{union.name}} { |
2 public: | 2 public: |
3 using Data_ = internal::{{union.name}}_Data; | 3 using Data_ = internal::{{union.name}}_Data; |
4 using Tag = Data_::{{union.name}}_Tag; | 4 using Tag = Data_::{{union.name}}_Tag; |
5 | 5 |
6 static {{union.name}}Ptr New(); | 6 static {{union.name}}Ptr New(); |
7 | 7 |
8 template <typename U> | 8 template <typename U> |
9 static {{union.name}}Ptr From(const U& u) { | 9 static {{union.name}}Ptr From(const U& u) { |
10 return mojo::TypeConverter<{{union.name}}Ptr, U>::Convert(u); | 10 return mojo::TypeConverter<{{union.name}}Ptr, U>::Convert(u); |
11 } | 11 } |
12 | 12 |
13 template <typename U> | 13 template <typename U> |
14 U To() const { | 14 U To() const { |
15 return mojo::TypeConverter<U, {{union.name}}>::Convert(*this); | 15 return mojo::TypeConverter<U, {{union.name}}>::Convert(*this); |
16 } | 16 } |
17 | 17 |
18 {{union.name}}(); | 18 {{union.name}}(); |
19 ~{{union.name}}(); | 19 ~{{union.name}}(); |
20 | 20 |
21 {% if union|is_cloneable_kind %} | 21 // Clone() is a template so it is only instantiated if it is used. Thus, the |
| 22 // bindings generator does not need to know whether Clone() or copy |
| 23 // constructor/assignment are available for members. |
| 24 template <typename UnionPtrType = {{union.name}}Ptr> |
22 {{union.name}}Ptr Clone() const; | 25 {{union.name}}Ptr Clone() const; |
23 {%- endif %} | 26 |
24 bool Equals(const {{union.name}}& other) const; | 27 // Equals() is a template so it is only instantiated if it is used. Thus, the |
| 28 // bindings generator does not need to know whether Equals() or == operator |
| 29 // are available for members. |
| 30 template <typename T, |
| 31 typename std::enable_if<std::is_same< |
| 32 T, {{union.name}}>::value>::type* = nullptr> |
| 33 bool Equals(const T& other) const; |
25 | 34 |
26 Tag which() const { | 35 Tag which() const { |
27 return tag_; | 36 return tag_; |
28 } | 37 } |
29 | 38 |
30 {% for field in union.fields %} | 39 {% for field in union.fields %} |
31 bool is_{{field.name}}() const; | 40 bool is_{{field.name}}() const; |
32 {{field.kind|cpp_union_getter_return_type}} get_{{field.name}}() const; | 41 {{field.kind|cpp_union_getter_return_type}} get_{{field.name}}() const; |
33 void set_{{field.name}}({{field.kind|cpp_wrapper_param_type}} {{field.name}}); | 42 void set_{{field.name}}({{field.kind|cpp_wrapper_param_type}} {{field.name}}); |
34 {%- endfor %} | 43 {%- endfor %} |
(...skipping 11 matching lines...) Expand all Loading... |
46 {{field.kind|cpp_wrapper_type}} {{field.name}}; | 55 {{field.kind|cpp_wrapper_type}} {{field.name}}; |
47 {% endif -%} | 56 {% endif -%} |
48 {%- endfor %} | 57 {%- endfor %} |
49 }; | 58 }; |
50 void SwitchActive(Tag new_active); | 59 void SwitchActive(Tag new_active); |
51 void SetActive(Tag new_active); | 60 void SetActive(Tag new_active); |
52 void DestroyActive(); | 61 void DestroyActive(); |
53 Tag tag_; | 62 Tag tag_; |
54 Union_ data_; | 63 Union_ data_; |
55 }; | 64 }; |
OLD | NEW |