58 lines
1.0 KiB
C++
58 lines
1.0 KiB
C++
#pragma once
|
|
#include <cstdint> // uint8_t
|
|
#include "Bits.h"
|
|
template <typename _Ty>
|
|
class Flag
|
|
{
|
|
public:
|
|
static_assert(std::is_arithmetic<_Ty>::value, "_Ty must be an arithmetic type");
|
|
|
|
typedef _Ty value_type;
|
|
|
|
_Ty value;
|
|
|
|
inline Flag()
|
|
: value()
|
|
{
|
|
}
|
|
|
|
inline Flag(_Ty value)
|
|
: value(value)
|
|
{
|
|
}
|
|
|
|
inline void Set(_Ty value)
|
|
{
|
|
bits::Set(this->value, value);
|
|
}
|
|
|
|
inline void Unset(_Ty value)
|
|
{
|
|
bits::Unset(this->value, value);
|
|
}
|
|
|
|
inline bool Has(_Ty value) const
|
|
{
|
|
return bits::Has(this->value, value);
|
|
}
|
|
};
|
|
|
|
template <typename _Ty>
|
|
struct IsFlag : public std::false_type
|
|
{
|
|
};
|
|
|
|
template <typename _Ty>
|
|
struct IsFlag<Flag<_Ty>> : public std::true_type
|
|
{
|
|
};
|
|
|
|
typedef Flag<uint8_t> FlagUint8;
|
|
typedef Flag<uint16_t> FlagUint16;
|
|
typedef Flag<uint32_t> FlagUint32;
|
|
typedef Flag<uint64_t> FlagUint64;
|
|
typedef Flag<int8_t> FlagInt8;
|
|
typedef Flag<int16_t> FlagInt16;
|
|
typedef Flag<int32_t> FlagInt32;
|
|
typedef Flag<int64_t> FlagInt64;
|