aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_template_definition.tmpl
blob: 4c4851fa83589eb97defe9d2d8abfb41c4ce40dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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_or_interface_kind %}
      rv->set_{{field.name}}(mojo::Clone(*data_.{{field.name}}));
{%-   else %}
      rv->set_{{field.name}}(mojo::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_or_interface_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;
}