Files
dolt/nomdl/codegen/test/struct_with_list.go
T
Erik Arvidsson 8294a77ead NomDL Codegen: Make sure we keep the original key names
The underlying map for structs should use the original field names as
the map keys.
2015-09-24 11:16:46 -04:00

250 lines
6.3 KiB
Go

// This file was generated by nomdl/codegen.
package test
import (
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func __testPackageInFile_struct_with_list_Ref() types.Ref {
p := types.PackageDef{
Types: types.MapOfStringToTypeRefDef{
"StructWithList": __typeRefOfStructWithList(),
},
}.New()
return types.Ref{R: types.RegisterPackage(&p)}
}
// StructWithList
type StructWithList struct {
m types.Map
}
func NewStructWithList() StructWithList {
return StructWithList{types.NewMap(
types.NewString("$name"), types.NewString("StructWithList"),
types.NewString("$type"), types.MakeTypeRef(types.NewString("StructWithList"), __testPackageInFile_struct_with_list_Ref()),
types.NewString("l"), types.NewList(),
types.NewString("b"), types.Bool(false),
types.NewString("s"), types.NewString(""),
types.NewString("i"), types.Int64(0),
)}
}
type StructWithListDef struct {
L ListOfUInt8Def
B bool
S string
I int64
}
func (def StructWithListDef) New() StructWithList {
return StructWithList{
types.NewMap(
types.NewString("$name"), types.NewString("StructWithList"),
types.NewString("$type"), types.MakeTypeRef(types.NewString("StructWithList"), __testPackageInFile_struct_with_list_Ref()),
types.NewString("l"), def.L.New().NomsValue(),
types.NewString("b"), types.Bool(def.B),
types.NewString("s"), types.NewString(def.S),
types.NewString("i"), types.Int64(def.I),
)}
}
func (self StructWithList) Def() StructWithListDef {
return StructWithListDef{
ListOfUInt8FromVal(self.m.Get(types.NewString("l"))).Def(),
bool(self.m.Get(types.NewString("b")).(types.Bool)),
self.m.Get(types.NewString("s")).(types.String).String(),
int64(self.m.Get(types.NewString("i")).(types.Int64)),
}
}
// Creates and returns a Noms Value that describes StructWithList.
func __typeRefOfStructWithList() types.TypeRef {
return types.MakeStructTypeRef(types.NewString("StructWithList"),
types.NewList(
types.NewString("l"), types.MakeCompoundTypeRef(types.NewString(""), types.ListKind, types.MakePrimitiveTypeRef(types.UInt8Kind)),
types.NewString("b"), types.MakePrimitiveTypeRef(types.BoolKind),
types.NewString("s"), types.MakePrimitiveTypeRef(types.StringKind),
types.NewString("i"), types.MakePrimitiveTypeRef(types.Int64Kind),
),
nil)
}
func StructWithListFromVal(val types.Value) StructWithList {
// TODO: Validate here
return StructWithList{val.(types.Map)}
}
func (self StructWithList) NomsValue() types.Value {
return self.m
}
func (self StructWithList) Equals(other StructWithList) bool {
return self.m.Equals(other.m)
}
func (self StructWithList) Ref() ref.Ref {
return self.m.Ref()
}
func (self StructWithList) Type() types.TypeRef {
return self.m.Get(types.NewString("$type")).(types.TypeRef)
}
func (self StructWithList) L() ListOfUInt8 {
return ListOfUInt8FromVal(self.m.Get(types.NewString("l")))
}
func (self StructWithList) SetL(val ListOfUInt8) StructWithList {
return StructWithList{self.m.Set(types.NewString("l"), val.NomsValue())}
}
func (self StructWithList) B() bool {
return bool(self.m.Get(types.NewString("b")).(types.Bool))
}
func (self StructWithList) SetB(val bool) StructWithList {
return StructWithList{self.m.Set(types.NewString("b"), types.Bool(val))}
}
func (self StructWithList) S() string {
return self.m.Get(types.NewString("s")).(types.String).String()
}
func (self StructWithList) SetS(val string) StructWithList {
return StructWithList{self.m.Set(types.NewString("s"), types.NewString(val))}
}
func (self StructWithList) I() int64 {
return int64(self.m.Get(types.NewString("i")).(types.Int64))
}
func (self StructWithList) SetI(val int64) StructWithList {
return StructWithList{self.m.Set(types.NewString("i"), types.Int64(val))}
}
// ListOfUInt8
type ListOfUInt8 struct {
l types.List
}
func NewListOfUInt8() ListOfUInt8 {
return ListOfUInt8{types.NewList()}
}
type ListOfUInt8Def []uint8
func (def ListOfUInt8Def) New() ListOfUInt8 {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = types.UInt8(d)
}
return ListOfUInt8{types.NewList(l...)}
}
func (self ListOfUInt8) Def() ListOfUInt8Def {
l := make([]uint8, self.Len())
for i := uint64(0); i < self.Len(); i++ {
l[i] = uint8(self.l.Get(i).(types.UInt8))
}
return l
}
func ListOfUInt8FromVal(val types.Value) ListOfUInt8 {
// TODO: Validate here
return ListOfUInt8{val.(types.List)}
}
func (self ListOfUInt8) NomsValue() types.Value {
return self.l
}
func (l ListOfUInt8) Equals(p ListOfUInt8) bool {
return l.l.Equals(p.l)
}
func (l ListOfUInt8) Ref() ref.Ref {
return l.l.Ref()
}
func (l ListOfUInt8) Len() uint64 {
return l.l.Len()
}
func (l ListOfUInt8) Empty() bool {
return l.Len() == uint64(0)
}
func (self ListOfUInt8) Get(i uint64) uint8 {
return uint8(self.l.Get(i).(types.UInt8))
}
func (l ListOfUInt8) Slice(idx uint64, end uint64) ListOfUInt8 {
return ListOfUInt8{l.l.Slice(idx, end)}
}
func (self ListOfUInt8) Set(i uint64, val uint8) ListOfUInt8 {
return ListOfUInt8{self.l.Set(i, types.UInt8(val))}
}
func (l ListOfUInt8) Append(v ...uint8) ListOfUInt8 {
return ListOfUInt8{l.l.Append(l.fromElemSlice(v)...)}
}
func (l ListOfUInt8) Insert(idx uint64, v ...uint8) ListOfUInt8 {
return ListOfUInt8{l.l.Insert(idx, l.fromElemSlice(v)...)}
}
func (l ListOfUInt8) Remove(idx uint64, end uint64) ListOfUInt8 {
return ListOfUInt8{l.l.Remove(idx, end)}
}
func (l ListOfUInt8) RemoveAt(idx uint64) ListOfUInt8 {
return ListOfUInt8{(l.l.RemoveAt(idx))}
}
func (l ListOfUInt8) fromElemSlice(p []uint8) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = types.UInt8(v)
}
return r
}
type ListOfUInt8IterCallback func(v uint8) (stop bool)
func (l ListOfUInt8) Iter(cb ListOfUInt8IterCallback) {
l.l.Iter(func(v types.Value) bool {
return cb(uint8(v.(types.UInt8)))
})
}
type ListOfUInt8IterAllCallback func(v uint8)
func (l ListOfUInt8) IterAll(cb ListOfUInt8IterAllCallback) {
l.l.IterAll(func(v types.Value) {
cb(uint8(v.(types.UInt8)))
})
}
type ListOfUInt8FilterCallback func(v uint8) (keep bool)
func (l ListOfUInt8) Filter(cb ListOfUInt8FilterCallback) ListOfUInt8 {
nl := NewListOfUInt8()
l.IterAll(func(v uint8) {
if cb(v) {
nl = nl.Append(v)
}
})
return nl
}