| // WARNING: This file is machine generated by fidlgen. |
| |
| #pragma once |
| |
| #include <fidl/test.versions/cpp/common_types.h> |
| #include <fidl/test.versions/cpp/markers.h> |
| #include <lib/fidl/cpp/natural_coding_traits.h> |
| #include <lib/fidl/cpp/natural_types.h> |
| |
| #include <cinttypes> |
| #include <string> |
| |
| #ifdef __Fuchsia__ |
| |
| #include <lib/zx/channel.h> |
| |
| #endif // __Fuchsia__ |
| |
| namespace test_versions { |
| class Struct; |
| |
| class Table; |
| |
| class Union; |
| |
| extern "C" const fidl_type_t test_versions_UnionTable; |
| |
| class Union { |
| private: |
| using Storage_ = std::variant<std::monostate, uint32_t>; |
| |
| public: |
| // TODO: share union tag types between wire & natural. |
| enum class Tag : fidl_union_tag_t { |
| kX = 1, // 0x1 |
| kUnknown = ::std::numeric_limits<::fidl_union_tag_t>::max(), |
| }; |
| // Create an unknown value of this union. |
| Union() : storage_(std::make_shared<Storage_>()) {} |
| |
| Union(Union&& other) noexcept |
| : Union(::fidl::internal::DefaultConstructPossiblyInvalidObjectTag{}) { |
| *storage_ = std::move(*other.storage_); |
| } |
| Union& operator=(Union&& other) noexcept { |
| if (this != &other) { |
| *storage_ = std::move(*other.storage_); |
| } |
| return *this; |
| } |
| Union(const Union& other) noexcept : Union(other.CloneStorage_()) {} |
| Union& operator=(const Union& other) noexcept { |
| if (this != &other) { |
| storage_ = other.CloneStorage_(); |
| } |
| return *this; |
| } |
| |
| bool operator==(const Union& other) const noexcept { |
| return *storage_ == *other.storage_; |
| } |
| bool operator!=(const Union& other) const noexcept { |
| return *storage_ != *other.storage_; |
| } |
| |
| constexpr ::test_versions::Union::Tag Which() const { |
| return Union::IndexToTag(storage_->index()).value(); |
| } |
| static Union WithX(uint32_t val) { |
| return Union( |
| std::make_shared<Storage_>(std::in_place_index_t<1>{}, std::move(val))); |
| } |
| |
| const ::fidl::internal::UnionMemberView<1, Storage_> x() const { |
| return ::fidl::internal::UnionMemberView<1, Storage_>(storage_); |
| } |
| ::fidl::internal::UnionMemberView<1, Storage_> x() { |
| return ::fidl::internal::UnionMemberView<1, Storage_>(storage_); |
| } |
| |
| Union(::fidl::internal::DefaultConstructPossiblyInvalidObjectTag) |
| : storage_(std::make_shared<Storage_>()) {} |
| |
| private: |
| std::shared_ptr<Storage_> storage_; |
| std::shared_ptr<Storage_> CloneStorage_() const; |
| friend struct ::fidl::internal::NaturalUnionCodingTraits< |
| ::test_versions::Union>; |
| static constexpr auto kMembers = |
| std::make_tuple(::fidl::internal::NaturalUnionMember< |
| ::fidl::internal::NaturalCodingConstraintEmpty>(), |
| ::fidl::internal::NaturalUnionMember< |
| fidl::internal::NaturalCodingConstraintEmpty>()); |
| |
| explicit Union(std::shared_ptr<Storage_> storage) |
| : storage_(std::move(storage)) {} |
| |
| static constexpr size_t TagToIndex(::fidl::internal::NaturalDecoder* decoder, |
| ::test_versions::Union::Tag tag) { |
| switch (tag) { |
| case ::test_versions::Union::Tag::kX: |
| return 1; |
| case ::test_versions::Union::Tag::kUnknown: |
| return 0; |
| default: { |
| decoder->SetError(::fidl::internal::kCodingErrorUnknownUnionTag); |
| return 0; |
| } |
| } |
| } |
| |
| static constexpr std::optional<::test_versions::Union::Tag> IndexToTag( |
| size_t index) { |
| switch (index) { |
| case 1: |
| return ::test_versions::Union::Tag::kX; |
| default: |
| return ::test_versions::Union::Tag::kUnknown; |
| } |
| } |
| }; |
| |
| extern "C" const fidl_type_t test_versions_TableTable; |
| |
| class Table { |
| private: |
| struct Storage_; |
| |
| public: |
| Table(Storage_ storage) noexcept : storage_(std::move(storage)) {} |
| Table() noexcept = default; |
| Table(Table&&) noexcept = default; |
| Table& operator=(Table&&) noexcept = default; |
| Table(const Table& other) noexcept : Table(other.CloneStorage_()) {} |
| Table& operator=(const Table& other) noexcept { |
| storage_ = other.CloneStorage_(); |
| return *this; |
| } |
| bool operator==(const Table& other) const noexcept { |
| return ::fidl::internal::NaturalTableCodingTraits< |
| ::test_versions::Table>::Equal(this, &other); |
| } |
| bool operator!=(const Table& other) const noexcept { |
| return !::fidl::internal::NaturalTableCodingTraits< |
| ::test_versions::Table>::Equal(this, &other); |
| } |
| |
| bool IsEmpty() const { return !(storage_.x.has_value()); } |
| |
| const std::optional<uint32_t>& x() const { return storage_.x; } |
| ::std::optional<uint32_t>& x() { return storage_.x; } |
| |
| Table(::fidl::internal::DefaultConstructPossiblyInvalidObjectTag) |
| : Table(Storage_{}) {} |
| |
| private: |
| struct Storage_ final { |
| ::std::optional<uint32_t> x{}; |
| }; |
| |
| // TODO(https://fxbug.dev/91252): Box the storage. |
| Storage_ storage_; |
| Storage_ CloneStorage_() const; |
| friend struct ::fidl::internal::NaturalTableCodingTraits< |
| ::test_versions::Table>; |
| friend struct ::fidl::internal::MemberVisitor<::test_versions::Table>; |
| static constexpr auto kMembers = std::make_tuple( |
| ::fidl::internal::NaturalTableMember< |
| Storage_, uint32_t, fidl::internal::NaturalCodingConstraintEmpty>{ |
| 1, &Storage_::x}); |
| }; |
| |
| extern "C" const fidl_type_t test_versions_StructTable; |
| |
| class Struct { |
| private: |
| struct Storage_; |
| |
| public: |
| Struct(Storage_ storage) noexcept : storage_(std::move(storage)) {} |
| Struct(uint32_t x) noexcept : storage_({.x = std::move(x)}) {} |
| |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wdefaulted-function-deleted" |
| // Default constructs a |Struct| only if all of its members are default |
| // constructible. |
| Struct() = default; |
| #pragma clang diagnostic pop |
| |
| Struct(Struct&&) noexcept = default; |
| Struct& operator=(Struct&&) noexcept = default; |
| Struct(const Struct& other) noexcept : Struct(other.CloneStorage_()) {} |
| Struct& operator=(const Struct& other) noexcept { |
| storage_ = other.CloneStorage_(); |
| return *this; |
| } |
| |
| bool operator==(const Struct& other) const noexcept { |
| return ::fidl::internal::NaturalStructCodingTraits<::test_versions::Struct, |
| 4>::Equal(this, &other); |
| } |
| bool operator!=(const Struct& other) const noexcept { |
| return !::fidl::internal::NaturalStructCodingTraits<::test_versions::Struct, |
| 4>::Equal(this, &other); |
| } |
| |
| uint32_t x() const { return storage_.x; } |
| |
| uint32_t& x() { return storage_.x; } |
| |
| Struct(::fidl::internal::DefaultConstructPossiblyInvalidObjectTag) |
| : Struct(Storage_{ |
| .x = {}, |
| }) {} |
| |
| private: |
| struct Storage_ final { |
| uint32_t x = {}; |
| }; |
| |
| Storage_ storage_; |
| Storage_ CloneStorage_() const; |
| |
| friend struct ::fidl::internal::NaturalStructCodingTraits< |
| ::test_versions::Struct, 4>; |
| friend struct ::fidl::internal::MemberVisitor<::test_versions::Struct>; |
| static constexpr auto kMembers = std::make_tuple( |
| ::fidl::internal::NaturalStructMember< |
| Storage_, uint32_t, fidl::internal::NaturalCodingConstraintEmpty>{ |
| &Storage_::x, 0}); |
| static constexpr auto kPadding = std::make_tuple(); |
| }; |
| |
| constexpr uint32_t kConst = 0u; |
| |
| constexpr bool kAddedAtHead = true; |
| |
| } // namespace test_versions |
| namespace fidl { |
| |
| extern "C" const fidl_type_t test_versions_StructTable; |
| |
| template <> |
| struct IsFidlType<::test_versions::Struct> : public std::true_type {}; |
| |
| template <> |
| struct ::fidl::internal::TypeTraits<::test_versions::Struct> final { |
| public: |
| static constexpr const fidl_type_t* kCodingTable = &test_versions_StructTable; |
| }; |
| |
| template <> |
| struct internal::NaturalCodingTraits< |
| ::test_versions::Struct, ::fidl::internal::NaturalCodingConstraintEmpty> |
| final : public ::fidl::internal::NaturalStructCodingTraits< |
| ::test_versions::Struct, 4> {}; |
| |
| extern "C" const fidl_type_t test_versions_TableTable; |
| |
| template <> |
| struct IsFidlType<::test_versions::Table> : public std::true_type {}; |
| |
| template <> |
| struct ::fidl::internal::TypeTraits<::test_versions::Table> final { |
| public: |
| static constexpr const fidl_type_t* kCodingTable = &test_versions_TableTable; |
| }; |
| |
| template <> |
| struct internal::NaturalCodingTraits< |
| ::test_versions::Table, ::fidl::internal::NaturalCodingConstraintEmpty> |
| : public ::fidl::internal::NaturalTableCodingTraits< |
| ::test_versions::Table> {}; |
| |
| extern "C" const fidl_type_t test_versions_UnionTable; |
| |
| template <> |
| struct IsFidlType<::test_versions::Union> : public std::true_type {}; |
| template <> |
| struct IsUnion<::test_versions::Union> : public std::true_type {}; |
| |
| template <> |
| struct ::fidl::internal::TypeTraits<::test_versions::Union> final { |
| public: |
| static constexpr const fidl_type_t* kCodingTable = &test_versions_UnionTable; |
| }; |
| |
| template <> |
| struct internal::NaturalCodingTraits< |
| ::test_versions::Union, ::fidl::internal::NaturalCodingConstraintEmpty> |
| final : public ::fidl::internal::NaturalUnionCodingTraits< |
| ::test_versions::Union> {}; |
| |
| template <> |
| struct internal::NaturalCodingTraits< |
| ::test_versions::Bits, ::fidl::internal::NaturalCodingConstraintEmpty> { |
| static constexpr size_t inline_size_v2 = sizeof(uint32_t); |
| static constexpr bool is_memcpy_compatible = true; |
| |
| static void Encode(internal::NaturalEncoder* encoder, |
| ::test_versions::Bits* value, size_t offset, |
| size_t recursion_depth) { |
| *encoder->template GetPtr<::test_versions::Bits>(offset) = *value; |
| } |
| static void Decode(internal::NaturalDecoder* decoder, |
| ::test_versions::Bits* value, size_t offset, |
| size_t recursion_depth) { |
| *value = *decoder->template GetPtr<::test_versions::Bits>(offset); |
| } |
| }; |
| |
| template <> |
| struct internal::NaturalCodingTraits< |
| ::test_versions::Enum, ::fidl::internal::NaturalCodingConstraintEmpty> { |
| static constexpr size_t inline_size_v2 = sizeof(uint32_t); |
| static constexpr bool is_memcpy_compatible = true; |
| |
| static void Encode(internal::NaturalEncoder* encoder, |
| ::test_versions::Enum* value, size_t offset, |
| size_t recursion_depth) { |
| *encoder->template GetPtr<::test_versions::Enum>(offset) = *value; |
| } |
| static void Decode(internal::NaturalDecoder* decoder, |
| ::test_versions::Enum* value, size_t offset, |
| size_t recursion_depth) { |
| *value = *decoder->template GetPtr<::test_versions::Enum>(offset); |
| } |
| }; |
| |
| } // namespace fidl |