blob: 01338cde632cbdeb89c1e0d4cc9a40e544b049a3 [file] [log] [blame]
{{/*
// 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:TypesHeader" }}
{{ EnsureNamespace . }}
struct {{ .Name }};
{{- end }}
{{/* TODO(fxbug.dev/36441): Remove __Fuchsia__ ifdefs once we have non-Fuchsia
emulated handles for C++. */}}
{{- define "Struct:TypesHeader" }}
{{ EnsureNamespace . }}
{{ if .IsResourceType }}
{{- IfdefFuchsia -}}
{{- end }}
extern "C" const fidl_type_t {{ .CodingTableType }};
{{ .Docs }}
struct {{ .Name }} {
static constexpr const fidl_type_t* Type = &{{ .CodingTableType }};
static constexpr uint32_t MaxNumHandles = {{ .TypeShapeV2.MaxHandles }};
static constexpr uint32_t PrimarySize = {{ .TypeShapeV2.InlineSize }};
static constexpr uint32_t PrimarySizeV1 = {{ .TypeShapeV1.InlineSize }};
[[maybe_unused]]
static constexpr uint32_t MaxOutOfLine = {{ .TypeShapeV2.MaxOutOfLine }};
static constexpr uint32_t MaxOutOfLineV1 = {{ .TypeShapeV1.MaxOutOfLine }};
static constexpr bool HasPointer = {{ .TypeShapeV2.HasPointer }};
{{- range .AnonymousChildren }}
using {{ .ScopedName }} = {{ .FlattenedName }};
{{- end }}
{{- range .Members }}
{{ "" }}
{{- .Docs }}
{{ .Type }} {{ .Name }} = {};
{{- end }}
{{- if .IsResourceType }}
void _CloseHandles();
{{- end }}
class UnownedEncodedMessage;
class OwnedEncodedMessage;
class DecodedMessage;
};
{{- if .IsResourceType }}
{{- EndifFuchsia -}}
{{- end }}
{{- end }}
{{/* TODO(fxbug.dev/36441): Remove __Fuchsia__ ifdefs once we have non-Fuchsia
emulated handles for C++. */}}
{{- define "Struct:TypesSource" }}
{{ 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:TypesHeader" }}
{{ if .IsResourceType }}
{{- IfdefFuchsia -}}
template <>
struct IsResource<{{ . }}> : public std::true_type {};
{{- end }}
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({{ . }}) == {{ . }}::PrimarySize);
{{- if .IsResourceType }}
{{- EndifFuchsia -}}
{{- end }}
{{- end }}