gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/flag/flag.go (about)

     1  package flag
     2  
     3  import "gitee.com/sy_183/go-common/generic"
     4  
     5  func TestFlag[F generic.Integer](flag F, mask F) bool {
     6  	return flag&mask != 0
     7  }
     8  
     9  func MaskFlag[F generic.Integer](flag F, mask F) F {
    10  	return flag | mask
    11  }
    12  
    13  func SetFlag[F generic.Integer](flagP *F, enable bool, mask F) {
    14  	if enable {
    15  		*flagP |= mask
    16  	} else {
    17  		*flagP &= ^mask
    18  	}
    19  }
    20  
    21  func MaskFlagP[F generic.Integer](flagP *F, mask F) {
    22  	*flagP |= mask
    23  }
    24  
    25  func UnmaskFlag[F generic.Integer](flag F, mask F) F {
    26  	return flag & ^mask
    27  }
    28  
    29  func UnmaskFlagP[F generic.Integer](flagP *F, mask F) {
    30  	*flagP &= ^mask
    31  }
    32  
    33  func SwapFlagMask[F generic.Integer](flag F, unmask, mask F) F {
    34  	return (flag & ^unmask) | mask
    35  }
    36  
    37  func SwapFlagPMask[F generic.Integer](flagP *F, unmask, mask F) {
    38  	*flagP = (*flagP & ^unmask) | mask
    39  }