2021-12-15 04:49:03 -05:00
|
|
|
package bitmask
|
|
|
|
|
|
|
|
// MaskBit is a flag container.
|
2022-02-01 15:36:56 -05:00
|
|
|
type MaskBit uint
|
2021-12-15 04:49:03 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
NewMaskBit is a convenience function.
|
|
|
|
It will return a MaskBit with a (referenced) value of 0, so set your consts up accordingly.
|
2022-02-01 15:36:56 -05:00
|
|
|
|
2021-12-15 04:49:03 -05:00
|
|
|
It is highly recommended to set this default as a "None" flag (separate from your iotas!)
|
|
|
|
as shown in the example.
|
|
|
|
*/
|
|
|
|
func NewMaskBit() (m *MaskBit) {
|
|
|
|
|
|
|
|
m = new(MaskBit)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-01 15:36:56 -05:00
|
|
|
// NewMaskBitExplicit is like NewMaskBit, but allows you to specify a non-zero (0x0) value.
|
|
|
|
func NewMaskBitExplicit(value uint) (m *MaskBit) {
|
|
|
|
|
|
|
|
var v MaskBit = MaskBit(value)
|
|
|
|
|
|
|
|
m = &v
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-15 04:49:03 -05:00
|
|
|
// HasFlag is true if m has MaskBit flag set/enabled.
|
|
|
|
func (m *MaskBit) HasFlag(flag MaskBit) (r bool) {
|
|
|
|
|
|
|
|
var b MaskBit = *m
|
|
|
|
|
|
|
|
if b&flag != 0 {
|
|
|
|
r = true
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddFlag adds MaskBit flag to m.
|
|
|
|
func (m *MaskBit) AddFlag(flag MaskBit) {
|
2022-02-01 15:36:56 -05:00
|
|
|
|
2021-12-15 04:49:03 -05:00
|
|
|
*m |= flag
|
2022-02-01 15:36:56 -05:00
|
|
|
|
2021-12-15 04:49:03 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearFlag removes MaskBit flag from m.
|
|
|
|
func (m *MaskBit) ClearFlag(flag MaskBit) {
|
2022-02-01 15:36:56 -05:00
|
|
|
|
2021-12-15 04:49:03 -05:00
|
|
|
*m &= flag
|
2022-02-01 15:36:56 -05:00
|
|
|
|
2021-12-15 04:49:03 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToggleFlag switches MaskBit flag in m to its inverse; if true, it is now false and vice versa.
|
|
|
|
func (m *MaskBit) ToggleFlag(flag MaskBit) {
|
2022-02-01 15:36:56 -05:00
|
|
|
|
2021-12-15 04:49:03 -05:00
|
|
|
*m ^= flag
|
2022-02-01 15:36:56 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Value returns the current raw uint value of a MaskBit.
|
|
|
|
func (m *MaskBit) Value() (v uint) {
|
|
|
|
|
|
|
|
v = uint(*m)
|
|
|
|
|
2021-12-15 04:49:03 -05:00
|
|
|
return
|
|
|
|
}
|