| // 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_consts { |
| |
| // |BitsType| is strict, hence is guaranteed to only contain |
| // members defined in the FIDL schema when receiving it in a message. |
| // Sending unknown members will fail at runtime. |
| class BitsType final { |
| public: |
| constexpr BitsType() = default; |
| |
| // Constructs an instance of |BitsType| from an underlying primitive value, |
| // preserving any bit member not defined in the FIDL schema. |
| explicit constexpr BitsType(uint32_t value) : value_(value) {} |
| const static BitsType kValue; |
| const static BitsType kTrue; |
| const static BitsType 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 BitsType& other) const { return value_ == other.value_; } |
| constexpr inline bool operator!=(const BitsType& other) const { return value_ != other.value_; } |
| constexpr inline BitsType operator~() const; |
| constexpr inline BitsType operator|(const BitsType& other) const; |
| constexpr inline BitsType operator&(const BitsType& other) const; |
| constexpr inline BitsType operator^(const BitsType& other) const; |
| constexpr inline BitsType operator-(const BitsType& other) const; |
| constexpr inline void operator|=(const BitsType& other); |
| constexpr inline void operator&=(const BitsType& other); |
| constexpr inline void operator^=(const BitsType& other); |
| constexpr inline void operator-=(const BitsType& other); |
| |
| // Constructs an instance of |BitsType| 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<BitsType> TryFrom(uint32_t value) { |
| if (value & ~kMask.value_) { |
| return std::nullopt; |
| } |
| return BitsType(value & BitsType::kMask.value_); |
| } |
| |
| // Constructs an instance of |BitsType| from an underlying primitive value, |
| // clearing any bit member not defined in the FIDL schema. |
| constexpr inline static BitsType TruncatingUnknown(uint32_t value) { |
| return BitsType(value & BitsType::kMask.value_); |
| } |
| |
| private: |
| uint32_t value_ = 0; |
| }; |
| constexpr const ::test_consts::BitsType BitsType::kValue = |
| ::test_consts::BitsType(1u); |
| constexpr const ::test_consts::BitsType BitsType::kTrue = |
| ::test_consts::BitsType(2u); |
| constexpr const ::test_consts::BitsType BitsType::kMask = ::test_consts::BitsType(3u); |
| |
| constexpr inline ::test_consts::BitsType BitsType::operator~() const { |
| return ::test_consts::BitsType(static_cast<uint32_t>(~this->value_ & kMask.value_)); |
| } |
| |
| constexpr inline ::test_consts::BitsType BitsType::operator|( |
| const ::test_consts::BitsType& other) const { |
| return ::test_consts::BitsType(static_cast<uint32_t>(this->value_ | other.value_)); |
| } |
| |
| constexpr inline ::test_consts::BitsType BitsType::operator&( |
| const ::test_consts::BitsType& other) const { |
| return ::test_consts::BitsType(static_cast<uint32_t>(this->value_ & other.value_)); |
| } |
| |
| constexpr inline ::test_consts::BitsType BitsType::operator^( |
| const ::test_consts::BitsType& other) const { |
| return ::test_consts::BitsType(static_cast<uint32_t>(this->value_ ^ other.value_)); |
| } |
| |
| constexpr inline ::test_consts::BitsType BitsType::operator-( |
| const ::test_consts::BitsType& other) const { |
| return ::test_consts::BitsType(static_cast<uint32_t>(this->value_ & ~other.value_)); |
| } |
| |
| constexpr inline void BitsType::operator|=( |
| const ::test_consts::BitsType& other) { |
| this->value_ |= other.value_; |
| } |
| |
| constexpr inline void BitsType::operator&=( |
| const ::test_consts::BitsType& other) { |
| this->value_ &= other.value_; |
| } |
| |
| constexpr inline void BitsType::operator^=( |
| const ::test_consts::BitsType& other) { |
| this->value_ ^= other.value_; |
| } |
| |
| constexpr inline void BitsType::operator-=( |
| const ::test_consts::BitsType& other) { |
| this->value_ &= ~other.value_; |
| } |
| |
| enum class EnumType : int32_t { |
| |
| kValue = 1u, |
| |
| kTrue = 2u, |
| }; |
| |
| } // namespace test_consts |
| |
| template <> |
| struct fidl::internal::DisplayError<::test_consts::EnumType> { |
| static size_t Format(const ::test_consts::EnumType& value, char* destination, size_t capacity); |
| }; |
| |
| namespace fidl { |
| |
| constexpr inline auto ToUnderlying(::test_consts::EnumType value) -> int32_t { |
| return static_cast<int32_t>(value); |
| } |
| |
| template <> |
| struct IsFidlType<::test_consts::BitsType> : public std::true_type {}; |
| template <> |
| struct ContainsHandle<::test_consts::BitsType> : public std::false_type {}; |
| static_assert(std::is_standard_layout_v<::test_consts::BitsType>); |
| static_assert(sizeof(::test_consts::BitsType) == sizeof(uint32_t)); |
| |
| template <> |
| struct IsFidlType<::test_consts::EnumType> : public std::true_type {}; |
| template <> |
| struct ContainsHandle<::test_consts::EnumType> : public std::false_type {}; |
| |
| #pragma clang diagnostic pop |
| |
| } // namespace fidl |