#pragma once #include #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) const { return this->value_ == other.value_; } bool operator!=(const FlagsEnum &other) const { return this->value_ != other.value_; } void set(T flag) { reinterpret_cast(this->value_) |= static_cast(flag); } /** Adds the flags from `flags` in this enum. */ void set(FlagsEnum flags) { reinterpret_cast(this->value_) |= static_cast(flags.value_); } 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); } FlagsEnum operator|(T flag) { FlagsEnum xd; xd.value_ = this->value_; xd.set(flag, true); return xd; } FlagsEnum operator|(FlagsEnum rhs) { return static_cast(static_cast(this->value_) | static_cast(rhs.value_)); } 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); } T value() const { return this->value_; } private: T value_{}; }; } // namespace chatterino