diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 1f3ecf844..28b182a2a 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h @@ -201,4 +201,44 @@ private: static_assert(bits > 0, "Invalid number of bits"); static_assert(std::is_standard_layout::value, "Invalid base type"); }; + +/** + * Abstract bit flag class. This is basically a specialization of BitField for single-bit fields. + * Instead of being cast to the underlying type, it acts like a boolean. + */ +template +struct BitFlag : protected BitField +{ +private: + BitFlag(T val) = delete; + + typedef BitField ParentType; + +public: + BitFlag() = default; + +#ifndef _WIN32 + BitFlag& operator=(const BitFlag&) = delete; +#endif + + __forceinline BitFlag& operator=(bool val) + { + Assign(val); + return *this; + } + + __forceinline operator bool() const + { + return Value(); + } + + __forceinline void Assign(bool value) { + ParentType::Assign(value); + } + + __forceinline bool Value() const + { + return ParentType::Value() != 0; + } +}; #pragma pack()