-
Notifications
You must be signed in to change notification settings - Fork 71
/
bitflag.go
45 lines (38 loc) · 1.4 KB
/
bitflag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2023, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package enums provides common interfaces for enums
// and bit flag enums and utilities for using them
package enums
// BitFlag is the interface that all bit flag enum types
// satisfy. Bit flag enum types support all of the operations
// that standard enums do, and additionally can check if they
// have a given bit flag.
type BitFlag interface {
Enum
// Has returns whether these flags
// have the given flag set.
HasFlag(f BitFlag) bool
// BitIndexString returns the string
// representation of the bit flag if
// the bit flag is a bit index value
// (typically an enum constant), and
// not an actual bit flag value.
BitIndexString() string
}
// BitFlagSetter is an expanded interface that all pointers
// to bit flag enum types satisfy. Pointers to bit flag
// enum types must satisfy all of the methods of [EnumSetter]
// and [BitFlag], and must also be able to set a given bit flag.
type BitFlagSetter interface {
EnumSetter
BitFlag
// Set sets the value of the given
// flags in these flags to the given value.
SetFlag(on bool, f ...BitFlag)
// SetStringOr sets the bit flag from its
// string representation while preserving any
// bit flags already set, and returns an
// error if the string is invalid.
SetStringOr(s string) error
}