-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumgen.go
126 lines (107 loc) · 2.57 KB
/
enumgen.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Code generated by "goki generate -add-types"; DO NOT EDIT.
package histyle
import (
"errors"
"log"
"strconv"
"strings"
"goki.dev/enums"
)
var _TrileanValues = []Trilean{0, 1, 2}
// TrileanN is the highest valid value
// for type Trilean, plus one.
const TrileanN Trilean = 3
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the enumgen command to generate them again.
func _TrileanNoOp() {
var x [1]struct{}
_ = x[Pass-(0)]
_ = x[Yes-(1)]
_ = x[No-(2)]
}
var _TrileanNameToValueMap = map[string]Trilean{
`Pass`: 0,
`pass`: 0,
`Yes`: 1,
`yes`: 1,
`No`: 2,
`no`: 2,
}
var _TrileanDescMap = map[Trilean]string{
0: ``,
1: ``,
2: ``,
}
var _TrileanMap = map[Trilean]string{
0: `Pass`,
1: `Yes`,
2: `No`,
}
// String returns the string representation
// of this Trilean value.
func (i Trilean) String() string {
if str, ok := _TrileanMap[i]; ok {
return str
}
return strconv.FormatInt(int64(i), 10)
}
// SetString sets the Trilean value from its
// string representation, and returns an
// error if the string is invalid.
func (i *Trilean) SetString(s string) error {
if val, ok := _TrileanNameToValueMap[s]; ok {
*i = val
return nil
}
if val, ok := _TrileanNameToValueMap[strings.ToLower(s)]; ok {
*i = val
return nil
}
return errors.New(s + " is not a valid value for type Trilean")
}
// Int64 returns the Trilean value as an int64.
func (i Trilean) Int64() int64 {
return int64(i)
}
// SetInt64 sets the Trilean value from an int64.
func (i *Trilean) SetInt64(in int64) {
*i = Trilean(in)
}
// Desc returns the description of the Trilean value.
func (i Trilean) Desc() string {
if str, ok := _TrileanDescMap[i]; ok {
return str
}
return i.String()
}
// TrileanValues returns all possible values
// for the type Trilean.
func TrileanValues() []Trilean {
return _TrileanValues
}
// Values returns all possible values
// for the type Trilean.
func (i Trilean) Values() []enums.Enum {
res := make([]enums.Enum, len(_TrileanValues))
for i, d := range _TrileanValues {
res[i] = d
}
return res
}
// IsValid returns whether the value is a
// valid option for type Trilean.
func (i Trilean) IsValid() bool {
_, ok := _TrileanMap[i]
return ok
}
// MarshalText implements the [encoding.TextMarshaler] interface.
func (i Trilean) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (i *Trilean) UnmarshalText(text []byte) error {
if err := i.SetString(string(text)); err != nil {
log.Println(err)
}
return nil
}