2017-10-11 21:44:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
2017-11-07 15:10:38 +01:00
|
|
|
#include "util_bit.h"
|
|
|
|
|
2017-10-11 21:44:02 +02:00
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Flags {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
using IntType = std::underlying_type_t<T>;
|
|
|
|
|
|
|
|
Flags() { }
|
|
|
|
|
2017-10-29 02:35:16 +02:00
|
|
|
Flags(IntType t)
|
|
|
|
: m_bits(t) { }
|
|
|
|
|
2017-10-11 21:44:02 +02:00
|
|
|
template<typename... Tx>
|
|
|
|
Flags(T f, Tx... fx) {
|
|
|
|
this->set(f, fx...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Tx>
|
|
|
|
void set(Tx... fx) {
|
|
|
|
m_bits |= bits(fx...);
|
|
|
|
}
|
|
|
|
|
2018-01-16 13:58:57 +01:00
|
|
|
void set(Flags flags) {
|
|
|
|
m_bits |= flags.m_bits;
|
|
|
|
}
|
|
|
|
|
2017-10-11 21:44:02 +02:00
|
|
|
template<typename... Tx>
|
|
|
|
void clr(Tx... fx) {
|
|
|
|
m_bits &= ~bits(fx...);
|
|
|
|
}
|
|
|
|
|
2018-01-16 13:58:57 +01:00
|
|
|
void clr(Flags flags) {
|
|
|
|
m_bits &= ~flags.m_bits;
|
|
|
|
}
|
|
|
|
|
2017-10-11 21:44:02 +02:00
|
|
|
template<typename... Tx>
|
|
|
|
bool any(Tx... fx) const {
|
|
|
|
return (m_bits & bits(fx...)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Tx>
|
|
|
|
bool all(Tx... fx) const {
|
|
|
|
const IntType mask = bits(fx...);
|
|
|
|
return (m_bits & mask) == mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test(T f) const {
|
|
|
|
return this->any(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isClear() const {
|
|
|
|
return m_bits == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clrAll() {
|
|
|
|
m_bits = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-07 15:10:38 +01:00
|
|
|
uint32_t raw() const {
|
|
|
|
return m_bits;
|
|
|
|
}
|
|
|
|
|
2017-10-11 21:44:02 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
IntType m_bits = 0;
|
|
|
|
|
|
|
|
static IntType bit(T f) {
|
|
|
|
return IntType(1) << static_cast<IntType>(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Tx>
|
|
|
|
static IntType bits(T f, Tx... fx) {
|
|
|
|
return bit(f) | bits(fx...);
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntType bits() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|