2020-09-27 01:24:56 +00:00
|
|
|
package repository
|
|
|
|
|
2020-10-09 07:05:25 +00:00
|
|
|
// Enumeration returns a Go enumeration.
|
2020-09-27 01:24:56 +00:00
|
|
|
type Enumeration struct {
|
2020-09-28 01:41:17 +00:00
|
|
|
Comment Comment
|
2020-09-27 01:24:56 +00:00
|
|
|
Name string
|
|
|
|
Values []EnumValue
|
2020-10-09 07:05:25 +00:00
|
|
|
|
|
|
|
// Bitwise is true if the enumeration is a bitwise one. The type would then
|
|
|
|
// be uint32 instead of uint8, allowing for 32 constants. As usual, the
|
|
|
|
// first value of enum must be 0.
|
|
|
|
Bitwise bool
|
2020-09-28 01:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GoType returns uint8 for a normal enum and uint32 for a bitwise enum. It
|
|
|
|
// returns an empty string if the length of values is overbound.
|
|
|
|
//
|
|
|
|
// The maximum number of values in a normal enum is math.MaxUint8 or 255. The
|
|
|
|
// maximum number of values in a bitwise enum is 32 for 32 bits in a uint32.
|
|
|
|
func (e Enumeration) GoType() string {
|
|
|
|
if !e.Bitwise {
|
|
|
|
if len(e.Values) > 255 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return "uint8"
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(e.Values) > 32 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return "uint32"
|
2020-09-27 01:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type EnumValue struct {
|
2020-09-28 01:41:17 +00:00
|
|
|
Comment Comment
|
|
|
|
Name string // also return value from String()
|
2020-09-27 01:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsPlaceholder returns true if the enumeration value is meant to be a
|
|
|
|
// placeholder. In Go, it would look like this:
|
|
|
|
//
|
|
|
|
// const (
|
|
|
|
// _ EnumType = iota // IsPlaceholder() == true
|
|
|
|
// V1
|
|
|
|
// )
|
|
|
|
//
|
|
|
|
func (v EnumValue) IsPlaceholder() bool {
|
|
|
|
return v.Name == ""
|
|
|
|
}
|