#pragma once #include namespace chatterino { // = std::enable_if::value>::type template ::type> class FlagsEnum { public: FlagsEnum() : value(static_cast(0)) { } FlagsEnum(T value) : value(value) { } FlagsEnum(std::initializer_list flags) { for (auto flag : flags) { this->set(flag); } } bool operator==(const FlagsEnum &other) { return this->value == other.value; } bool operator!=(const FlagsEnum &other) { return this->value != other.value; } void set(T flag) { reinterpret_cast(this->value) |= static_cast(flag); } void unset(T flag) { reinterpret_cast(this->value) &= ~static_cast(flag); } void set(T flag, bool value) { if (value) this->set(flag); else this->unset(flag); } bool has(T flag) const { return static_cast(this->value) & static_cast(flag); } // bool hasAny(std::initializer_list flags) const //{ // for (auto flag : flags) { // if (this->has(flag)) return true; // } // return false; //} bool hasAny(FlagsEnum flags) const { return static_cast(this->value) & static_cast(flags.value); } // bool hasAll(std::initializer_list flags) const //{ // for (auto flag : flags) { // if (!this->has(flag)) return false; // } // return true; //} bool hasAll(FlagsEnum flags) const { return (static_cast(this->value) & static_cast(flags.value)) && static_cast(flags->value); } bool hasNone(std::initializer_list flags) const { return !this->hasAny(flags); } private: T value; }; } // namespace chatterino