modifying bitmask to allow specifying an explicit value, and changing to uint instead of uint8
This commit is contained in:
@@ -11,18 +11,18 @@ To use this, set constants like thus:
|
||||
"r00t2.io/goutils/bitmask"
|
||||
)
|
||||
|
||||
const OPTNONE types.MaskBit = 0
|
||||
const OPTNONE bitmask.MaskBit = 0
|
||||
const (
|
||||
OPT1 types.MaskBit = 1 << iota
|
||||
OPT1 bitmask.MaskBit = 1 << iota
|
||||
OPT2
|
||||
OPT3
|
||||
// ...
|
||||
)
|
||||
|
||||
var MyMask *MaskBit
|
||||
var MyMask *bitmask.MaskBit
|
||||
|
||||
func main() {
|
||||
MyMask = types.NewMaskBit
|
||||
MyMask = bitmask.NewMaskBit()
|
||||
|
||||
MyMask.AddFlag(OPT1)
|
||||
MyMask.AddFlag(OPT3)
|
||||
@@ -41,5 +41,13 @@ As would this:
|
||||
But this would return false:
|
||||
|
||||
MyMask.HasFlag(OPT2)
|
||||
|
||||
If you need something with more flexibility (as always, at the cost of complexity),
|
||||
you may be interested in one of the following libraries:
|
||||
|
||||
. github.com/alvaroloes/enumer
|
||||
. github.com/abice/go-enum
|
||||
. github.com/jeffreyrichter/enum/enum
|
||||
|
||||
*/
|
||||
package bitmask
|
||||
|
||||
Reference in New Issue
Block a user