-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumgen.go
381 lines (338 loc) · 9.03 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
// Code generated by "goki generate"; DO NOT EDIT.
package filetree
import (
"fmt"
"log"
"strconv"
"strings"
"sync/atomic"
"goki.dev/enums"
"goki.dev/gi/v2/giv"
)
var _DirFlagsValues = []DirFlags{0, 1, 2, 3}
// DirFlagsN is the highest valid value
// for type DirFlags, plus one.
const DirFlagsN DirFlags = 4
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the enumgen command to generate them again.
func _DirFlagsNoOp() {
var x [1]struct{}
_ = x[DirMark-(0)]
_ = x[DirIsOpen-(1)]
_ = x[DirSortByName-(2)]
_ = x[DirSortByModTime-(3)]
}
var _DirFlagsNameToValueMap = map[string]DirFlags{
`Mark`: 0,
`mark`: 0,
`IsOpen`: 1,
`isopen`: 1,
`SortByName`: 2,
`sortbyname`: 2,
`SortByModTime`: 3,
`sortbymodtime`: 3,
}
var _DirFlagsDescMap = map[DirFlags]string{
0: `DirMark means directory is marked -- unmarked entries are deleted post-update`,
1: `DirIsOpen means directory is open -- else closed`,
2: `DirSortByName means sort the directory entries by name. this is mutex with other sorts -- keeping option open for non-binary sort choices.`,
3: `DirSortByModTime means sort the directory entries by modification time`,
}
var _DirFlagsMap = map[DirFlags]string{
0: `Mark`,
1: `IsOpen`,
2: `SortByName`,
3: `SortByModTime`,
}
// String returns the string representation
// of this DirFlags value.
func (i DirFlags) String() string {
str := ""
for _, ie := range _DirFlagsValues {
if i.HasFlag(ie) {
ies := ie.BitIndexString()
if str == "" {
str = ies
} else {
str += "|" + ies
}
}
}
return str
}
// BitIndexString returns the string
// representation of this DirFlags value
// if it is a bit index value
// (typically an enum constant), and
// not an actual bit flag value.
func (i DirFlags) BitIndexString() string {
if str, ok := _DirFlagsMap[i]; ok {
return str
}
return strconv.FormatInt(int64(i), 10)
}
// SetString sets the DirFlags value from its
// string representation, and returns an
// error if the string is invalid.
func (i *DirFlags) SetString(s string) error {
*i = 0
return i.SetStringOr(s)
}
// SetStringOr sets the DirFlags value from its
// string representation while preserving any
// bit flags already set, and returns an
// error if the string is invalid.
func (i *DirFlags) SetStringOr(s string) error {
flgs := strings.Split(s, "|")
for _, flg := range flgs {
if val, ok := _DirFlagsNameToValueMap[flg]; ok {
i.SetFlag(true, &val)
} else if val, ok := _DirFlagsNameToValueMap[strings.ToLower(flg)]; ok {
i.SetFlag(true, &val)
} else if flg == "" {
continue
} else {
return fmt.Errorf("%q is not a valid value for type DirFlags", flg)
}
}
return nil
}
// Int64 returns the DirFlags value as an int64.
func (i DirFlags) Int64() int64 {
return int64(i)
}
// SetInt64 sets the DirFlags value from an int64.
func (i *DirFlags) SetInt64(in int64) {
*i = DirFlags(in)
}
// Desc returns the description of the DirFlags value.
func (i DirFlags) Desc() string {
if str, ok := _DirFlagsDescMap[i]; ok {
return str
}
return i.String()
}
// DirFlagsValues returns all possible values
// for the type DirFlags.
func DirFlagsValues() []DirFlags {
return _DirFlagsValues
}
// Values returns all possible values
// for the type DirFlags.
func (i DirFlags) Values() []enums.Enum {
res := make([]enums.Enum, len(_DirFlagsValues))
for i, d := range _DirFlagsValues {
res[i] = d
}
return res
}
// IsValid returns whether the value is a
// valid option for type DirFlags.
func (i DirFlags) IsValid() bool {
_, ok := _DirFlagsMap[i]
return ok
}
// HasFlag returns whether these
// bit flags have the given bit flag set.
func (i DirFlags) HasFlag(f enums.BitFlag) bool {
return atomic.LoadInt64((*int64)(&i))&(1<<uint32(f.Int64())) != 0
}
// SetFlag sets the value of the given
// flags in these flags to the given value.
func (i *DirFlags) SetFlag(on bool, f ...enums.BitFlag) {
var mask int64
for _, v := range f {
mask |= 1 << v.Int64()
}
in := int64(*i)
if on {
in |= mask
atomic.StoreInt64((*int64)(i), in)
} else {
in &^= mask
atomic.StoreInt64((*int64)(i), in)
}
}
// MarshalText implements the [encoding.TextMarshaler] interface.
func (i DirFlags) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (i *DirFlags) UnmarshalText(text []byte) error {
if err := i.SetString(string(text)); err != nil {
log.Println(err)
}
return nil
}
var _NodeFlagsValues = []NodeFlags{11, 12}
// NodeFlagsN is the highest valid value
// for type NodeFlags, plus one.
const NodeFlagsN NodeFlags = 13
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the enumgen command to generate them again.
func _NodeFlagsNoOp() {
var x [1]struct{}
_ = x[NodeOpen-(11)]
_ = x[NodeSymLink-(12)]
}
var _NodeFlagsNameToValueMap = map[string]NodeFlags{
`Open`: 11,
`open`: 11,
`SymLink`: 12,
`symlink`: 12,
}
var _NodeFlagsDescMap = map[NodeFlags]string{
11: `NodeOpen means file is open. For directories, this means that sub-files should be / have been loaded. For files, means that they have been opened e.g., for editing.`,
12: `NodeSymLink indicates that file is a symbolic link. File info is all for the target of the symlink.`,
}
var _NodeFlagsMap = map[NodeFlags]string{
11: `Open`,
12: `SymLink`,
}
// String returns the string representation
// of this NodeFlags value.
func (i NodeFlags) String() string {
str := ""
for _, ie := range giv.TreeViewFlagsValues() {
if i.HasFlag(ie) {
ies := ie.BitIndexString()
if str == "" {
str = ies
} else {
str += "|" + ies
}
}
}
for _, ie := range _NodeFlagsValues {
if i.HasFlag(ie) {
ies := ie.BitIndexString()
if str == "" {
str = ies
} else {
str += "|" + ies
}
}
}
return str
}
// BitIndexString returns the string
// representation of this NodeFlags value
// if it is a bit index value
// (typically an enum constant), and
// not an actual bit flag value.
func (i NodeFlags) BitIndexString() string {
if str, ok := _NodeFlagsMap[i]; ok {
return str
}
return giv.TreeViewFlags(i).BitIndexString()
}
// SetString sets the NodeFlags value from its
// string representation, and returns an
// error if the string is invalid.
func (i *NodeFlags) SetString(s string) error {
*i = 0
return i.SetStringOr(s)
}
// SetStringOr sets the NodeFlags value from its
// string representation while preserving any
// bit flags already set, and returns an
// error if the string is invalid.
func (i *NodeFlags) SetStringOr(s string) error {
flgs := strings.Split(s, "|")
for _, flg := range flgs {
if val, ok := _NodeFlagsNameToValueMap[flg]; ok {
i.SetFlag(true, &val)
} else if val, ok := _NodeFlagsNameToValueMap[strings.ToLower(flg)]; ok {
i.SetFlag(true, &val)
} else if flg == "" {
continue
} else {
err := (*giv.TreeViewFlags)(i).SetStringOr(flg)
if err != nil {
return err
}
}
}
return nil
}
// Int64 returns the NodeFlags value as an int64.
func (i NodeFlags) Int64() int64 {
return int64(i)
}
// SetInt64 sets the NodeFlags value from an int64.
func (i *NodeFlags) SetInt64(in int64) {
*i = NodeFlags(in)
}
// Desc returns the description of the NodeFlags value.
func (i NodeFlags) Desc() string {
if str, ok := _NodeFlagsDescMap[i]; ok {
return str
}
return giv.TreeViewFlags(i).Desc()
}
// NodeFlagsValues returns all possible values
// for the type NodeFlags.
func NodeFlagsValues() []NodeFlags {
es := giv.TreeViewFlagsValues()
res := make([]NodeFlags, len(es))
for i, e := range es {
res[i] = NodeFlags(e)
}
res = append(res, _NodeFlagsValues...)
return res
}
// Values returns all possible values
// for the type NodeFlags.
func (i NodeFlags) Values() []enums.Enum {
es := giv.TreeViewFlagsValues()
les := len(es)
res := make([]enums.Enum, les+len(_NodeFlagsValues))
for i, d := range es {
res[i] = d
}
for i, d := range _NodeFlagsValues {
res[i+les] = d
}
return res
}
// IsValid returns whether the value is a
// valid option for type NodeFlags.
func (i NodeFlags) IsValid() bool {
_, ok := _NodeFlagsMap[i]
if !ok {
return giv.TreeViewFlags(i).IsValid()
}
return ok
}
// HasFlag returns whether these
// bit flags have the given bit flag set.
func (i NodeFlags) HasFlag(f enums.BitFlag) bool {
return atomic.LoadInt64((*int64)(&i))&(1<<uint32(f.Int64())) != 0
}
// SetFlag sets the value of the given
// flags in these flags to the given value.
func (i *NodeFlags) SetFlag(on bool, f ...enums.BitFlag) {
var mask int64
for _, v := range f {
mask |= 1 << v.Int64()
}
in := int64(*i)
if on {
in |= mask
atomic.StoreInt64((*int64)(i), in)
} else {
in &^= mask
atomic.StoreInt64((*int64)(i), in)
}
}
// MarshalText implements the [encoding.TextMarshaler] interface.
func (i NodeFlags) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (i *NodeFlags) UnmarshalText(text []byte) error {
if err := i.SetString(string(text)); err != nil {
log.Println(err)
}
return nil
}