adding small usage note for bitmasks

This commit is contained in:
brent s 2021-07-27 22:30:10 -04:00
parent 0887f0c76e
commit d5b1d449e5
Signed by: bts
GPG Key ID: 8C004C2F93481F6B

View File

@ -1,5 +1,36 @@
package types package types


/*
See https://yourbasic.org/golang/bitmask-flag-set-clear/ for more information.
To use this, set constants like thus:
const (
OPT1 types.MaskBit = 1 << iota
OPT2
OPT3
// ...
)

type Object struct {
Opts BitMask
}

o := Object{
BitMask: uint8(0)
}

o.AddFlag(OPT1)
o.AddFlag(OPT3)


This would return true:
o.HasFlag(OPT1)
As would this:
o.HasFlag(OPT3)
But this would return false:
o.HasFlag(OPT2)

*/
type BitMask interface { type BitMask interface {
HasFlag(bit MaskBit) bool HasFlag(bit MaskBit) bool
AddFlag(bit MaskBit) AddFlag(bit MaskBit)