template <typename UnionPtrType>
{{union.name}}Ptr {{union.name}}::Clone() const {
switch (tag_) {
{%- for field in union.fields %}
case Tag::k{{field.name|under_to_camel}}:
{%- if field.kind|is_object_kind or
field.kind|is_any_handle_or_interface_kind %}
return New{{field.name|under_to_camel}}(
mojo::Clone(*data_.{{field.name}}));
{%- else %}
return New{{field.name|under_to_camel}}(
mojo::Clone(data_.{{field.name}}));
{%- endif %}
{%- endfor %}
}
return nullptr;
}
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::k{{field.name|under_to_camel}}:
{%- if field.kind|is_object_kind or
field.kind|is_any_handle_or_interface_kind %}
return mojo::Equals(*(data_.{{field.name}}), *(other.data_.{{field.name}}));
{%- else %}
return mojo::Equals(data_.{{field.name}}, other.data_.{{field.name}});
{%- endif %}
{%- endfor %}
}
return false;
}