Files
dolt/nomdl/codegen/ref.tmpl
Erik Arvidsson 1d13a878c4 Fix types.Ref and RefKind objects
Ref Values now have a TargetRef() method that returns the ref.Ref of
the target the Value is referencing.

Note: This is a breaking change. In old code the Ref() of the Value was
the Ref of the underlying target.

Fixes #464
2015-10-26 11:18:02 -04:00

50 lines
1.2 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 {
if other, ok := other.({{.Name}}); ok {
return r.Ref() == other.Ref()
}
return false
}
func (r {{.Name}}) Chunks() []{{$typesPackage}}Future {
return r.TypeRef().Chunks()
}
func {{.Name}}FromVal(val {{$typesPackage}}Value) {{.Name}} {
// TODO: Do we still need FromVal?
if val, ok := val.({{.Name}}); ok {
return val
}
return New{{.Name}}(val.({{$typesPackage}}Ref).TargetRef())
}
{{template "type_ref.tmpl" .}}
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))
}