diff options
author | rtk0c <[email protected]> | 2022-05-30 17:03:20 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-05-30 17:03:20 -0700 |
commit | e66286ebe30afc9acc4531fc2bea29b7fb924f93 (patch) | |
tree | fa6b76554c3eb88bc8f088fbab68e20c40118ca7 /source-common/Enum.hpp | |
parent | 366ef5a5450c6e0e680c924c3454943a9ae9814d (diff) |
Changeset: 56 Buildsystem cleanup: change to layered structure for different targets
Diffstat (limited to 'source-common/Enum.hpp')
-rw-r--r-- | source-common/Enum.hpp | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/source-common/Enum.hpp b/source-common/Enum.hpp deleted file mode 100644 index 8ad75ba..0000000 --- a/source-common/Enum.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -#include <initializer_list> -#include <type_traits> - -template <class TEnum> -class EnumFlags { -public: - using Enum = TEnum; - using Underlying = std::underlying_type_t<TEnum>; - -private: - Underlying mValue; - -public: - EnumFlags() - : mValue{ 0 } { - } - - EnumFlags(TEnum e) - : mValue{ static_cast<Underlying>(1) << static_cast<Underlying>(e) } { - } - - bool IsSet(EnumFlags mask) const { - return (mValue & mask.mValue) == mask.mValue; - } - - bool IsSet(std::initializer_list<TEnum> enums) { - EnumFlags flags; - for (auto& e : enums) { - flags.mValue |= static_cast<Underlying>(e); - } - return IsSet(flags); - } - - bool IsSetExclusive(EnumFlags mask) const { - return mValue == mask.mValue; - } - - bool IsSetExclusive(std::initializer_list<TEnum> enums) { - EnumFlags flags; - for (auto& e : enums) { - flags.mValue |= static_cast<Underlying>(e); - } - return IsSetExclusive(flags); - } - - void SetOn(EnumFlags mask) { - mValue |= mask.mValue; - } - - void SetOff(EnumFlags mask) { - mValue &= ~mask.mValue; - } - - void Set(EnumFlags mask, bool enabled) { - if (enabled) { - SetOn(mask); - } else { - SetOff(mask); - } - } - - EnumFlags& operator|=(EnumFlags that) { - mValue |= that.mValue; - return *this; - } - - EnumFlags& operator&=(EnumFlags that) { - mValue &= that.mValue; - return *this; - } - - EnumFlags& operator^=(EnumFlags that) { - mValue ^= that.mValue; - return *this; - } - - EnumFlags& operator|=(TEnum e) { - mValue |= 1 << static_cast<Underlying>(e); - return *this; - } - - EnumFlags& operator&=(TEnum e) { - mValue &= 1 << static_cast<Underlying>(e); - return *this; - } - - EnumFlags& operator^=(TEnum e) { - mValue ^= 1 << static_cast<Underlying>(e); - return *this; - } - - EnumFlags operator|(EnumFlags that) const { return EnumFlags(mValue | that.mValue); } - EnumFlags operator&(EnumFlags that) const { return EnumFlags(mValue & that.mValue); } - EnumFlags operator^(EnumFlags that) const { return EnumFlags(mValue ^ that.mValue); } - - EnumFlags operator|(TEnum e) const { return EnumFlags(mValue | 1 << static_cast<Underlying>(e)); } - EnumFlags operator&(TEnum e) const { return EnumFlags(mValue & 1 << static_cast<Underlying>(e)); } - EnumFlags operator^(TEnum e) const { return EnumFlags(mValue ^ 1 << static_cast<Underlying>(e)); } - - EnumFlags operator~() const { return EnumFlags(~mValue); } -}; |