Files
dolt/nomdl/codegen/go/ref.tmpl
T
2016-04-11 17:09:25 -07:00

63 lines
1.6 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 && __typeFor{{.Name}}.Equals(other.Type()) && r.Ref() == other.Ref()
}
func (r {{.Name}}) Chunks() (chunks []{{$typesPackage}}RefBase) {
chunks = append(chunks, r.Type().Chunks()...)
chunks = append(chunks, r)
return
}
func (r {{.Name}}) ChildValues() []{{$typesPackage}}Value {
return nil
}
// A Noms Value that describes {{.Name}}.
var __typeFor{{.Name}} {{$typesPackage}}Type
func (r {{.Name}}) Type() {{$typesPackage}}Type {
return __typeFor{{.Name}}
}
func (r {{.Name}}) Less(other {{$typesPackage}}OrderedValue) bool {
return r.TargetRef().Less(other.({{$typesPackage}}RefBase).TargetRef())
}
func init() {
__typeFor{{.Name}} = {{toTypesType .Type .FileID .PackageName}}
{{$typesPackage}}RegisterRef(__typeFor{{.Name}}, builderFor{{.Name}})
}
func builderFor{{.Name}}(r ref.Ref) {{$typesPackage}}RefBase {
return New{{.Name}}(r)
}
func (r {{.Name}}) TargetValue(vr {{$typesPackage}}ValueReader) {{userType .ElemType}} {
return {{valueToUser "vr.ReadValue(r.target)" .ElemType}}
}
func (r {{.Name}}) SetTargetValue(val {{userType .ElemType}}, vw {{$typesPackage}}ValueWriter) {{.Name}} {
return vw.WriteValue({{userToValue "val" .ElemType}}).({{.Name}})
}