mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-26 10:37:04 -06:00
171 lines
5.1 KiB
Cheetah
171 lines
5.1 KiB
Cheetah
{{$typesPackage := .TypesPackage}}
|
|
|
|
// {{.Name}}
|
|
|
|
type {{.Name}} struct {
|
|
{{range .Fields}}_{{.Name}} {{userType .T}}
|
|
{{if .Optional}}__optional{{.Name}} bool
|
|
{{end}}{{end}}{{if .HasUnion}}__unionIndex uint32
|
|
__unionValue {{$typesPackage}}Value{{end}}
|
|
cs chunks.ChunkStore
|
|
ref *ref.Ref
|
|
}
|
|
|
|
func New{{.Name}}(cs chunks.ChunkStore) {{.Name}} {
|
|
return {{.Name}}{
|
|
{{range .Fields}}{{if (not .Optional)}}_{{.Name}}: {{userZero "cs" .T}},
|
|
{{end}}{{end}}{{if .HasUnion}}__unionIndex: 0,
|
|
__unionValue: {{valueZero .UnionZeroType}},{{end}}
|
|
cs: cs,
|
|
ref: &ref.Ref{},
|
|
}
|
|
}
|
|
|
|
{{if .CanUseDef}}
|
|
type {{.Name}}Def struct {
|
|
{{range .Fields}}{{title .Name}} {{defType .T}}
|
|
{{end}}{{if .HasUnion}}__unionIndex uint32
|
|
__unionValue {{$typesPackage}}Value
|
|
{{end}}}
|
|
|
|
func (def {{.Name}}Def) New(cs chunks.ChunkStore) {{.Name}} {
|
|
return {{.Name}}{
|
|
{{range .Fields}}_{{.Name}}: {{defToUser (print "def." (title .Name)) .T}},
|
|
{{if .Optional}}__optional{{.Name}}: true,
|
|
{{end}}{{end}}{{if .HasUnion}}__unionIndex: def.__unionIndex,
|
|
__unionValue: def.__unionValue,
|
|
{{end}}cs: cs,
|
|
ref: &ref.Ref{},
|
|
}
|
|
}
|
|
|
|
func (s {{.Name}}) Def() (d {{.Name}}Def) {
|
|
{{range .Fields}}{{if .Optional}}if s.__optional{{.Name}}{ {{end}}d.{{title .Name}} = {{userToDef (printf `s._%s` .Name) .T}}
|
|
{{if .Optional}} }
|
|
{{end}}{{end}}{{if .HasUnion}}d.__unionIndex = s.__unionIndex
|
|
d.__unionValue = s.__unionValue
|
|
{{end}}return
|
|
}
|
|
{{end}}
|
|
|
|
var __typeFor{{.Name}} {{$typesPackage}}Type
|
|
|
|
func (m {{.Name}}) Type() {{$typesPackage}}Type {
|
|
return __typeFor{{.Name}}
|
|
}
|
|
|
|
func init() {
|
|
__typeFor{{.Name}} = {{$typesPackage}}MakeType(__{{.PackageName}}PackageInFile_{{.FileID}}_CachedRef, {{.Ordinal}})
|
|
{{$typesPackage}}RegisterStruct(__typeFor{{.Name}}, builderFor{{.Name}}, readerFor{{.Name}})
|
|
}
|
|
|
|
func builderFor{{.Name}}(cs chunks.ChunkStore, values []{{$typesPackage}}Value) {{$typesPackage}}Value {
|
|
i := 0
|
|
s := {{.Name}}{ref: &ref.Ref{}, cs: cs}{{range .Fields}}{{if .Optional}}
|
|
s.__optional{{.Name}} = bool(values[i].({{$typesPackage}}Bool))
|
|
i++
|
|
if s.__optional{{.Name}} {
|
|
s._{{.Name}} = {{valueToUser "values[i]" .T}}
|
|
i++
|
|
}{{else}}
|
|
s._{{.Name}} = {{valueToUser "values[i]" .T}}
|
|
i++{{end}}{{end}}
|
|
{{if .HasUnion}}s.__unionIndex = uint32(values[i].({{$typesPackage}}Uint32))
|
|
i++
|
|
s.__unionValue = values[i]
|
|
i++
|
|
{{end}}return s
|
|
}
|
|
|
|
func readerFor{{.Name}}(v {{$typesPackage}}Value) []{{$typesPackage}}Value {
|
|
values := []{{$typesPackage}}Value{}
|
|
s := v.({{.Name}}){{range .Fields}}{{if .Optional}}
|
|
values = append(values, {{$typesPackage}}Bool(s.__optional{{.Name}}))
|
|
if s.__optional{{.Name}} {
|
|
values = append(values, {{userToValue (printf "s._%s" .Name) .T}})
|
|
}{{else}}
|
|
values = append(values, {{userToValue (printf "s._%s" .Name) .T}}){{end}}{{end}}
|
|
{{if .HasUnion}}values = append(values, {{$typesPackage}}Uint32(s.__unionIndex))
|
|
values = append(values, s.__unionValue)
|
|
{{end}}return values
|
|
}
|
|
|
|
func (s {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
|
|
return other != nil && __typeFor{{.Name}}.Equals(other.Type()) && s.Ref() == other.Ref()
|
|
}
|
|
|
|
func (s {{.Name}}) Ref() ref.Ref {
|
|
return {{$typesPackage}}EnsureRef(s.ref, s)
|
|
}
|
|
|
|
func (s {{.Name}}) Chunks() (chunks []ref.Ref) {
|
|
chunks = append(chunks, __typeFor{{.Name}}.Chunks()...)
|
|
{{range .Fields}}{{if mayHaveChunks .T}}{{if .Optional}}if s.__optional{{.Name}} {
|
|
{{end}}chunks = append(chunks, s._{{.Name}}.Chunks()...)
|
|
{{if .Optional}} }
|
|
{{end}}{{end}}{{end}}{{if .HasUnion}}chunks = append(chunks, s.__unionValue.Chunks()...)
|
|
{{end}}return
|
|
}
|
|
|
|
func (s {{.Name}}) ChildValues() (ret []{{$typesPackage}}Value) {
|
|
{{range .Fields}}{{if .Optional}}if s.__optional{{.Name}} {
|
|
{{end}}ret = append(ret, {{userToValue (printf "s._%s" .Name) .T}})
|
|
{{if .Optional}} }
|
|
{{end}}{{end}}{{if .HasUnion}}ret = append(ret, s.__unionValue)
|
|
{{end}}return
|
|
}
|
|
|
|
{{$name := .Name}}
|
|
{{range $index, $field := .Fields}}
|
|
{{if .Optional}}
|
|
func (s {{$name}}) {{title .Name}}() (v {{userType .T}}, ok bool) {
|
|
if s.__optional{{.Name}} {
|
|
return s._{{.Name}}, true
|
|
}
|
|
return
|
|
}
|
|
{{else}}
|
|
func (s {{$name}}) {{title .Name}}() {{userType .T}} {
|
|
return s._{{.Name}}
|
|
}
|
|
{{end}}
|
|
func (s {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
|
|
{{if .Optional}}s.__optional{{.Name}} = true
|
|
{{end}}s._{{.Name}} = val
|
|
s.ref = &ref.Ref{}
|
|
return s
|
|
}
|
|
{{end}}
|
|
|
|
{{$canUseDef := .CanUseDef}}
|
|
{{range $index, $field := .Choices}}
|
|
func (s {{$name}}) {{title .Name}}() (val {{userType .T}}, ok bool) {
|
|
if s.__unionIndex != {{$index}} {
|
|
return
|
|
}
|
|
return {{valueToUser "s.__unionValue" .T}}, true
|
|
}
|
|
|
|
func (s {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
|
|
s.__unionIndex = {{$index}}
|
|
s.__unionValue = {{userToValue "val" .T}}
|
|
s.ref = &ref.Ref{}
|
|
return s
|
|
}
|
|
|
|
{{if $canUseDef}}
|
|
func (def {{$name}}Def) {{title .Name}}() (val {{defType .T}}, ok bool) {
|
|
if def.__unionIndex != {{$index}} {
|
|
return
|
|
}
|
|
return {{valueToDef "def.__unionValue" .T}}, true
|
|
}
|
|
|
|
func (def {{$name}}Def) Set{{title .Name}}(cs chunks.ChunkStore, val {{defType .T}}) {{$name}}Def {
|
|
def.__unionIndex = {{$index}}
|
|
def.__unionValue = {{defToValue "val" .T}}
|
|
return def
|
|
}
|
|
{{end}}
|
|
{{end}}
|