| {{/* |
| // Copyright 2022 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| */}} |
| |
| {{- define "Filename:HLCPPConversion" -}} |
| fidl/{{ .LibraryDots }}/cpp/hlcpp_conversion.h |
| {{- end }} |
| |
| |
| {{- define "Filename:HLCPPHeader" -}} |
| {{ .LibrarySlashes }}/cpp/fidl.h |
| {{- end }} |
| |
| |
| {{- define "File:HLCPPConversion" -}} |
| {{- UseWire -}} |
| // WARNING: This file is machine generated by fidlgen. |
| |
| #pragma once |
| |
| #include <lib/fidl/llcpp/internal/transport_channel.h> |
| #include <lib/fidl/cpp/hlcpp_conversion.h> |
| |
| #include <{{ .Library | Filename "NaturalTypesHeader" }}> |
| #include <{{ .Library | Filename "HLCPPHeader" }}> |
| |
| {{ range .Dependencies -}} |
| #include <{{ . | Filename "HLCPPConversion" }}> |
| {{ end -}} |
| |
| |
| {{ EnsureNamespace "fidl::internal" }} |
| |
| {{- range .Enums }} |
| template<> |
| struct NaturalToHLCPPTraits<{{ .Unified }}> : public NaturalToHLCPPTraitsEnum<{{ .Unified }}, {{ .HLCPP }}>{}; |
| template<> |
| struct HLCPPToNaturalTraits<{{ .HLCPP }}> : public HLCPPToNaturalTraitsEnum<{{ .HLCPP }}, {{ .Unified }}>{}; |
| {{- end }} |
| |
| {{- range .Bits }} |
| template<> |
| struct NaturalToHLCPPTraits<{{ .Unified }}> : public NaturalToHLCPPTraitsBits<{{ .Unified }}, {{ .HLCPP }}, {{ .Type }}>{}; |
| template<> |
| struct HLCPPToNaturalTraits<{{ .HLCPP }}> : public HLCPPToNaturalTraitsBits<{{ .HLCPP }}, {{ .Unified }}, {{ .Type }}>{}; |
| {{- end }} |
| |
| {{ range ( call .ProtocolsForTransport "Channel" ) }} |
| template<> |
| struct NaturalToHLCPPTraits<fidl::ClientEnd<{{ .Wire }}>> { |
| using HLCPPType = fidl::InterfaceHandle<{{ .HLCPP }}>; |
| static inline fidl::InterfaceHandle<{{ .HLCPP }}> Convert(fidl::ClientEnd<{{ .Wire }}>&& c) { |
| return fidl::InterfaceHandle<{{ .HLCPP }}>(c.TakeChannel()); |
| } |
| }; |
| |
| template<> |
| struct NaturalToHLCPPTraits<fidl::ServerEnd<{{ .Wire }}>> { |
| using HLCPPType = fidl::InterfaceRequest<{{ .HLCPP }}>; |
| static inline fidl::InterfaceRequest<{{ .HLCPP }}> Convert(fidl::ServerEnd<{{ .Wire }}>&& c) { |
| return fidl::InterfaceRequest<{{ .HLCPP }}>(c.TakeChannel()); |
| } |
| }; |
| |
| template<> |
| struct HLCPPToNaturalTraits<fidl::InterfaceHandle<{{ .HLCPP }}>> { |
| using NaturalType = fidl::ClientEnd<{{ .Wire }}>; |
| static inline fidl::ClientEnd<{{ .Wire }}> Convert(fidl::InterfaceHandle<{{ .HLCPP }}>&& c) { |
| return fidl::ClientEnd<{{ .Wire }}>(c.TakeChannel()); |
| } |
| }; |
| |
| template<> |
| struct HLCPPToNaturalTraits<fidl::InterfaceRequest<{{ .HLCPP }}>> { |
| using NaturalType = fidl::ServerEnd<{{ .Wire }}>; |
| static inline fidl::ServerEnd<{{ .Wire }}> Convert(fidl::InterfaceRequest<{{ .HLCPP }}>&& c) { |
| return fidl::ServerEnd<{{ .Wire }}>(c.TakeChannel()); |
| } |
| }; |
| {{- end }} |
| |
| {{ range .Structs }} |
| template<> |
| struct NaturalToHLCPPTraits<{{ .Unified }}> { |
| using HLCPPType = {{ .HLCPP }}; |
| static inline {{ .HLCPP }} Convert({{ .Unified }}&&); |
| }; |
| template<> |
| struct HLCPPToNaturalTraits<{{ .HLCPP }}> { |
| using NaturalType = {{ .Unified }}; |
| static inline {{ .Unified }} Convert({{ .HLCPP }}&&); |
| }; |
| {{- end }} |
| |
| {{- range .Tables }} |
| template<> |
| struct NaturalToHLCPPTraits<{{ .Unified }}> { |
| using HLCPPType = {{ .HLCPP }}; |
| static inline {{ .HLCPP }} Convert({{ .Unified }}&&); |
| }; |
| template<> |
| struct HLCPPToNaturalTraits<{{ .HLCPP }}> { |
| using NaturalType = {{ .Unified }}; |
| static inline {{ .Unified }} Convert({{ .HLCPP }}&&); |
| }; |
| {{- end }} |
| |
| {{- range .Unions }} |
| template<> |
| struct NaturalToHLCPPTraits<{{ .Unified }}> { |
| using HLCPPType = {{ .HLCPP }}; |
| static inline {{ .HLCPP }} Convert({{ .Unified }}&&); |
| }; |
| template<> |
| struct HLCPPToNaturalTraits<{{ .HLCPP }}> { |
| using NaturalType = {{ .Unified }}; |
| static inline {{ .Unified }} Convert({{ .HLCPP }}&&); |
| }; |
| {{- end }} |
| |
| {{ range .Structs }} |
| {{ .HLCPP }} NaturalToHLCPPTraits<{{ .Unified }}>::Convert({{ .Unified }}&& value) { |
| {{ .HLCPP }} hlcpp; |
| {{- range .Members }} |
| hlcpp.{{ .HLCPP }} = ::fidl::NaturalToHLCPP(std::move(value.{{ .Unified }}())); |
| {{- end }} |
| return hlcpp; |
| } |
| |
| {{ .Unified }} HLCPPToNaturalTraits<{{ .HLCPP }}>::Convert({{ .HLCPP }}&& value) { |
| return {{ .Unified }}{ { |
| {{- range .Members }} |
| .{{ .Unified }} = ::fidl::HLCPPToNatural(std::move(value.{{ .HLCPP }})), |
| {{- end }} |
| } }; |
| } |
| {{- end }} |
| |
| {{- range .Tables }} |
| {{ .HLCPP }} NaturalToHLCPPTraits<{{ .Unified }}>::Convert({{ .Unified }}&& value) { |
| {{ .HLCPP }} hlcpp; |
| {{- range .Members }} |
| if (value.{{ .Unified }}().has_value()) { |
| hlcpp.set_{{ .HLCPP }}(::fidl::NaturalToHLCPP(std::move(value.{{ .Unified }}().value()))); |
| } |
| {{- end }} |
| return hlcpp; |
| } |
| |
| {{ .Unified }} HLCPPToNaturalTraits<{{ .HLCPP }}>::Convert({{ .HLCPP }}&& value) { |
| {{ .Unified }} natural; |
| {{- range .Members }} |
| if (value.{{ .MethodHasName }}()) { |
| natural.{{ .Unified }}() = ::fidl::HLCPPToNatural(std::move(*value.mutable_{{ .HLCPP }}())); |
| } |
| {{- end }} |
| return natural; |
| } |
| {{- end }} |
| |
| {{ range .Unions }} |
| {{ .HLCPP }} NaturalToHLCPPTraits<{{ .Unified }}>::Convert({{ .Unified }}&& value) { |
| {{ .HLCPP }} hlcpp; |
| switch (value.Which()) { |
| {{- range .Members }} |
| case {{ .TagName.Unified }}: |
| hlcpp.set_{{ .HLCPP }}(::fidl::NaturalToHLCPP(std::move(value.{{ .Unified }}().value()))); |
| break; |
| {{- end }} |
| default: |
| break; |
| } |
| return hlcpp; |
| } |
| |
| {{ .Unified }} HLCPPToNaturalTraits<{{ .HLCPP }}>::Convert({{ .HLCPP }}&& value) { |
| using _NaturalUnion = {{ .Unified }}; |
| switch (value.Which()) { |
| {{- range .Members }} |
| case {{ .TagName.HLCPP }}: |
| return _NaturalUnion::With{{ .UpperCamelCaseName }}( |
| ::fidl::HLCPPToNatural(std::move(value.{{ .HLCPP }}()))); |
| {{- end }} |
| default: |
| {{- if .IsFlexible }} |
| return _NaturalUnion(); |
| {{- else }} |
| ZX_PANIC("Can't convert invalid strict union %s from HLCPP to Natural", "{{ .HLCPP }}"); |
| {{- end }} |
| } |
| } |
| {{- end }} |
| |
| {{ EndOfFile }} |
| {{ end }} |