Files
dolt/nomdl/codegen/ref.tmpl
Erik Arvidsson 460841e3ed Clean up registration of Ref values
Ref values use the TargetRef to get the internal implementation

RegisterFromValFunction and ToNomsValueFromTypeRef were only used by
ref values at this point so these were renamed and simplified to be
more specific for ref values
2015-11-05 14:32:45 -05:00

55 lines
1.4 KiB
Cheetah

{{$typesPackage := .TypesPackage}}
// {{.Name}}
type {{.Name}} struct {
target ref.Ref
ref *ref.Ref
}
func New{{.Name}}(target ref.Ref) {{.Name}} {
return {{.Name}}{target, &ref.Ref{}}
}
func (r {{.Name}}) TargetRef() ref.Ref {
return r.target
}
func (r {{.Name}}) Ref() ref.Ref {
return {{$typesPackage}}EnsureRef(r.ref, r)
}
func (r {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
return other != nil && __typeRefFor{{.Name}}.Equals(other.TypeRef()) && r.Ref() == other.Ref()
}
func (r {{.Name}}) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, r.TypeRef().Chunks()...)
chunks = append(chunks, r.target)
return
}
// A Noms Value that describes {{.Name}}.
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
func (m {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
return __typeRefFor{{.Name}}
}
func init() {
__typeRefFor{{.Name}} = {{toTypesTypeRef .Type .FileID .PackageName}}
{{$typesPackage}}RegisterRef(__typeRefFor{{.Name}}, builderFor{{.Name}})
}
func builderFor{{.Name}}(r ref.Ref) {{$typesPackage}}Value {
return New{{.Name}}(r)
}
func (r {{.Name}}) TargetValue(cs chunks.ChunkSource) {{userType .ElemType}} {
return {{valueToUser (printf "%sReadValue(r.target, cs)" $typesPackage) .ElemType}}
}
func (r {{.Name}}) SetTargetValue(val {{userType .ElemType}}, cs chunks.ChunkSink) {{.Name}} {
return New{{.Name}}({{$typesPackage}}WriteValue({{userToValue "val" .ElemType}}, cs))
}