#pragma once #include namespace chatterino { 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(FlagsEnum flags) const { return static_cast(this->value_) & static_cast(flags.value_); } 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