Add more flag operator overloads
This commit is contained in:
parent
2a90cdee18
commit
db5197b3b1
17
flags.hpp
17
flags.hpp
@ -37,17 +37,34 @@ struct [[gnu::packed]] FlagsImpl
|
||||
return *this;
|
||||
}
|
||||
|
||||
FlagsImpl &operator|=(const uint8_t &flag)
|
||||
{
|
||||
data |= flag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FlagsImpl &operator&=(const FlagsT &flag)
|
||||
{
|
||||
data &= static_cast<uint8_t>(flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
FlagsImpl &operator&=(const uint8_t &flag)
|
||||
{
|
||||
data &= flag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FlagsImpl &operator~()
|
||||
{
|
||||
data = ~data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const FlagsT &flag) const
|
||||
{
|
||||
return data & static_cast<uint8_t>(flag);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FlagsT>
|
||||
|
@ -375,6 +375,11 @@ enum class ControlRegFlags : uint8_t {
|
||||
A1IE = 1 << 0,
|
||||
};
|
||||
|
||||
static inline uint8_t operator~(const ControlRegFlags &flag)
|
||||
{
|
||||
return ~static_cast<uint8_t>(flag);
|
||||
}
|
||||
|
||||
struct [[gnu::packed]] ControlReg : FlagsImpl<ControlRegFlags>{};
|
||||
|
||||
static_assert(sizeof(ControlReg) == 1, "Invalid control register size");
|
||||
@ -389,6 +394,11 @@ enum class ControlStatusRegFlags : uint8_t {
|
||||
A1F = 1 << 0,
|
||||
};
|
||||
|
||||
static inline uint8_t operator~(const ControlStatusRegFlags &flag)
|
||||
{
|
||||
return ~static_cast<uint8_t>(flag);
|
||||
}
|
||||
|
||||
struct [[gnu::packed]] ControlStatusReg : FlagsImpl<ControlStatusRegFlags>{};
|
||||
|
||||
static_assert(sizeof(ControlStatusReg) == 1, "Invalid control/status register size");
|
||||
|
Loading…
Reference in New Issue
Block a user