| {{/* |
| // Copyright 2018 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 "Struct:ForwardDeclaration:WireTypesHeader" }} |
| {{ EnsureNamespace . }} |
| struct {{ .Name }}; |
| {{- end }} |
| |
| {{/* TODO(fxbug.dev/36441): Remove __Fuchsia__ ifdefs once we have non-Fuchsia |
| emulated handles for C++. */}} |
| {{- define "Struct:WireTypesHeader" }} |
| {{ EnsureNamespace . }} |
| {{ if .IsResourceType }} |
| {{- IfdefFuchsia -}} |
| {{- end }} |
| extern "C" const fidl_type_t {{ .CodingTableType.Name }}; |
| {{ .Docs }} |
| struct {{ .Name }} { |
| {{- range .AnonymousChildren }} |
| using {{ .ScopedName }} = {{ .FlattenedName }}; |
| {{- end }} |
| |
| {{- range .Members }} |
| {{ "" }} |
| {{- .Docs }} |
| {{ .Type }} {{ .Name }} = {}; |
| {{- end }} |
| |
| {{- if .IsResourceType }} |
| |
| void _CloseHandles(); |
| {{- end }} |
| }; |
| |
| {{- if .IsResourceType }} |
| {{- EndifFuchsia -}} |
| {{- end }} |
| {{- end }} |
| |
| {{/* TODO(fxbug.dev/36441): Remove __Fuchsia__ ifdefs once we have non-Fuchsia |
| emulated handles for C++. */}} |
| {{- define "Struct:WireTypesSource" }} |
| {{ EnsureNamespace "" }} |
| {{ if .IsResourceType }} |
| {{- IfdefFuchsia -}} |
| void {{ . }}::_CloseHandles() { |
| {{- range .Members }} |
| {{- CloseHandles . false false }} |
| {{- end }} |
| } |
| {{- EndifFuchsia -}} |
| {{- end }} |
| {{- end }} |
| |
| {{/* TODO(fxbug.dev/36441): Remove __Fuchsia__ ifdefs once we have non-Fuchsia |
| emulated handles for C++. */}} |
| {{- define "Struct:Traits:WireTypesHeader" }} |
| {{ if .IsResourceType }} |
| {{- IfdefFuchsia -}} |
| template <> |
| struct IsResource<{{ . }}> : public std::true_type {}; |
| {{- end }} |
| |
| template<> |
| struct TypeTraits<{{ . }}> { |
| static constexpr const fidl_type_t* kType = &{{ .CodingTableType }}; |
| static constexpr uint32_t kMaxNumHandles = {{ .TypeShapeV2.MaxHandles }}; |
| static constexpr uint32_t kPrimarySize = {{ .TypeShapeV2.InlineSize }}; |
| static constexpr uint32_t kPrimarySizeV1 = {{ .TypeShapeV1.InlineSize }}; |
| [[maybe_unused]] |
| static constexpr uint32_t kMaxOutOfLine = {{ .TypeShapeV2.MaxOutOfLine }}; |
| static constexpr uint32_t kMaxOutOfLineV1 = {{ .TypeShapeV1.MaxOutOfLine }}; |
| static constexpr bool kHasPointer = {{ .TypeShapeV2.HasPointer }}; |
| }; |
| |
| template <> |
| struct IsFidlType<{{ . }}> : public std::true_type {}; |
| template <> |
| struct IsStruct<{{ . }}> : public std::true_type {}; |
| static_assert(std::is_standard_layout_v<{{ . }}>); |
| {{- $struct := . }} |
| {{- range .Members }} |
| static_assert(offsetof({{ $struct }}, {{ .Name }}) == {{ .OffsetV2 }}); |
| {{- end }} |
| static_assert(sizeof({{ . }}) == TypeTraits<{{ . }}>::kPrimarySize); |
| {{- if .IsResourceType }} |
| {{- EndifFuchsia -}} |
| {{- end }} |
| {{- end }} |
| |