2023-10-31 22:58:28 +01:00
|
|
|
// Code generated by enum-generate.go DO NOT EDIT.
|
|
|
|
|
|
|
|
package {{.PkgName}}
|
|
|
|
|
|
|
|
import "gogs.mikescher.com/BlackForestBytes/goext/langext"
|
|
|
|
import "gogs.mikescher.com/BlackForestBytes/goext/enums"
|
|
|
|
|
|
|
|
const ChecksumEnumGenerator = "{{.Checksum}}" // GoExtVersion: {{.GoextVersion}}
|
|
|
|
|
|
|
|
{{range .Enums}}
|
|
|
|
|
|
|
|
{{ $hasStr := ( . | hasStr ) }}
|
|
|
|
{{ $hasDescr := ( . | hasDescr ) }}
|
2023-12-07 17:57:06 +01:00
|
|
|
{{ $hasData := ( . | hasData ) }}
|
2023-10-31 22:58:28 +01:00
|
|
|
|
|
|
|
// ================================ {{.EnumTypeName}} ================================
|
|
|
|
//
|
|
|
|
// File: {{.FileRelative}}
|
|
|
|
// StringEnum: {{$hasStr | boolToStr}}
|
|
|
|
// DescrEnum: {{$hasDescr | boolToStr}}
|
2023-12-07 17:57:06 +01:00
|
|
|
// DataEnum: {{$hasData | boolToStr}}
|
2023-10-31 22:58:28 +01:00
|
|
|
//
|
|
|
|
|
2023-12-07 17:57:06 +01:00
|
|
|
{{ $typename := .EnumTypeName }}
|
|
|
|
{{ $enumdef := . }}
|
|
|
|
|
2023-10-31 22:58:28 +01:00
|
|
|
var __{{.EnumTypeName}}Values = []{{.EnumTypeName}}{ {{range .Values}}
|
|
|
|
{{.VarName}}, {{end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{if $hasDescr}}
|
|
|
|
var __{{.EnumTypeName}}Descriptions = map[{{.EnumTypeName}}]string{ {{range .Values}}
|
2023-12-07 17:57:06 +01:00
|
|
|
{{.VarName}}: {{.Description | deref | trimSpace | gostr}}, {{end}}
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{if $hasData}}
|
|
|
|
type {{ .EnumTypeName }}Data struct { {{ range $datakey, $datatype := ($enumdef | generalDataKeys) }}
|
|
|
|
{{ $datakey | godatakey }} {{ $datatype }} `json:"{{ $datakey }}"` {{ end }}
|
|
|
|
}
|
|
|
|
|
|
|
|
var __{{.EnumTypeName}}Data = map[{{.EnumTypeName}}]{{.EnumTypeName}}Data{ {{range .Values}} {{ $enumvalue := . }}
|
|
|
|
{{.VarName}}: {{ $typename }}Data{ {{ range $datakey, $datatype := $enumdef | generalDataKeys }}
|
|
|
|
{{ $datakey | godatakey }}: {{ (mapindex $enumvalue.Data $datakey) | godatavalue }}, {{ end }}
|
|
|
|
}, {{end}}
|
2023-10-31 22:58:28 +01:00
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
var __{{.EnumTypeName}}Varnames = map[{{.EnumTypeName}}]string{ {{range .Values}}
|
|
|
|
{{.VarName}}: "{{.VarName}}", {{end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e {{.EnumTypeName}}) Valid() bool {
|
|
|
|
return langext.InArray(e, __{{.EnumTypeName}}Values)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e {{.EnumTypeName}}) Values() []{{.EnumTypeName}} {
|
|
|
|
return __{{.EnumTypeName}}Values
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e {{.EnumTypeName}}) ValuesAny() []any {
|
|
|
|
return langext.ArrCastToAny(__{{.EnumTypeName}}Values)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e {{.EnumTypeName}}) ValuesMeta() []enums.EnumMetaValue {
|
|
|
|
return {{.EnumTypeName}}ValuesMeta()
|
|
|
|
}
|
|
|
|
|
|
|
|
{{if $hasStr}}
|
|
|
|
func (e {{.EnumTypeName}}) String() string {
|
|
|
|
return string(e)
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{if $hasDescr}}
|
|
|
|
func (e {{.EnumTypeName}}) Description() string {
|
|
|
|
if d, ok := __{{.EnumTypeName}}Descriptions[e]; ok {
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
2023-12-07 17:57:06 +01:00
|
|
|
{{if $hasData}}
|
|
|
|
func (e {{.EnumTypeName}}) Data() {{.EnumTypeName}}Data {
|
|
|
|
if d, ok := __{{.EnumTypeName}}Data[e]; ok {
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
return {{.EnumTypeName}}Data{}
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
2023-10-31 22:58:28 +01:00
|
|
|
func (e {{.EnumTypeName}}) VarName() string {
|
|
|
|
if d, ok := __{{.EnumTypeName}}Varnames[e]; ok {
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e {{.EnumTypeName}}) Meta() enums.EnumMetaValue {
|
|
|
|
{{if $hasDescr}} return enums.EnumMetaValue{VarName: e.VarName(), Value: e, Description: langext.Ptr(e.Description())} {{else}} return enums.EnumMetaValue{VarName: e.VarName(), Value: e, Description: nil} {{end}}
|
|
|
|
}
|
|
|
|
|
2023-12-05 19:38:03 +01:00
|
|
|
{{if $hasDescr}}
|
|
|
|
func (e {{.EnumTypeName}}) DescriptionMeta() enums.EnumDescriptionMetaValue {
|
2023-12-05 19:42:37 +01:00
|
|
|
return enums.EnumDescriptionMetaValue{VarName: e.VarName(), Value: e, Description: e.Description()}
|
2023-12-05 19:38:03 +01:00
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
2023-10-31 22:58:28 +01:00
|
|
|
func Parse{{.EnumTypeName}}(vv string) ({{.EnumTypeName}}, bool) {
|
|
|
|
for _, ev := range __{{.EnumTypeName}}Values {
|
|
|
|
if string(ev) == vv {
|
|
|
|
return ev, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
|
|
|
|
func {{.EnumTypeName}}Values() []{{.EnumTypeName}} {
|
|
|
|
return __{{.EnumTypeName}}Values
|
|
|
|
}
|
|
|
|
|
|
|
|
func {{.EnumTypeName}}ValuesMeta() []enums.EnumMetaValue {
|
|
|
|
return []enums.EnumMetaValue{ {{range .Values}}
|
|
|
|
{{.VarName}}.Meta(), {{end}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-05 19:38:03 +01:00
|
|
|
{{if $hasDescr}}
|
2023-12-05 19:45:35 +01:00
|
|
|
func {{.EnumTypeName}}ValuesDescriptionMeta() []enums.EnumDescriptionMetaValue {
|
2023-12-05 19:42:37 +01:00
|
|
|
return []enums.EnumDescriptionMetaValue{ {{range .Values}}
|
2023-12-05 19:50:24 +01:00
|
|
|
{{.VarName}}.DescriptionMeta(), {{end}}
|
2023-12-05 19:38:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
2023-10-31 22:58:28 +01:00
|
|
|
{{end}}
|