Files
dolt/nomdl/codegen/enum.tmpl
Erik Arvidsson 91e7ffb8e1 NomDL Codegen: Parameterize the types package
This allows us to use the codegen from types/ without manual touchups
2015-10-23 11:04:30 -04:00

49 lines
1.1 KiB
Cheetah

{{$typesPackage := .TypesPackage}}
// {{.Name}}
type {{.Name}} uint32
{{$name := .Name}}
const ({{range $index, $id := .Ids}}
{{title $id}}{{if eq $index 0}} {{$name}} = iota{{end}}{{end}}
)
func New{{.Name}}() {{.Name}} {
return {{.Name}}(0)
}
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
func (e {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
return __typeRefFor{{.Name}}
}
func init() {
__typeRefFor{{.Name}} = {{$typesPackage}}MakeTypeRef(__{{.PackageName}}PackageInFile_{{.FileID}}_CachedRef, {{.Ordinal}})
{{$typesPackage}}RegisterFromValFunction(__typeRefFor{{.Name}}, func(v {{$typesPackage}}Value) {{$typesPackage}}Value {
return {{.Name}}(uint32(v.({{$typesPackage}}UInt32)))
})
}
func (e {{.Name}}) InternalImplementation() uint32 {
return uint32(e)
}
func (e {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
if other, ok := other.({{.Name}}); ok {
return e == other
}
return false
}
func (e {{.Name}}) Ref() ref.Ref {
throwaway := ref.Ref{}
return {{$typesPackage}}EnsureRef(&throwaway, e)
}
func (e {{.Name}}) Chunks() []{{$typesPackage}}Future {
return nil
}