| // WARNING: This file is machine generated by fidlgen. |
| |
| #pragma once |
| |
| #include <lib/fidl/llcpp/internal/display_error.h> |
| #include <lib/fidl/llcpp/traits.h> |
| #include <lib/stdcompat/optional.h> |
| |
| #include <cinttypes> |
| |
| namespace test_bitsconstants { |
| // |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 kA; |
| const static BitsType kB; |
| const static BitsType kC; |
| 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 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_bitsconstants::BitsType BitsType::kA = |
| ::test_bitsconstants::BitsType(1u); |
| constexpr const ::test_bitsconstants::BitsType BitsType::kB = |
| ::test_bitsconstants::BitsType(128u); |
| constexpr const ::test_bitsconstants::BitsType BitsType::kC = |
| ::test_bitsconstants::BitsType(2u); |
| constexpr const ::test_bitsconstants::BitsType BitsType::kMask = ::test_bitsconstants::BitsType(131u); |
| |
| constexpr inline ::test_bitsconstants::BitsType BitsType::operator~() const { |
| return ::test_bitsconstants::BitsType(static_cast<uint32_t>(~this->value_ & kMask.value_)); |
| } |
| |
| constexpr inline ::test_bitsconstants::BitsType BitsType::operator|( |
| const ::test_bitsconstants::BitsType& other) const { |
| return ::test_bitsconstants::BitsType(static_cast<uint32_t>(this->value_ | other.value_)); |
| } |
| |
| constexpr inline ::test_bitsconstants::BitsType BitsType::operator&( |
| const ::test_bitsconstants::BitsType& other) const { |
| return ::test_bitsconstants::BitsType(static_cast<uint32_t>(this->value_ & other.value_)); |
| } |
| |
| constexpr inline ::test_bitsconstants::BitsType BitsType::operator^( |
| const ::test_bitsconstants::BitsType& other) const { |
| return ::test_bitsconstants::BitsType(static_cast<uint32_t>(this->value_ ^ other.value_)); |
| } |
| |
| constexpr inline void BitsType::operator|=( |
| const ::test_bitsconstants::BitsType& other) { |
| this->value_ |= other.value_; |
| } |
| |
| constexpr inline void BitsType::operator&=( |
| const ::test_bitsconstants::BitsType& other) { |
| this->value_ &= other.value_; |
| } |
| |
| constexpr inline void BitsType::operator^=( |
| const ::test_bitsconstants::BitsType& other) { |
| this->value_ ^= other.value_; |
| } |
| |
| } // namespace test_bitsconstants |
| namespace fidl { |
| |
| template <> |
| struct IsFidlType<::test_bitsconstants::BitsType> : public std::true_type {}; |
| template <> |
| struct ContainsHandle<::test_bitsconstants::BitsType> : public std::false_type {}; |
| static_assert(std::is_standard_layout_v<::test_bitsconstants::BitsType>); |
| static_assert(sizeof(::test_bitsconstants::BitsType) == sizeof(uint32_t)); |
| |
| } // namespace fidl |