Mike Schwörer
d47c84cd47
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
158 lines
4.2 KiB
Plaintext
158 lines
4.2 KiB
Plaintext
// 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}}
|
|
|
|
{{ $pkgname := .PkgName }}
|
|
|
|
{{range .Enums}}
|
|
|
|
{{ $hasStr := ( . | hasStr ) }}
|
|
{{ $hasDescr := ( . | hasDescr ) }}
|
|
{{ $hasData := ( . | hasData ) }}
|
|
|
|
// ================================ {{.EnumTypeName}} ================================
|
|
//
|
|
// File: {{.FileRelative}}
|
|
// StringEnum: {{$hasStr | boolToStr}}
|
|
// DescrEnum: {{$hasDescr | boolToStr}}
|
|
// DataEnum: {{$hasData | boolToStr}}
|
|
//
|
|
|
|
{{ $typename := .EnumTypeName }}
|
|
{{ $enumdef := . }}
|
|
|
|
var __{{.EnumTypeName}}Values = []{{.EnumTypeName}}{ {{range .Values}}
|
|
{{.VarName}}, {{end}}
|
|
}
|
|
|
|
{{if $hasDescr}}
|
|
var __{{.EnumTypeName}}Descriptions = map[{{.EnumTypeName}}]string{ {{range .Values}}
|
|
{{.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}}
|
|
}
|
|
{{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 {
|
|
if e == nil {
|
|
return "<nil>"
|
|
}
|
|
return string(e)
|
|
}
|
|
{{end}}
|
|
|
|
{{if $hasDescr}}
|
|
func (e {{.EnumTypeName}}) Description() string {
|
|
if d, ok := __{{.EnumTypeName}}Descriptions[e]; ok {
|
|
return d
|
|
}
|
|
return ""
|
|
}
|
|
{{end}}
|
|
|
|
{{if $hasData}}
|
|
func (e {{.EnumTypeName}}) Data() {{.EnumTypeName}}Data {
|
|
if d, ok := __{{.EnumTypeName}}Data[e]; ok {
|
|
return d
|
|
}
|
|
return {{.EnumTypeName}}Data{}
|
|
}
|
|
{{end}}
|
|
|
|
func (e {{.EnumTypeName}}) VarName() string {
|
|
if d, ok := __{{.EnumTypeName}}Varnames[e]; ok {
|
|
return d
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (e {{.EnumTypeName}}) TypeName() string {
|
|
return "{{$typename}}"
|
|
}
|
|
|
|
func (e {{.EnumTypeName}}) PackageName() string {
|
|
return "{{$pkgname }}"
|
|
}
|
|
|
|
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}}
|
|
}
|
|
|
|
{{if $hasDescr}}
|
|
func (e {{.EnumTypeName}}) DescriptionMeta() enums.EnumDescriptionMetaValue {
|
|
return enums.EnumDescriptionMetaValue{VarName: e.VarName(), Value: e, Description: e.Description()}
|
|
}
|
|
{{end}}
|
|
|
|
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}}
|
|
}
|
|
}
|
|
|
|
{{if $hasDescr}}
|
|
func {{.EnumTypeName}}ValuesDescriptionMeta() []enums.EnumDescriptionMetaValue {
|
|
return []enums.EnumDescriptionMetaValue{ {{range .Values}}
|
|
{{.VarName}}.DescriptionMeta(), {{end}}
|
|
}
|
|
}
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
// ================================ ================= ================================
|
|
|
|
func AllPackageEnums() []enums.Enum {
|
|
return []enums.Enum{ {{range .Enums}}
|
|
{{ if gt (len .Values) 0 }} {{ $v := index .Values 0 }} {{ $v.VarName}}, {{end}} // {{ .EnumTypeName }} {{end}}
|
|
}
|
|
} |