go_goutils/types/bitmasks.go

34 lines
465 B
Go
Raw Normal View History

2021-02-26 15:52:29 -05:00
package types
type BitMask interface {
HasFlag(bit MaskBit) bool
AddFlag(bit MaskBit)
ClearFlag(bit MaskBit)
ToggleFlag(bit MaskBit)
}
// BitMasks
type MaskBit uint8
func (f MaskBit) HasFlag(flag MaskBit) (r bool) {
if f&flag != 0 {
r = true
}
return
}
func (f *MaskBit) AddFlag(flag MaskBit) {
*f |= flag
return
}
func (f *MaskBit) ClearFlag(flag MaskBit) {
*f &= flag
return
}
func (f *MaskBit) ToggleFlag(flag MaskBit) {
*f ^= flag
return
}