1template <typename UnionPtrType> 2{{union.name}}Ptr {{union.name}}::Clone() const { 3 // Use UnionPtrType to prevent the compiler from trying to compile this 4 // without being asked. 5 UnionPtrType rv(New()); 6 switch (tag_) { 7{%- for field in union.fields %} 8 case Tag::{{field.name|upper}}: 9{%- if field.kind|is_object_kind or 10 field.kind|is_any_handle_or_interface_kind %} 11 rv->set_{{field.name}}(mojo::Clone(*data_.{{field.name}})); 12{%- else %} 13 rv->set_{{field.name}}(mojo::Clone(data_.{{field.name}})); 14{%- endif %} 15 break; 16{%- endfor %} 17 }; 18 return rv; 19} 20 21template <typename T, 22 typename std::enable_if<std::is_same< 23 T, {{union.name}}>::value>::type*> 24bool {{union.name}}::Equals(const T& other) const { 25 if (tag_ != other.which()) 26 return false; 27 28 switch (tag_) { 29{%- for field in union.fields %} 30 case Tag::{{field.name|upper}}: 31{%- if field.kind|is_object_kind or 32 field.kind|is_any_handle_or_interface_kind %} 33 return mojo::Equals(*(data_.{{field.name}}), *(other.data_.{{field.name}})); 34{%- else %} 35 return mojo::Equals(data_.{{field.name}}, other.data_.{{field.name}}); 36{%- endif %} 37{%- endfor %} 38 }; 39 40 return false; 41} 42