| {%- set mojom_type = union|get_qualified_name_for_kind %} |
| |
| template <> |
| struct {{export_attribute}} UnionTraits<{{mojom_type}}::DataView, |
| {{mojom_type}}Ptr> { |
| static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; } |
| static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); } |
| |
| static {{mojom_type}}::Tag GetTag(const {{mojom_type}}Ptr& input) { |
| return input->which(); |
| } |
| |
| {%- for field in union.fields %} |
| {%- set maybe_const_in = "" if field.kind|contains_handles_or_interfaces else "const" %} |
| {%- set maybe_const_out = "" if field.kind|contains_handles_or_interfaces or not field.kind|is_reference_kind else "const" %} |
| {# We want the field accessor to be const whenever possible to allow |
| structs to be used as map keys. #} |
| static {{maybe_const_out}} {{field.kind|cpp_union_trait_getter_return_type}} {{field.name}}({{maybe_const_in}} {{mojom_type}}Ptr& input) { |
| return input->get_{{field.name}}(); |
| } |
| {%- endfor %} |
| |
| static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output); |
| }; |