| // WARNING: This file is machine generated by fidlgen. |
| |
| // fidl_experiment = output_index_json |
| |
| #pragma once |
| |
| #include <lib/fidl/cpp/wire/internal/display_error.h> |
| #include <lib/fidl/cpp/wire/traits.h> |
| #include <lib/stdcompat/optional.h> |
| |
| #include <cinttypes> |
| |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wshadow" |
| |
| namespace test_typesinprotocols { |
| |
| // |Bits| is flexible, hence may contain unknown members not |
| // defined in the FIDL schema. |
| class Bits final { |
| public: |
| constexpr Bits() = default; |
| |
| // Constructs an instance of |Bits| from an underlying primitive value, |
| // preserving any bit member not defined in the FIDL schema. |
| explicit constexpr Bits(uint32_t value) : value_(value) {} |
| const static Bits kVal; |
| const static Bits kMask; |
| |
| explicit constexpr inline operator uint32_t() const { return value_; } |
| explicit constexpr inline operator bool() const { return static_cast<bool>(value_); } |
| constexpr inline bool operator==(const Bits& other) const { return value_ == other.value_; } |
| constexpr inline bool operator!=(const Bits& other) const { return value_ != other.value_; } |
| constexpr inline Bits operator~() const; |
| constexpr inline Bits operator|(const Bits& other) const; |
| constexpr inline Bits operator&(const Bits& other) const; |
| constexpr inline Bits operator^(const Bits& other) const; |
| constexpr inline Bits operator-(const Bits& other) const; |
| constexpr inline void operator|=(const Bits& other); |
| constexpr inline void operator&=(const Bits& other); |
| constexpr inline void operator^=(const Bits& other); |
| constexpr inline void operator-=(const Bits& other); |
| |
| // Constructs an instance of |Bits| from an underlying primitive value |
| // if the primitive does not contain any unknown members not defined in the |
| // FIDL schema. Otherwise, returns |std::nullopt|. |
| constexpr inline static std::optional<Bits> TryFrom(uint32_t value) { |
| if (value & ~kMask.value_) { |
| return std::nullopt; |
| } |
| return Bits(value & Bits::kMask.value_); |
| } |
| |
| // Constructs an instance of |Bits| from an underlying primitive value, |
| // clearing any bit member not defined in the FIDL schema. |
| constexpr inline static Bits TruncatingUnknown(uint32_t value) { |
| return Bits(value & Bits::kMask.value_); |
| } |
| constexpr inline Bits unknown_bits() const { |
| return *this & Bits(~kMask.value_); |
| } |
| constexpr inline bool has_unknown_bits() const { return static_cast<bool>(unknown_bits()); } |
| |
| private: |
| uint32_t value_ = 0; |
| }; |
| constexpr const ::test_typesinprotocols::Bits Bits::kVal = |
| ::test_typesinprotocols::Bits(1u); |
| constexpr const ::test_typesinprotocols::Bits Bits::kMask = ::test_typesinprotocols::Bits(1u); |
| |
| constexpr inline ::test_typesinprotocols::Bits Bits::operator~() const { |
| return ::test_typesinprotocols::Bits(static_cast<uint32_t>(~this->value_ & kMask.value_)); |
| } |
| |
| constexpr inline ::test_typesinprotocols::Bits Bits::operator|( |
| const ::test_typesinprotocols::Bits& other) const { |
| return ::test_typesinprotocols::Bits(static_cast<uint32_t>(this->value_ | other.value_)); |
| } |
| |
| constexpr inline ::test_typesinprotocols::Bits Bits::operator&( |
| const ::test_typesinprotocols::Bits& other) const { |
| return ::test_typesinprotocols::Bits(static_cast<uint32_t>(this->value_ & other.value_)); |
| } |
| |
| constexpr inline ::test_typesinprotocols::Bits Bits::operator^( |
| const ::test_typesinprotocols::Bits& other) const { |
| return ::test_typesinprotocols::Bits(static_cast<uint32_t>(this->value_ ^ other.value_)); |
| } |
| |
| constexpr inline ::test_typesinprotocols::Bits Bits::operator-( |
| const ::test_typesinprotocols::Bits& other) const { |
| return ::test_typesinprotocols::Bits(static_cast<uint32_t>(this->value_ & ~other.value_)); |
| } |
| |
| constexpr inline void Bits::operator|=( |
| const ::test_typesinprotocols::Bits& other) { |
| this->value_ |= other.value_; |
| } |
| |
| constexpr inline void Bits::operator&=( |
| const ::test_typesinprotocols::Bits& other) { |
| this->value_ &= other.value_; |
| } |
| |
| constexpr inline void Bits::operator^=( |
| const ::test_typesinprotocols::Bits& other) { |
| this->value_ ^= other.value_; |
| } |
| |
| constexpr inline void Bits::operator-=( |
| const ::test_typesinprotocols::Bits& other) { |
| this->value_ &= ~other.value_; |
| } |
| |
| class Enum final { |
| private: |
| enum class EnumForSwitching_ : uint32_t { |
| |
| kVal = 1u, |
| |
| _do_not_handle_this__write_a_default_case_instead = 0xffffffff, |
| }; |
| |
| constexpr explicit Enum(EnumForSwitching_ value) : value_(static_cast<uint32_t>(value)) {} |
| |
| public: |
| constexpr Enum() : value_(static_cast<uint32_t>(Unknown())) {} |
| constexpr explicit Enum(uint32_t value) : value_(value) {} |
| constexpr operator EnumForSwitching_() const { return static_cast<EnumForSwitching_>(value_); } |
| constexpr explicit operator uint32_t() const { return value_; } |
| |
| constexpr bool IsUnknown() const { |
| switch (value_) { |
| case 1u: |
| |
| return false; |
| } |
| return true; |
| } |
| |
| // Returns an enum corresponding to the member designated as @unknown in the |
| // FIDL schema if exists, or a compiler-reserved unknown value otherwise. |
| constexpr static Enum Unknown() { |
| return Enum(0xffffffff); |
| } |
| |
| static const Enum kVal; |
| |
| private: |
| uint32_t value_; |
| }; |
| constexpr const ::test_typesinprotocols::Enum Enum::kVal = |
| ::test_typesinprotocols::Enum(1u); |
| |
| } // namespace test_typesinprotocols |
| |
| template <> |
| struct fidl::internal::DisplayError<::test_typesinprotocols::Enum> { |
| static size_t Format(const ::test_typesinprotocols::Enum& value, char* destination, size_t capacity); |
| }; |
| |
| namespace fidl { |
| |
| constexpr inline auto ToUnderlying(::test_typesinprotocols::Enum value) -> uint32_t { |
| return static_cast<uint32_t>(value); |
| } |
| |
| template <> |
| struct IsFidlType<::test_typesinprotocols::Bits> : public std::true_type {}; |
| template <> |
| struct ContainsHandle<::test_typesinprotocols::Bits> : public std::false_type {}; |
| static_assert(std::is_standard_layout_v<::test_typesinprotocols::Bits>); |
| static_assert(sizeof(::test_typesinprotocols::Bits) == sizeof(uint32_t)); |
| |
| template <> |
| struct IsFidlType<::test_typesinprotocols::Enum> : public std::true_type {}; |
| template <> |
| struct ContainsHandle<::test_typesinprotocols::Enum> : public std::false_type {}; |
| |
| #pragma clang diagnostic pop |
| |
| } // namespace fidl |