blob: 00b5067693f1d9d9799b3b471e7f83e73fa6b32a [file] [log] [blame]
{{/*
// 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:NaturalOStreamSource" -}}
fidl/{{ .LibraryDots }}/cpp/natural_ostream.cc
{{- end }}
{{- define "File:NaturalOStreamSource" -}}
{{- UseUnified -}}
// WARNING: This file is machine generated by fidlgen.
{{ range $experiment := .Experiments }}
// fidl_experiment = {{ $experiment }}
{{- end }}
#include <{{ .Library | Filename "NaturalOStreamHeader" }}>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
{{ EnsureNamespace "" }}
{{- range .Enums }}
std::ostream& fidl::ostream::Formatter<{{ . }}>::Format(std::ostream& os, const {{ . }}& value) {
os << "{{ .NoLeading }}";
os << "::";
switch (value) {
{{- $enum := . -}}
{{- range .Members }}
case {{ $enum }}::{{ . }}:
os << "{{ . }}";
break;
{{- end }}
default:
{{- if or (eq .Type.String "uint8_t") ((eq .Type.String "int8_t")) }}
os << "UNKNOWN(" << static_cast<int>(static_cast<{{ .Type }}>(value)) << ")";
{{- else }}
os << "UNKNOWN(" << static_cast<{{ .Type }}>(value) << ")";
{{- end }}
}
return os;
}
{{- end }}
{{- range .Bits }}
std::ostream& fidl::ostream::Formatter<{{ . }}>::Format(std::ostream& os, const {{ . }}& value) {
os << "{{ .NoLeading }}";
os << "(";
bool first = true;
{{- $bits := . }}
{{- range .Members }}
if (value & {{ $bits }}::{{ . }}) {
if (!first) os << "|";
first = false;
os << "{{ . }}";
}
{{- end }}
{{- if not .IsStrict }}
if (value.has_unknown_bits()) {
if (!first) os << "|";
{{- if or (eq .Type.String "uint8_t") ((eq .Type.String "int8_t")) }}
os << static_cast<int>(static_cast<{{ .Type }}>(value.unknown_bits()));
{{- else }}
os << static_cast<{{ .Type }}>(value.unknown_bits());
{{- end }}
}
{{- end }}
os << ")";
return os;
}
{{- end }}
{{- range .Structs }}
{{- if .IsResourceType }}
{{- IfdefFuchsia }}
{{- end }}
std::ostream& fidl::ostream::Formatter<{{ . }}>::Format(std::ostream& os, const {{ . }}& value) {
os << "{{ .NoLeading }}";
os << "{ ";
{{- range .Members }}
os << "{{ .Name }}";
os << " = " << fidl::ostream::Formatted<{{ .Type }}>(value.{{ .Name }}()) << ", ";
{{- end }}
os << "}";
return os;
}
{{- if .IsResourceType }}
{{- EndifFuchsia -}}
{{- end }}
{{- end }}
{{- range .Tables }}
{{- if .IsResourceType }}
{{- IfdefFuchsia }}
{{- end }}
std::ostream& fidl::ostream::Formatter<{{ . }}>::Format(std::ostream& os, const {{ . }}& value) {
os << "{{ .NoLeading }}";
os << "{ ";
{{- range .Members }}
if (value.{{ .Name }}().has_value()) {
os << "{{ .Name }}";
os << " = " << fidl::ostream::Formatted<{{ .Type }}>(value.{{ .Name }}().value()) << ", ";
}
{{- end }}
os << "}";
return os;
}
{{- if .IsResourceType }}
{{- EndifFuchsia -}}
{{- end }}
{{- end }}
{{- range .Unions }}
{{- if .IsResourceType }}
{{- IfdefFuchsia }}
{{- end }}
std::ostream& fidl::ostream::Formatter<{{ . }}>::Format(std::ostream& os, const {{ . }}& value) {
os << "{{ .NoLeading }}::";
switch (value.Which()) {
{{- range .Members }}
case {{ .TagName }}:
os << "{{ .Name }}(" << fidl::ostream::Formatted<{{ .Type }}>(value.{{ .Name }}().value()) << ")";
break;
{{- end }}
default:
os << "Unknown";
}
return os;
}
{{- if .IsResourceType }}
{{- EndifFuchsia -}}
{{- end }}
{{- end }}
{{ range .Decls }}
{{- if and (ne .Kind Kinds.Alias) (ne .Kind Kinds.Const) (ne .Kind Kinds.Protocol) (ne .Kind Kinds.Service) }}
{{- EnsureNamespace . }}
{{- if .IsResourceType }}
{{- IfdefFuchsia }}
{{- end }}
std::ostream& operator<<(std::ostream& os, const {{ . }}& value) {
return fidl::ostream::Formatter<{{ . }}>::Format(os, value);
}
{{- if .IsResourceType }}
{{- EndifFuchsia -}}
{{- end }}
{{- end }}
{{- end }}
#pragma clang diagnostic pop
{{ EndOfFile }}
{{- end }}