From b7ac4cb54e2c3ffed4a4e70501b328a8ff6dce34 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 8 Jul 2015 22:52:21 -0400 Subject: [PATCH] bit_field: Ported over 'BitFlag' from nihstro. --- src/common/bit_field.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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()