NomDL: Update tagdex

This changes clients/tagdex to use nomdl

To make this work we crippled it a bit and it no longer takes a dataset
ID but a ref to a `Set(Ref(RemotePhoto))`
This commit is contained in:
Erik Arvidsson
2015-10-29 10:32:08 -04:00
parent 1939602844
commit 35a30eeae7
12 changed files with 1968 additions and 720 deletions
+13 -8
View File
@@ -17,6 +17,7 @@ import (
"github.com/attic-labs/noms/clients/util"
"github.com/attic-labs/noms/d"
"github.com/attic-labs/noms/dataset"
"github.com/attic-labs/noms/types"
)
var (
@@ -73,7 +74,8 @@ func main() {
func getUser() {
if commit, ok := ds.MaybeHead(); ok {
user = UserFromVal(commit.Value())
userRef := commit.Value().(RefOfUser)
user = userRef.TargetValue(ds.Store())
if checkAuth() {
return
}
@@ -142,9 +144,10 @@ func getAlbum(id string) Album {
})
d.Chk.NoError(err)
fmt.Printf("Photoset: %v\n", response.Photoset.Title.Content)
photos := getAlbumPhotos(id)
fmt.Printf("Photoset: %v\nRef: %s\n", response.Photoset.Title.Content, photos.TargetRef())
return NewAlbum().
SetId(id).
SetTitle(response.Photoset.Title.Content).
@@ -187,7 +190,7 @@ func getAlbums() MapOfStringToAlbum {
return albums
}
func getAlbumPhotos(id string) SetOfRemotePhoto {
func getAlbumPhotos(id string) RefOfSetOfRefOfRemotePhoto {
response := struct {
flickrCall
Photoset struct {
@@ -224,7 +227,7 @@ func getAlbumPhotos(id string) SetOfRemotePhoto {
})
d.Chk.NoError(err)
photos := NewSetOfRemotePhoto()
photos := NewSetOfRefOfRemotePhoto()
for _, p := range response.Photoset.Photo {
photo := RemotePhotoDef{
@@ -247,10 +250,11 @@ func getAlbumPhotos(id string) SetOfRemotePhoto {
photo = photo.SetGeoposition(GeopositionDef{lat, lon}.New())
}
photos = photos.Insert(photo)
photos = photos.Insert(NewRefOfRemotePhoto(types.WriteValue(photo, ds.Store())))
}
return photos
r := types.WriteValue(photos, ds.Store())
return NewRefOfSetOfRefOfRemotePhoto(r)
}
func getTags(tagStr string) (tags SetOfStringDef) {
@@ -322,7 +326,8 @@ func awaitOAuthResponse(l net.Listener, tempCred *oauth.Credentials) error {
func commitUser() {
ok := false
*ds, ok = ds.Commit(user)
r := NewRefOfUser(types.WriteValue(user, ds.Store()))
*ds, ok = ds.Commit(r)
d.Exp.True(ok, "Could not commit due to conflicting edit")
}
@@ -7,20 +7,32 @@ import (
"github.com/attic-labs/noms/types"
)
var __mainPackageInFile_sha1_00419eb_CachedRef ref.Ref
var __mainPackageInFile_sha1_8829255_CachedRef ref.Ref
// 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 init() {
p := types.NewPackage([]types.TypeRef{
types.MakeStructTypeRef("Photo",
[]types.Field{
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Url", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"), 0), false},
types.Field{"Size", types.MakeTypeRef(ref.Ref{}, 2), false},
types.Field{"Tags", types.MakeCompoundTypeRef(types.SetKind, types.MakePrimitiveTypeRef(types.StringKind)), false},
types.Field{"Image", types.MakePrimitiveTypeRef(types.BlobKind), false},
},
types.Choices{},
),
types.MakeStructTypeRef("RemotePhoto",
[]types.Field{
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Url", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"), 0), false},
types.Field{"Sizes", types.MakeCompoundTypeRef(types.MapKind, types.MakeTypeRef(ref.Ref{}, 1), types.MakePrimitiveTypeRef(types.StringKind)), false},
types.Field{"Sizes", types.MakeCompoundTypeRef(types.MapKind, types.MakeTypeRef(ref.Ref{}, 2), types.MakePrimitiveTypeRef(types.StringKind)), false},
types.Field{"Tags", types.MakeCompoundTypeRef(types.SetKind, types.MakePrimitiveTypeRef(types.StringKind)), false},
},
types.Choices{},
@@ -35,7 +47,159 @@ func init() {
}, []ref.Ref{
ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"),
})
__mainPackageInFile_sha1_00419eb_CachedRef = types.RegisterPackage(&p)
__mainPackageInFile_sha1_8829255_CachedRef = types.RegisterPackage(&p)
}
// Photo
type Photo struct {
m types.Map
ref *ref.Ref
}
func NewPhoto() Photo {
return Photo{types.NewMap(
types.NewString("Id"), types.NewString(""),
types.NewString("Title"), types.NewString(""),
types.NewString("Url"), types.NewString(""),
types.NewString("Geoposition"), NewGeoposition(),
types.NewString("Size"), NewSize(),
types.NewString("Tags"), NewSetOfString(),
types.NewString("Image"), types.NewEmptyBlob(),
), &ref.Ref{}}
}
type PhotoDef struct {
Id string
Title string
Url string
Geoposition GeopositionDef
Size SizeDef
Tags SetOfStringDef
Image types.Blob
}
func (def PhotoDef) New() Photo {
return Photo{
types.NewMap(
types.NewString("Id"), types.NewString(def.Id),
types.NewString("Title"), types.NewString(def.Title),
types.NewString("Url"), types.NewString(def.Url),
types.NewString("Geoposition"), def.Geoposition.New(),
types.NewString("Size"), def.Size.New(),
types.NewString("Tags"), def.Tags.New(),
types.NewString("Image"), def.Image,
), &ref.Ref{}}
}
func (s Photo) Def() (d PhotoDef) {
d.Id = s.m.Get(types.NewString("Id")).(types.String).String()
d.Title = s.m.Get(types.NewString("Title")).(types.String).String()
d.Url = s.m.Get(types.NewString("Url")).(types.String).String()
d.Geoposition = s.m.Get(types.NewString("Geoposition")).(Geoposition).Def()
d.Size = s.m.Get(types.NewString("Size")).(Size).Def()
d.Tags = s.m.Get(types.NewString("Tags")).(SetOfString).Def()
d.Image = s.m.Get(types.NewString("Image")).(types.Blob)
return
}
var __typeRefForPhoto types.TypeRef
func (m Photo) TypeRef() types.TypeRef {
return __typeRefForPhoto
}
func init() {
__typeRefForPhoto = types.MakeTypeRef(__mainPackageInFile_sha1_8829255_CachedRef, 0)
types.RegisterFromValFunction(__typeRefForPhoto, func(v types.Value) types.Value {
return PhotoFromVal(v)
})
}
func PhotoFromVal(val types.Value) Photo {
// TODO: Do we still need FromVal?
if val, ok := val.(Photo); ok {
return val
}
// TODO: Validate here
return Photo{val.(types.Map), &ref.Ref{}}
}
func (s Photo) InternalImplementation() types.Map {
return s.m
}
func (s Photo) Equals(other types.Value) bool {
if other, ok := other.(Photo); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s Photo) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s Photo) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s Photo) Id() string {
return s.m.Get(types.NewString("Id")).(types.String).String()
}
func (s Photo) SetId(val string) Photo {
return Photo{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
}
func (s Photo) Title() string {
return s.m.Get(types.NewString("Title")).(types.String).String()
}
func (s Photo) SetTitle(val string) Photo {
return Photo{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
}
func (s Photo) Url() string {
return s.m.Get(types.NewString("Url")).(types.String).String()
}
func (s Photo) SetUrl(val string) Photo {
return Photo{s.m.Set(types.NewString("Url"), types.NewString(val)), &ref.Ref{}}
}
func (s Photo) Geoposition() Geoposition {
return s.m.Get(types.NewString("Geoposition")).(Geoposition)
}
func (s Photo) SetGeoposition(val Geoposition) Photo {
return Photo{s.m.Set(types.NewString("Geoposition"), val), &ref.Ref{}}
}
func (s Photo) Size() Size {
return s.m.Get(types.NewString("Size")).(Size)
}
func (s Photo) SetSize(val Size) Photo {
return Photo{s.m.Set(types.NewString("Size"), val), &ref.Ref{}}
}
func (s Photo) Tags() SetOfString {
return s.m.Get(types.NewString("Tags")).(SetOfString)
}
func (s Photo) SetTags(val SetOfString) Photo {
return Photo{s.m.Set(types.NewString("Tags"), val), &ref.Ref{}}
}
func (s Photo) Image() types.Blob {
return s.m.Get(types.NewString("Image")).(types.Blob)
}
func (s Photo) SetImage(val types.Blob) Photo {
return Photo{s.m.Set(types.NewString("Image"), val), &ref.Ref{}}
}
// RemotePhoto
@@ -94,7 +258,7 @@ func (m RemotePhoto) TypeRef() types.TypeRef {
}
func init() {
__typeRefForRemotePhoto = types.MakeTypeRef(__mainPackageInFile_sha1_00419eb_CachedRef, 0)
__typeRefForRemotePhoto = types.MakeTypeRef(__mainPackageInFile_sha1_8829255_CachedRef, 1)
types.RegisterFromValFunction(__typeRefForRemotePhoto, func(v types.Value) types.Value {
return RemotePhotoFromVal(v)
})
@@ -218,7 +382,7 @@ func (m Size) TypeRef() types.TypeRef {
}
func init() {
__typeRefForSize = types.MakeTypeRef(__mainPackageInFile_sha1_00419eb_CachedRef, 1)
__typeRefForSize = types.MakeTypeRef(__mainPackageInFile_sha1_8829255_CachedRef, 2)
types.RegisterFromValFunction(__typeRefForSize, func(v types.Value) types.Value {
return SizeFromVal(v)
})
@@ -270,142 +434,6 @@ func (s Size) SetHeight(val uint32) Size {
return Size{s.m.Set(types.NewString("Height"), types.UInt32(val)), &ref.Ref{}}
}
// MapOfSizeToString
type MapOfSizeToString struct {
m types.Map
ref *ref.Ref
}
func NewMapOfSizeToString() MapOfSizeToString {
return MapOfSizeToString{types.NewMap(), &ref.Ref{}}
}
type MapOfSizeToStringDef map[SizeDef]string
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, k.New(), types.NewString(v))
}
return MapOfSizeToString{types.NewMap(kv...), &ref.Ref{}}
}
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
def := make(map[SizeDef]string)
m.m.Iter(func(k, v types.Value) bool {
def[k.(Size).Def()] = v.(types.String).String()
return false
})
return def
}
func MapOfSizeToStringFromVal(val types.Value) MapOfSizeToString {
// TODO: Do we still need FromVal?
if val, ok := val.(MapOfSizeToString); ok {
return val
}
// TODO: Validate here
return MapOfSizeToString{val.(types.Map), &ref.Ref{}}
}
func (m MapOfSizeToString) InternalImplementation() types.Map {
return m.m
}
func (m MapOfSizeToString) Equals(other types.Value) bool {
if other, ok := other.(MapOfSizeToString); ok {
return m.Ref() == other.Ref()
}
return false
}
func (m MapOfSizeToString) Ref() ref.Ref {
return types.EnsureRef(m.ref, m)
}
func (m MapOfSizeToString) Chunks() (futures []types.Future) {
futures = append(futures, m.TypeRef().Chunks()...)
futures = append(futures, m.m.Chunks()...)
return
}
// A Noms Value that describes MapOfSizeToString.
var __typeRefForMapOfSizeToString types.TypeRef
func (m MapOfSizeToString) TypeRef() types.TypeRef {
return __typeRefForMapOfSizeToString
}
func init() {
__typeRefForMapOfSizeToString = types.MakeCompoundTypeRef(types.MapKind, types.MakeTypeRef(__mainPackageInFile_sha1_00419eb_CachedRef, 1), types.MakePrimitiveTypeRef(types.StringKind))
types.RegisterFromValFunction(__typeRefForMapOfSizeToString, func(v types.Value) types.Value {
return MapOfSizeToStringFromVal(v)
})
}
func (m MapOfSizeToString) Empty() bool {
return m.m.Empty()
}
func (m MapOfSizeToString) Len() uint64 {
return m.m.Len()
}
func (m MapOfSizeToString) Has(p Size) bool {
return m.m.Has(p)
}
func (m MapOfSizeToString) Get(p Size) string {
return m.m.Get(p).(types.String).String()
}
func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
v, ok := m.m.MaybeGet(p)
if !ok {
return "", false
}
return v.(types.String).String(), ok
}
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
}
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
func (m MapOfSizeToString) Iter(cb MapOfSizeToStringIterCallback) {
m.m.Iter(func(k, v types.Value) bool {
return cb(k.(Size), v.(types.String).String())
})
}
type MapOfSizeToStringIterAllCallback func(k Size, v string)
func (m MapOfSizeToString) IterAll(cb MapOfSizeToStringIterAllCallback) {
m.m.IterAll(func(k, v types.Value) {
cb(k.(Size), v.(types.String).String())
})
}
type MapOfSizeToStringFilterCallback func(k Size, v string) (keep bool)
func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeToString {
nm := NewMapOfSizeToString()
m.IterAll(func(k Size, v string) {
if cb(k, v) {
nm = nm.Set(k, v)
}
})
return nm
}
// SetOfString
type SetOfString struct {
@@ -556,3 +584,139 @@ func (s SetOfString) fromElemSlice(p []string) []types.Value {
}
return r
}
// MapOfSizeToString
type MapOfSizeToString struct {
m types.Map
ref *ref.Ref
}
func NewMapOfSizeToString() MapOfSizeToString {
return MapOfSizeToString{types.NewMap(), &ref.Ref{}}
}
type MapOfSizeToStringDef map[SizeDef]string
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, k.New(), types.NewString(v))
}
return MapOfSizeToString{types.NewMap(kv...), &ref.Ref{}}
}
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
def := make(map[SizeDef]string)
m.m.Iter(func(k, v types.Value) bool {
def[k.(Size).Def()] = v.(types.String).String()
return false
})
return def
}
func MapOfSizeToStringFromVal(val types.Value) MapOfSizeToString {
// TODO: Do we still need FromVal?
if val, ok := val.(MapOfSizeToString); ok {
return val
}
// TODO: Validate here
return MapOfSizeToString{val.(types.Map), &ref.Ref{}}
}
func (m MapOfSizeToString) InternalImplementation() types.Map {
return m.m
}
func (m MapOfSizeToString) Equals(other types.Value) bool {
if other, ok := other.(MapOfSizeToString); ok {
return m.Ref() == other.Ref()
}
return false
}
func (m MapOfSizeToString) Ref() ref.Ref {
return types.EnsureRef(m.ref, m)
}
func (m MapOfSizeToString) Chunks() (futures []types.Future) {
futures = append(futures, m.TypeRef().Chunks()...)
futures = append(futures, m.m.Chunks()...)
return
}
// A Noms Value that describes MapOfSizeToString.
var __typeRefForMapOfSizeToString types.TypeRef
func (m MapOfSizeToString) TypeRef() types.TypeRef {
return __typeRefForMapOfSizeToString
}
func init() {
__typeRefForMapOfSizeToString = types.MakeCompoundTypeRef(types.MapKind, types.MakeTypeRef(__mainPackageInFile_sha1_8829255_CachedRef, 2), types.MakePrimitiveTypeRef(types.StringKind))
types.RegisterFromValFunction(__typeRefForMapOfSizeToString, func(v types.Value) types.Value {
return MapOfSizeToStringFromVal(v)
})
}
func (m MapOfSizeToString) Empty() bool {
return m.m.Empty()
}
func (m MapOfSizeToString) Len() uint64 {
return m.m.Len()
}
func (m MapOfSizeToString) Has(p Size) bool {
return m.m.Has(p)
}
func (m MapOfSizeToString) Get(p Size) string {
return m.m.Get(p).(types.String).String()
}
func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
v, ok := m.m.MaybeGet(p)
if !ok {
return "", false
}
return v.(types.String).String(), ok
}
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
}
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
func (m MapOfSizeToString) Iter(cb MapOfSizeToStringIterCallback) {
m.m.Iter(func(k, v types.Value) bool {
return cb(k.(Size), v.(types.String).String())
})
}
type MapOfSizeToStringIterAllCallback func(k Size, v string)
func (m MapOfSizeToString) IterAll(cb MapOfSizeToStringIterAllCallback) {
m.m.IterAll(func(k, v types.Value) {
cb(k.(Size), v.(types.String).String())
})
}
type MapOfSizeToStringFilterCallback func(k Size, v string) (keep bool)
func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeToString {
nm := NewMapOfSizeToString()
m.IterAll(func(k Size, v string) {
if cb(k, v) {
nm = nm.Set(k, v)
}
})
return nm
}
+2 -2
View File
@@ -11,8 +11,8 @@ struct User {
struct Album {
Id: String
Title: String
Photos: Set(Img.RemotePhoto)
Photos: Ref(Set(Ref(Img.RemotePhoto)))
}
using Map(String, Album)
using Set(Img.RemotePhoto)
using Ref(User)
+321 -50
View File
@@ -3,6 +3,7 @@
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -28,12 +29,12 @@ func init() {
[]types.Field{
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Photos", types.MakeCompoundTypeRef(types.SetKind, types.MakeTypeRef(ref.Parse("sha1-00419ebbb418539af67238164b20341913efeb4d"), 0)), false},
types.Field{"Photos", types.MakeCompoundTypeRef(types.RefKind, types.MakeCompoundTypeRef(types.SetKind, types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(ref.Parse("sha1-8829255f15d0403222188a23b8ced0afdbee2a97"), 1)))), false},
},
types.Choices{},
),
}, []ref.Ref{
ref.Parse("sha1-00419ebbb418539af67238164b20341913efeb4d"),
ref.Parse("sha1-8829255f15d0403222188a23b8ced0afdbee2a97"),
})
__mainPackageInFile_types_CachedRef = types.RegisterPackage(&p)
}
@@ -55,6 +56,34 @@ func NewUser() User {
), &ref.Ref{}}
}
type UserDef struct {
Id string
Name string
OAuthToken string
OAuthSecret string
Albums MapOfStringToAlbumDef
}
func (def UserDef) New() User {
return User{
types.NewMap(
types.NewString("Id"), types.NewString(def.Id),
types.NewString("Name"), types.NewString(def.Name),
types.NewString("OAuthToken"), types.NewString(def.OAuthToken),
types.NewString("OAuthSecret"), types.NewString(def.OAuthSecret),
types.NewString("Albums"), def.Albums.New(),
), &ref.Ref{}}
}
func (s User) Def() (d UserDef) {
d.Id = s.m.Get(types.NewString("Id")).(types.String).String()
d.Name = s.m.Get(types.NewString("Name")).(types.String).String()
d.OAuthToken = s.m.Get(types.NewString("OAuthToken")).(types.String).String()
d.OAuthSecret = s.m.Get(types.NewString("OAuthSecret")).(types.String).String()
d.Albums = s.m.Get(types.NewString("Albums")).(MapOfStringToAlbum).Def()
return
}
var __typeRefForUser types.TypeRef
func (m User) TypeRef() types.TypeRef {
@@ -149,10 +178,32 @@ func NewAlbum() Album {
return Album{types.NewMap(
types.NewString("Id"), types.NewString(""),
types.NewString("Title"), types.NewString(""),
types.NewString("Photos"), NewSetOfRemotePhoto(),
types.NewString("Photos"), NewRefOfSetOfRefOfRemotePhoto(ref.Ref{}),
), &ref.Ref{}}
}
type AlbumDef struct {
Id string
Title string
Photos ref.Ref
}
func (def AlbumDef) New() Album {
return Album{
types.NewMap(
types.NewString("Id"), types.NewString(def.Id),
types.NewString("Title"), types.NewString(def.Title),
types.NewString("Photos"), NewRefOfSetOfRefOfRemotePhoto(def.Photos),
), &ref.Ref{}}
}
func (s Album) Def() (d AlbumDef) {
d.Id = s.m.Get(types.NewString("Id")).(types.String).String()
d.Title = s.m.Get(types.NewString("Title")).(types.String).String()
d.Photos = s.m.Get(types.NewString("Photos")).(RefOfSetOfRefOfRemotePhoto).TargetRef()
return
}
var __typeRefForAlbum types.TypeRef
func (m Album) TypeRef() types.TypeRef {
@@ -212,11 +263,11 @@ func (s Album) SetTitle(val string) Album {
return Album{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
}
func (s Album) Photos() SetOfRemotePhoto {
return s.m.Get(types.NewString("Photos")).(SetOfRemotePhoto)
func (s Album) Photos() RefOfSetOfRefOfRemotePhoto {
return s.m.Get(types.NewString("Photos")).(RefOfSetOfRefOfRemotePhoto)
}
func (s Album) SetPhotos(val SetOfRemotePhoto) Album {
func (s Album) SetPhotos(val RefOfSetOfRefOfRemotePhoto) Album {
return Album{s.m.Set(types.NewString("Photos"), val), &ref.Ref{}}
}
@@ -231,6 +282,25 @@ func NewMapOfStringToAlbum() MapOfStringToAlbum {
return MapOfStringToAlbum{types.NewMap(), &ref.Ref{}}
}
type MapOfStringToAlbumDef map[string]AlbumDef
func (def MapOfStringToAlbumDef) New() MapOfStringToAlbum {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v.New())
}
return MapOfStringToAlbum{types.NewMap(kv...), &ref.Ref{}}
}
func (m MapOfStringToAlbum) Def() MapOfStringToAlbumDef {
def := make(map[string]AlbumDef)
m.m.Iter(func(k, v types.Value) bool {
def[k.(types.String).String()] = v.(Album).Def()
return false
})
return def
}
func MapOfStringToAlbumFromVal(val types.Value) MapOfStringToAlbum {
// TODO: Do we still need FromVal?
if val, ok := val.(MapOfStringToAlbum); ok {
@@ -337,93 +407,234 @@ func (m MapOfStringToAlbum) Filter(cb MapOfStringToAlbumFilterCallback) MapOfStr
return nm
}
// SetOfRemotePhoto
// RefOfUser
type SetOfRemotePhoto struct {
type RefOfUser struct {
target ref.Ref
ref *ref.Ref
}
func NewRefOfUser(target ref.Ref) RefOfUser {
return RefOfUser{target, &ref.Ref{}}
}
func (r RefOfUser) TargetRef() ref.Ref {
return r.target
}
func (r RefOfUser) Ref() ref.Ref {
return types.EnsureRef(r.ref, r)
}
func (r RefOfUser) Equals(other types.Value) bool {
if other, ok := other.(RefOfUser); ok {
return r.Ref() == other.Ref()
}
return false
}
func (r RefOfUser) Chunks() []types.Future {
return r.TypeRef().Chunks()
}
func RefOfUserFromVal(val types.Value) RefOfUser {
// TODO: Do we still need FromVal?
if val, ok := val.(RefOfUser); ok {
return val
}
return NewRefOfUser(val.(types.Ref).TargetRef())
}
// A Noms Value that describes RefOfUser.
var __typeRefForRefOfUser types.TypeRef
func (m RefOfUser) TypeRef() types.TypeRef {
return __typeRefForRefOfUser
}
func init() {
__typeRefForRefOfUser = types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(__mainPackageInFile_types_CachedRef, 0))
types.RegisterFromValFunction(__typeRefForRefOfUser, func(v types.Value) types.Value {
return RefOfUserFromVal(v)
})
}
func (r RefOfUser) TargetValue(cs chunks.ChunkSource) User {
return types.ReadValue(r.target, cs).(User)
}
func (r RefOfUser) SetTargetValue(val User, cs chunks.ChunkSink) RefOfUser {
return NewRefOfUser(types.WriteValue(val, cs))
}
// RefOfSetOfRefOfRemotePhoto
type RefOfSetOfRefOfRemotePhoto struct {
target ref.Ref
ref *ref.Ref
}
func NewRefOfSetOfRefOfRemotePhoto(target ref.Ref) RefOfSetOfRefOfRemotePhoto {
return RefOfSetOfRefOfRemotePhoto{target, &ref.Ref{}}
}
func (r RefOfSetOfRefOfRemotePhoto) TargetRef() ref.Ref {
return r.target
}
func (r RefOfSetOfRefOfRemotePhoto) Ref() ref.Ref {
return types.EnsureRef(r.ref, r)
}
func (r RefOfSetOfRefOfRemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(RefOfSetOfRefOfRemotePhoto); ok {
return r.Ref() == other.Ref()
}
return false
}
func (r RefOfSetOfRefOfRemotePhoto) Chunks() []types.Future {
return r.TypeRef().Chunks()
}
func RefOfSetOfRefOfRemotePhotoFromVal(val types.Value) RefOfSetOfRefOfRemotePhoto {
// TODO: Do we still need FromVal?
if val, ok := val.(RefOfSetOfRefOfRemotePhoto); ok {
return val
}
return NewRefOfSetOfRefOfRemotePhoto(val.(types.Ref).TargetRef())
}
// A Noms Value that describes RefOfSetOfRefOfRemotePhoto.
var __typeRefForRefOfSetOfRefOfRemotePhoto types.TypeRef
func (m RefOfSetOfRefOfRemotePhoto) TypeRef() types.TypeRef {
return __typeRefForRefOfSetOfRefOfRemotePhoto
}
func init() {
__typeRefForRefOfSetOfRefOfRemotePhoto = types.MakeCompoundTypeRef(types.RefKind, types.MakeCompoundTypeRef(types.SetKind, types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(ref.Parse("sha1-8829255f15d0403222188a23b8ced0afdbee2a97"), 1))))
types.RegisterFromValFunction(__typeRefForRefOfSetOfRefOfRemotePhoto, func(v types.Value) types.Value {
return RefOfSetOfRefOfRemotePhotoFromVal(v)
})
}
func (r RefOfSetOfRefOfRemotePhoto) TargetValue(cs chunks.ChunkSource) SetOfRefOfRemotePhoto {
return types.ReadValue(r.target, cs).(SetOfRefOfRemotePhoto)
}
func (r RefOfSetOfRefOfRemotePhoto) SetTargetValue(val SetOfRefOfRemotePhoto, cs chunks.ChunkSink) RefOfSetOfRefOfRemotePhoto {
return NewRefOfSetOfRefOfRemotePhoto(types.WriteValue(val, cs))
}
// SetOfRefOfRemotePhoto
type SetOfRefOfRemotePhoto struct {
s types.Set
ref *ref.Ref
}
func NewSetOfRemotePhoto() SetOfRemotePhoto {
return SetOfRemotePhoto{types.NewSet(), &ref.Ref{}}
func NewSetOfRefOfRemotePhoto() SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{types.NewSet(), &ref.Ref{}}
}
func SetOfRemotePhotoFromVal(val types.Value) SetOfRemotePhoto {
type SetOfRefOfRemotePhotoDef map[ref.Ref]bool
func (def SetOfRefOfRemotePhotoDef) New() SetOfRefOfRemotePhoto {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfRemotePhoto(d)
i++
}
return SetOfRefOfRemotePhoto{types.NewSet(l...), &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Def() SetOfRefOfRemotePhotoDef {
def := make(map[ref.Ref]bool, s.Len())
s.s.Iter(func(v types.Value) bool {
def[v.(RefOfRemotePhoto).TargetRef()] = true
return false
})
return def
}
func SetOfRefOfRemotePhotoFromVal(val types.Value) SetOfRefOfRemotePhoto {
// TODO: Do we still need FromVal?
if val, ok := val.(SetOfRemotePhoto); ok {
if val, ok := val.(SetOfRefOfRemotePhoto); ok {
return val
}
return SetOfRemotePhoto{val.(types.Set), &ref.Ref{}}
return SetOfRefOfRemotePhoto{val.(types.Set), &ref.Ref{}}
}
func (s SetOfRemotePhoto) InternalImplementation() types.Set {
func (s SetOfRefOfRemotePhoto) InternalImplementation() types.Set {
return s.s
}
func (s SetOfRemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(SetOfRemotePhoto); ok {
func (s SetOfRefOfRemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(SetOfRefOfRemotePhoto); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s SetOfRemotePhoto) Ref() ref.Ref {
func (s SetOfRefOfRemotePhoto) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s SetOfRemotePhoto) Chunks() (futures []types.Future) {
func (s SetOfRefOfRemotePhoto) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.s.Chunks()...)
return
}
// A Noms Value that describes SetOfRemotePhoto.
var __typeRefForSetOfRemotePhoto types.TypeRef
// A Noms Value that describes SetOfRefOfRemotePhoto.
var __typeRefForSetOfRefOfRemotePhoto types.TypeRef
func (m SetOfRemotePhoto) TypeRef() types.TypeRef {
return __typeRefForSetOfRemotePhoto
func (m SetOfRefOfRemotePhoto) TypeRef() types.TypeRef {
return __typeRefForSetOfRefOfRemotePhoto
}
func init() {
__typeRefForSetOfRemotePhoto = types.MakeCompoundTypeRef(types.SetKind, types.MakeTypeRef(ref.Parse("sha1-00419ebbb418539af67238164b20341913efeb4d"), 0))
types.RegisterFromValFunction(__typeRefForSetOfRemotePhoto, func(v types.Value) types.Value {
return SetOfRemotePhotoFromVal(v)
__typeRefForSetOfRefOfRemotePhoto = types.MakeCompoundTypeRef(types.SetKind, types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(ref.Parse("sha1-8829255f15d0403222188a23b8ced0afdbee2a97"), 1)))
types.RegisterFromValFunction(__typeRefForSetOfRefOfRemotePhoto, func(v types.Value) types.Value {
return SetOfRefOfRemotePhotoFromVal(v)
})
}
func (s SetOfRemotePhoto) Empty() bool {
func (s SetOfRefOfRemotePhoto) Empty() bool {
return s.s.Empty()
}
func (s SetOfRemotePhoto) Len() uint64 {
func (s SetOfRefOfRemotePhoto) Len() uint64 {
return s.s.Len()
}
func (s SetOfRemotePhoto) Has(p RemotePhoto) bool {
func (s SetOfRefOfRemotePhoto) Has(p RefOfRemotePhoto) bool {
return s.s.Has(p)
}
type SetOfRemotePhotoIterCallback func(p RemotePhoto) (stop bool)
type SetOfRefOfRemotePhotoIterCallback func(p RefOfRemotePhoto) (stop bool)
func (s SetOfRemotePhoto) Iter(cb SetOfRemotePhotoIterCallback) {
func (s SetOfRefOfRemotePhoto) Iter(cb SetOfRefOfRemotePhotoIterCallback) {
s.s.Iter(func(v types.Value) bool {
return cb(v.(RemotePhoto))
return cb(v.(RefOfRemotePhoto))
})
}
type SetOfRemotePhotoIterAllCallback func(p RemotePhoto)
type SetOfRefOfRemotePhotoIterAllCallback func(p RefOfRemotePhoto)
func (s SetOfRemotePhoto) IterAll(cb SetOfRemotePhotoIterAllCallback) {
func (s SetOfRefOfRemotePhoto) IterAll(cb SetOfRefOfRemotePhotoIterAllCallback) {
s.s.IterAll(func(v types.Value) {
cb(v.(RemotePhoto))
cb(v.(RefOfRemotePhoto))
})
}
type SetOfRemotePhotoFilterCallback func(p RemotePhoto) (keep bool)
type SetOfRefOfRemotePhotoFilterCallback func(p RefOfRemotePhoto) (keep bool)
func (s SetOfRemotePhoto) Filter(cb SetOfRemotePhotoFilterCallback) SetOfRemotePhoto {
ns := NewSetOfRemotePhoto()
s.IterAll(func(v RemotePhoto) {
func (s SetOfRefOfRemotePhoto) Filter(cb SetOfRefOfRemotePhotoFilterCallback) SetOfRefOfRemotePhoto {
ns := NewSetOfRefOfRemotePhoto()
s.IterAll(func(v RefOfRemotePhoto) {
if cb(v) {
ns = ns.Insert(v)
}
@@ -431,27 +642,27 @@ func (s SetOfRemotePhoto) Filter(cb SetOfRemotePhotoFilterCallback) SetOfRemoteP
return ns
}
func (s SetOfRemotePhoto) Insert(p ...RemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
func (s SetOfRefOfRemotePhoto) Insert(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
}
func (s SetOfRemotePhoto) Remove(p ...RemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
func (s SetOfRefOfRemotePhoto) Remove(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
}
func (s SetOfRemotePhoto) Union(others ...SetOfRemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
func (s SetOfRefOfRemotePhoto) Union(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
}
func (s SetOfRemotePhoto) Subtract(others ...SetOfRemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
func (s SetOfRefOfRemotePhoto) Subtract(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
}
func (s SetOfRemotePhoto) Any() RemotePhoto {
return s.s.Any().(RemotePhoto)
func (s SetOfRefOfRemotePhoto) Any() RefOfRemotePhoto {
return s.s.Any().(RefOfRemotePhoto)
}
func (s SetOfRemotePhoto) fromStructSlice(p []SetOfRemotePhoto) []types.Set {
func (s SetOfRefOfRemotePhoto) fromStructSlice(p []SetOfRefOfRemotePhoto) []types.Set {
r := make([]types.Set, len(p))
for i, v := range p {
r[i] = v.s
@@ -459,10 +670,70 @@ func (s SetOfRemotePhoto) fromStructSlice(p []SetOfRemotePhoto) []types.Set {
return r
}
func (s SetOfRemotePhoto) fromElemSlice(p []RemotePhoto) []types.Value {
func (s SetOfRefOfRemotePhoto) fromElemSlice(p []RefOfRemotePhoto) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = v
}
return r
}
// RefOfRemotePhoto
type RefOfRemotePhoto struct {
target ref.Ref
ref *ref.Ref
}
func NewRefOfRemotePhoto(target ref.Ref) RefOfRemotePhoto {
return RefOfRemotePhoto{target, &ref.Ref{}}
}
func (r RefOfRemotePhoto) TargetRef() ref.Ref {
return r.target
}
func (r RefOfRemotePhoto) Ref() ref.Ref {
return types.EnsureRef(r.ref, r)
}
func (r RefOfRemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(RefOfRemotePhoto); ok {
return r.Ref() == other.Ref()
}
return false
}
func (r RefOfRemotePhoto) Chunks() []types.Future {
return r.TypeRef().Chunks()
}
func RefOfRemotePhotoFromVal(val types.Value) RefOfRemotePhoto {
// TODO: Do we still need FromVal?
if val, ok := val.(RefOfRemotePhoto); ok {
return val
}
return NewRefOfRemotePhoto(val.(types.Ref).TargetRef())
}
// A Noms Value that describes RefOfRemotePhoto.
var __typeRefForRefOfRemotePhoto types.TypeRef
func (m RefOfRemotePhoto) TypeRef() types.TypeRef {
return __typeRefForRefOfRemotePhoto
}
func init() {
__typeRefForRefOfRemotePhoto = types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(ref.Parse("sha1-8829255f15d0403222188a23b8ced0afdbee2a97"), 1))
types.RegisterFromValFunction(__typeRefForRefOfRemotePhoto, func(v types.Value) types.Value {
return RefOfRemotePhotoFromVal(v)
})
}
func (r RefOfRemotePhoto) TargetValue(cs chunks.ChunkSource) RemotePhoto {
return types.ReadValue(r.target, cs).(RemotePhoto)
}
func (r RefOfRemotePhoto) SetTargetValue(val RemotePhoto, cs chunks.ChunkSink) RefOfRemotePhoto {
return NewRefOfRemotePhoto(types.WriteValue(val, cs))
}
-15
View File
@@ -1,15 +0,0 @@
package main
func main() {
// Keep old file at least
// ng := nomgen.New("types.go")
// ng.AddType(util.PhotoTypeDef)
// ng.AddType(util.RemotePhotoTypeDef)
//
// ng.AddType(types.NewMap(
// types.NewString("$type"), types.NewString("noms.MapDef"),
// types.NewString("key"), types.NewString("string"),
// types.NewString("value"), types.NewString("set")))
//
// ng.WriteGo("main")
}
+1 -1
View File
@@ -1,3 +1,3 @@
package main
//go:generate go run gen/types.go
//go:generate go run ../../nomdl/codegen/codegen.go -package=main -out-dir=.
+217
View File
@@ -0,0 +1,217 @@
// This file was generated by nomdl/codegen.
package main
import (
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
var __mainPackageInFile_sha1_6d5e1c5_CachedRef ref.Ref
// 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 init() {
p := types.NewPackage([]types.TypeRef{
types.MakeStructTypeRef("Geoposition",
[]types.Field{
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
},
types.Choices{},
),
types.MakeStructTypeRef("Georectangle",
[]types.Field{
types.Field{"TopLeft", types.MakeTypeRef(ref.Ref{}, 0), false},
types.Field{"BottomRight", types.MakeTypeRef(ref.Ref{}, 0), false},
},
types.Choices{},
),
}, []ref.Ref{})
__mainPackageInFile_sha1_6d5e1c5_CachedRef = types.RegisterPackage(&p)
}
// Geoposition
type Geoposition struct {
m types.Map
ref *ref.Ref
}
func NewGeoposition() Geoposition {
return Geoposition{types.NewMap(
types.NewString("Latitude"), types.Float32(0),
types.NewString("Longitude"), types.Float32(0),
), &ref.Ref{}}
}
type GeopositionDef struct {
Latitude float32
Longitude float32
}
func (def GeopositionDef) New() Geoposition {
return Geoposition{
types.NewMap(
types.NewString("Latitude"), types.Float32(def.Latitude),
types.NewString("Longitude"), types.Float32(def.Longitude),
), &ref.Ref{}}
}
func (s Geoposition) Def() (d GeopositionDef) {
d.Latitude = float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
d.Longitude = float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
return
}
var __typeRefForGeoposition types.TypeRef
func (m Geoposition) TypeRef() types.TypeRef {
return __typeRefForGeoposition
}
func init() {
__typeRefForGeoposition = types.MakeTypeRef(__mainPackageInFile_sha1_6d5e1c5_CachedRef, 0)
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.Value {
return GeopositionFromVal(v)
})
}
func GeopositionFromVal(val types.Value) Geoposition {
// TODO: Do we still need FromVal?
if val, ok := val.(Geoposition); ok {
return val
}
// TODO: Validate here
return Geoposition{val.(types.Map), &ref.Ref{}}
}
func (s Geoposition) InternalImplementation() types.Map {
return s.m
}
func (s Geoposition) Equals(other types.Value) bool {
if other, ok := other.(Geoposition); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s Geoposition) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s Geoposition) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s Geoposition) Latitude() float32 {
return float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
}
func (s Geoposition) SetLatitude(val float32) Geoposition {
return Geoposition{s.m.Set(types.NewString("Latitude"), types.Float32(val)), &ref.Ref{}}
}
func (s Geoposition) Longitude() float32 {
return float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
}
func (s Geoposition) SetLongitude(val float32) Geoposition {
return Geoposition{s.m.Set(types.NewString("Longitude"), types.Float32(val)), &ref.Ref{}}
}
// Georectangle
type Georectangle struct {
m types.Map
ref *ref.Ref
}
func NewGeorectangle() Georectangle {
return Georectangle{types.NewMap(
types.NewString("TopLeft"), NewGeoposition(),
types.NewString("BottomRight"), NewGeoposition(),
), &ref.Ref{}}
}
type GeorectangleDef struct {
TopLeft GeopositionDef
BottomRight GeopositionDef
}
func (def GeorectangleDef) New() Georectangle {
return Georectangle{
types.NewMap(
types.NewString("TopLeft"), def.TopLeft.New(),
types.NewString("BottomRight"), def.BottomRight.New(),
), &ref.Ref{}}
}
func (s Georectangle) Def() (d GeorectangleDef) {
d.TopLeft = s.m.Get(types.NewString("TopLeft")).(Geoposition).Def()
d.BottomRight = s.m.Get(types.NewString("BottomRight")).(Geoposition).Def()
return
}
var __typeRefForGeorectangle types.TypeRef
func (m Georectangle) TypeRef() types.TypeRef {
return __typeRefForGeorectangle
}
func init() {
__typeRefForGeorectangle = types.MakeTypeRef(__mainPackageInFile_sha1_6d5e1c5_CachedRef, 1)
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.Value {
return GeorectangleFromVal(v)
})
}
func GeorectangleFromVal(val types.Value) Georectangle {
// TODO: Do we still need FromVal?
if val, ok := val.(Georectangle); ok {
return val
}
// TODO: Validate here
return Georectangle{val.(types.Map), &ref.Ref{}}
}
func (s Georectangle) InternalImplementation() types.Map {
return s.m
}
func (s Georectangle) Equals(other types.Value) bool {
if other, ok := other.(Georectangle); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s Georectangle) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s Georectangle) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s Georectangle) TopLeft() Geoposition {
return s.m.Get(types.NewString("TopLeft")).(Geoposition)
}
func (s Georectangle) SetTopLeft(val Geoposition) Georectangle {
return Georectangle{s.m.Set(types.NewString("TopLeft"), val), &ref.Ref{}}
}
func (s Georectangle) BottomRight() Geoposition {
return s.m.Get(types.NewString("BottomRight")).(Geoposition)
}
func (s Georectangle) SetBottomRight(val Geoposition) Georectangle {
return Georectangle{s.m.Set(types.NewString("BottomRight"), val), &ref.Ref{}}
}
+722
View File
@@ -0,0 +1,722 @@
// This file was generated by nomdl/codegen.
package main
import (
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
var __mainPackageInFile_sha1_8829255_CachedRef ref.Ref
// 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 init() {
p := types.NewPackage([]types.TypeRef{
types.MakeStructTypeRef("Photo",
[]types.Field{
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Url", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"), 0), false},
types.Field{"Size", types.MakeTypeRef(ref.Ref{}, 2), false},
types.Field{"Tags", types.MakeCompoundTypeRef(types.SetKind, types.MakePrimitiveTypeRef(types.StringKind)), false},
types.Field{"Image", types.MakePrimitiveTypeRef(types.BlobKind), false},
},
types.Choices{},
),
types.MakeStructTypeRef("RemotePhoto",
[]types.Field{
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Url", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"), 0), false},
types.Field{"Sizes", types.MakeCompoundTypeRef(types.MapKind, types.MakeTypeRef(ref.Ref{}, 2), types.MakePrimitiveTypeRef(types.StringKind)), false},
types.Field{"Tags", types.MakeCompoundTypeRef(types.SetKind, types.MakePrimitiveTypeRef(types.StringKind)), false},
},
types.Choices{},
),
types.MakeStructTypeRef("Size",
[]types.Field{
types.Field{"Width", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"Height", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
},
types.Choices{},
),
}, []ref.Ref{
ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"),
})
__mainPackageInFile_sha1_8829255_CachedRef = types.RegisterPackage(&p)
}
// Photo
type Photo struct {
m types.Map
ref *ref.Ref
}
func NewPhoto() Photo {
return Photo{types.NewMap(
types.NewString("Id"), types.NewString(""),
types.NewString("Title"), types.NewString(""),
types.NewString("Url"), types.NewString(""),
types.NewString("Geoposition"), NewGeoposition(),
types.NewString("Size"), NewSize(),
types.NewString("Tags"), NewSetOfString(),
types.NewString("Image"), types.NewEmptyBlob(),
), &ref.Ref{}}
}
type PhotoDef struct {
Id string
Title string
Url string
Geoposition GeopositionDef
Size SizeDef
Tags SetOfStringDef
Image types.Blob
}
func (def PhotoDef) New() Photo {
return Photo{
types.NewMap(
types.NewString("Id"), types.NewString(def.Id),
types.NewString("Title"), types.NewString(def.Title),
types.NewString("Url"), types.NewString(def.Url),
types.NewString("Geoposition"), def.Geoposition.New(),
types.NewString("Size"), def.Size.New(),
types.NewString("Tags"), def.Tags.New(),
types.NewString("Image"), def.Image,
), &ref.Ref{}}
}
func (s Photo) Def() (d PhotoDef) {
d.Id = s.m.Get(types.NewString("Id")).(types.String).String()
d.Title = s.m.Get(types.NewString("Title")).(types.String).String()
d.Url = s.m.Get(types.NewString("Url")).(types.String).String()
d.Geoposition = s.m.Get(types.NewString("Geoposition")).(Geoposition).Def()
d.Size = s.m.Get(types.NewString("Size")).(Size).Def()
d.Tags = s.m.Get(types.NewString("Tags")).(SetOfString).Def()
d.Image = s.m.Get(types.NewString("Image")).(types.Blob)
return
}
var __typeRefForPhoto types.TypeRef
func (m Photo) TypeRef() types.TypeRef {
return __typeRefForPhoto
}
func init() {
__typeRefForPhoto = types.MakeTypeRef(__mainPackageInFile_sha1_8829255_CachedRef, 0)
types.RegisterFromValFunction(__typeRefForPhoto, func(v types.Value) types.Value {
return PhotoFromVal(v)
})
}
func PhotoFromVal(val types.Value) Photo {
// TODO: Do we still need FromVal?
if val, ok := val.(Photo); ok {
return val
}
// TODO: Validate here
return Photo{val.(types.Map), &ref.Ref{}}
}
func (s Photo) InternalImplementation() types.Map {
return s.m
}
func (s Photo) Equals(other types.Value) bool {
if other, ok := other.(Photo); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s Photo) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s Photo) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s Photo) Id() string {
return s.m.Get(types.NewString("Id")).(types.String).String()
}
func (s Photo) SetId(val string) Photo {
return Photo{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
}
func (s Photo) Title() string {
return s.m.Get(types.NewString("Title")).(types.String).String()
}
func (s Photo) SetTitle(val string) Photo {
return Photo{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
}
func (s Photo) Url() string {
return s.m.Get(types.NewString("Url")).(types.String).String()
}
func (s Photo) SetUrl(val string) Photo {
return Photo{s.m.Set(types.NewString("Url"), types.NewString(val)), &ref.Ref{}}
}
func (s Photo) Geoposition() Geoposition {
return s.m.Get(types.NewString("Geoposition")).(Geoposition)
}
func (s Photo) SetGeoposition(val Geoposition) Photo {
return Photo{s.m.Set(types.NewString("Geoposition"), val), &ref.Ref{}}
}
func (s Photo) Size() Size {
return s.m.Get(types.NewString("Size")).(Size)
}
func (s Photo) SetSize(val Size) Photo {
return Photo{s.m.Set(types.NewString("Size"), val), &ref.Ref{}}
}
func (s Photo) Tags() SetOfString {
return s.m.Get(types.NewString("Tags")).(SetOfString)
}
func (s Photo) SetTags(val SetOfString) Photo {
return Photo{s.m.Set(types.NewString("Tags"), val), &ref.Ref{}}
}
func (s Photo) Image() types.Blob {
return s.m.Get(types.NewString("Image")).(types.Blob)
}
func (s Photo) SetImage(val types.Blob) Photo {
return Photo{s.m.Set(types.NewString("Image"), val), &ref.Ref{}}
}
// RemotePhoto
type RemotePhoto struct {
m types.Map
ref *ref.Ref
}
func NewRemotePhoto() RemotePhoto {
return RemotePhoto{types.NewMap(
types.NewString("Id"), types.NewString(""),
types.NewString("Title"), types.NewString(""),
types.NewString("Url"), types.NewString(""),
types.NewString("Geoposition"), NewGeoposition(),
types.NewString("Sizes"), NewMapOfSizeToString(),
types.NewString("Tags"), NewSetOfString(),
), &ref.Ref{}}
}
type RemotePhotoDef struct {
Id string
Title string
Url string
Geoposition GeopositionDef
Sizes MapOfSizeToStringDef
Tags SetOfStringDef
}
func (def RemotePhotoDef) New() RemotePhoto {
return RemotePhoto{
types.NewMap(
types.NewString("Id"), types.NewString(def.Id),
types.NewString("Title"), types.NewString(def.Title),
types.NewString("Url"), types.NewString(def.Url),
types.NewString("Geoposition"), def.Geoposition.New(),
types.NewString("Sizes"), def.Sizes.New(),
types.NewString("Tags"), def.Tags.New(),
), &ref.Ref{}}
}
func (s RemotePhoto) Def() (d RemotePhotoDef) {
d.Id = s.m.Get(types.NewString("Id")).(types.String).String()
d.Title = s.m.Get(types.NewString("Title")).(types.String).String()
d.Url = s.m.Get(types.NewString("Url")).(types.String).String()
d.Geoposition = s.m.Get(types.NewString("Geoposition")).(Geoposition).Def()
d.Sizes = s.m.Get(types.NewString("Sizes")).(MapOfSizeToString).Def()
d.Tags = s.m.Get(types.NewString("Tags")).(SetOfString).Def()
return
}
var __typeRefForRemotePhoto types.TypeRef
func (m RemotePhoto) TypeRef() types.TypeRef {
return __typeRefForRemotePhoto
}
func init() {
__typeRefForRemotePhoto = types.MakeTypeRef(__mainPackageInFile_sha1_8829255_CachedRef, 1)
types.RegisterFromValFunction(__typeRefForRemotePhoto, func(v types.Value) types.Value {
return RemotePhotoFromVal(v)
})
}
func RemotePhotoFromVal(val types.Value) RemotePhoto {
// TODO: Do we still need FromVal?
if val, ok := val.(RemotePhoto); ok {
return val
}
// TODO: Validate here
return RemotePhoto{val.(types.Map), &ref.Ref{}}
}
func (s RemotePhoto) InternalImplementation() types.Map {
return s.m
}
func (s RemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(RemotePhoto); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s RemotePhoto) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s RemotePhoto) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s RemotePhoto) Id() string {
return s.m.Get(types.NewString("Id")).(types.String).String()
}
func (s RemotePhoto) SetId(val string) RemotePhoto {
return RemotePhoto{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
}
func (s RemotePhoto) Title() string {
return s.m.Get(types.NewString("Title")).(types.String).String()
}
func (s RemotePhoto) SetTitle(val string) RemotePhoto {
return RemotePhoto{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
}
func (s RemotePhoto) Url() string {
return s.m.Get(types.NewString("Url")).(types.String).String()
}
func (s RemotePhoto) SetUrl(val string) RemotePhoto {
return RemotePhoto{s.m.Set(types.NewString("Url"), types.NewString(val)), &ref.Ref{}}
}
func (s RemotePhoto) Geoposition() Geoposition {
return s.m.Get(types.NewString("Geoposition")).(Geoposition)
}
func (s RemotePhoto) SetGeoposition(val Geoposition) RemotePhoto {
return RemotePhoto{s.m.Set(types.NewString("Geoposition"), val), &ref.Ref{}}
}
func (s RemotePhoto) Sizes() MapOfSizeToString {
return s.m.Get(types.NewString("Sizes")).(MapOfSizeToString)
}
func (s RemotePhoto) SetSizes(val MapOfSizeToString) RemotePhoto {
return RemotePhoto{s.m.Set(types.NewString("Sizes"), val), &ref.Ref{}}
}
func (s RemotePhoto) Tags() SetOfString {
return s.m.Get(types.NewString("Tags")).(SetOfString)
}
func (s RemotePhoto) SetTags(val SetOfString) RemotePhoto {
return RemotePhoto{s.m.Set(types.NewString("Tags"), val), &ref.Ref{}}
}
// Size
type Size struct {
m types.Map
ref *ref.Ref
}
func NewSize() Size {
return Size{types.NewMap(
types.NewString("Width"), types.UInt32(0),
types.NewString("Height"), types.UInt32(0),
), &ref.Ref{}}
}
type SizeDef struct {
Width uint32
Height uint32
}
func (def SizeDef) New() Size {
return Size{
types.NewMap(
types.NewString("Width"), types.UInt32(def.Width),
types.NewString("Height"), types.UInt32(def.Height),
), &ref.Ref{}}
}
func (s Size) Def() (d SizeDef) {
d.Width = uint32(s.m.Get(types.NewString("Width")).(types.UInt32))
d.Height = uint32(s.m.Get(types.NewString("Height")).(types.UInt32))
return
}
var __typeRefForSize types.TypeRef
func (m Size) TypeRef() types.TypeRef {
return __typeRefForSize
}
func init() {
__typeRefForSize = types.MakeTypeRef(__mainPackageInFile_sha1_8829255_CachedRef, 2)
types.RegisterFromValFunction(__typeRefForSize, func(v types.Value) types.Value {
return SizeFromVal(v)
})
}
func SizeFromVal(val types.Value) Size {
// TODO: Do we still need FromVal?
if val, ok := val.(Size); ok {
return val
}
// TODO: Validate here
return Size{val.(types.Map), &ref.Ref{}}
}
func (s Size) InternalImplementation() types.Map {
return s.m
}
func (s Size) Equals(other types.Value) bool {
if other, ok := other.(Size); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s Size) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s Size) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.m.Chunks()...)
return
}
func (s Size) Width() uint32 {
return uint32(s.m.Get(types.NewString("Width")).(types.UInt32))
}
func (s Size) SetWidth(val uint32) Size {
return Size{s.m.Set(types.NewString("Width"), types.UInt32(val)), &ref.Ref{}}
}
func (s Size) Height() uint32 {
return uint32(s.m.Get(types.NewString("Height")).(types.UInt32))
}
func (s Size) SetHeight(val uint32) Size {
return Size{s.m.Set(types.NewString("Height"), types.UInt32(val)), &ref.Ref{}}
}
// SetOfString
type SetOfString struct {
s types.Set
ref *ref.Ref
}
func NewSetOfString() SetOfString {
return SetOfString{types.NewSet(), &ref.Ref{}}
}
type SetOfStringDef map[string]bool
func (def SetOfStringDef) New() SetOfString {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.NewString(d)
i++
}
return SetOfString{types.NewSet(l...), &ref.Ref{}}
}
func (s SetOfString) Def() SetOfStringDef {
def := make(map[string]bool, s.Len())
s.s.Iter(func(v types.Value) bool {
def[v.(types.String).String()] = true
return false
})
return def
}
func SetOfStringFromVal(val types.Value) SetOfString {
// TODO: Do we still need FromVal?
if val, ok := val.(SetOfString); ok {
return val
}
return SetOfString{val.(types.Set), &ref.Ref{}}
}
func (s SetOfString) InternalImplementation() types.Set {
return s.s
}
func (s SetOfString) Equals(other types.Value) bool {
if other, ok := other.(SetOfString); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s SetOfString) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s SetOfString) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.s.Chunks()...)
return
}
// A Noms Value that describes SetOfString.
var __typeRefForSetOfString types.TypeRef
func (m SetOfString) TypeRef() types.TypeRef {
return __typeRefForSetOfString
}
func init() {
__typeRefForSetOfString = types.MakeCompoundTypeRef(types.SetKind, types.MakePrimitiveTypeRef(types.StringKind))
types.RegisterFromValFunction(__typeRefForSetOfString, func(v types.Value) types.Value {
return SetOfStringFromVal(v)
})
}
func (s SetOfString) Empty() bool {
return s.s.Empty()
}
func (s SetOfString) Len() uint64 {
return s.s.Len()
}
func (s SetOfString) Has(p string) bool {
return s.s.Has(types.NewString(p))
}
type SetOfStringIterCallback func(p string) (stop bool)
func (s SetOfString) Iter(cb SetOfStringIterCallback) {
s.s.Iter(func(v types.Value) bool {
return cb(v.(types.String).String())
})
}
type SetOfStringIterAllCallback func(p string)
func (s SetOfString) IterAll(cb SetOfStringIterAllCallback) {
s.s.IterAll(func(v types.Value) {
cb(v.(types.String).String())
})
}
type SetOfStringFilterCallback func(p string) (keep bool)
func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
ns := NewSetOfString()
s.IterAll(func(v string) {
if cb(v) {
ns = ns.Insert(v)
}
})
return ns
}
func (s SetOfString) Insert(p ...string) SetOfString {
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
}
func (s SetOfString) Remove(p ...string) SetOfString {
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
}
func (s SetOfString) Union(others ...SetOfString) SetOfString {
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
}
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
}
func (s SetOfString) Any() string {
return s.s.Any().(types.String).String()
}
func (s SetOfString) fromStructSlice(p []SetOfString) []types.Set {
r := make([]types.Set, len(p))
for i, v := range p {
r[i] = v.s
}
return r
}
func (s SetOfString) fromElemSlice(p []string) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = types.NewString(v)
}
return r
}
// MapOfSizeToString
type MapOfSizeToString struct {
m types.Map
ref *ref.Ref
}
func NewMapOfSizeToString() MapOfSizeToString {
return MapOfSizeToString{types.NewMap(), &ref.Ref{}}
}
type MapOfSizeToStringDef map[SizeDef]string
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, k.New(), types.NewString(v))
}
return MapOfSizeToString{types.NewMap(kv...), &ref.Ref{}}
}
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
def := make(map[SizeDef]string)
m.m.Iter(func(k, v types.Value) bool {
def[k.(Size).Def()] = v.(types.String).String()
return false
})
return def
}
func MapOfSizeToStringFromVal(val types.Value) MapOfSizeToString {
// TODO: Do we still need FromVal?
if val, ok := val.(MapOfSizeToString); ok {
return val
}
// TODO: Validate here
return MapOfSizeToString{val.(types.Map), &ref.Ref{}}
}
func (m MapOfSizeToString) InternalImplementation() types.Map {
return m.m
}
func (m MapOfSizeToString) Equals(other types.Value) bool {
if other, ok := other.(MapOfSizeToString); ok {
return m.Ref() == other.Ref()
}
return false
}
func (m MapOfSizeToString) Ref() ref.Ref {
return types.EnsureRef(m.ref, m)
}
func (m MapOfSizeToString) Chunks() (futures []types.Future) {
futures = append(futures, m.TypeRef().Chunks()...)
futures = append(futures, m.m.Chunks()...)
return
}
// A Noms Value that describes MapOfSizeToString.
var __typeRefForMapOfSizeToString types.TypeRef
func (m MapOfSizeToString) TypeRef() types.TypeRef {
return __typeRefForMapOfSizeToString
}
func init() {
__typeRefForMapOfSizeToString = types.MakeCompoundTypeRef(types.MapKind, types.MakeTypeRef(__mainPackageInFile_sha1_8829255_CachedRef, 2), types.MakePrimitiveTypeRef(types.StringKind))
types.RegisterFromValFunction(__typeRefForMapOfSizeToString, func(v types.Value) types.Value {
return MapOfSizeToStringFromVal(v)
})
}
func (m MapOfSizeToString) Empty() bool {
return m.m.Empty()
}
func (m MapOfSizeToString) Len() uint64 {
return m.m.Len()
}
func (m MapOfSizeToString) Has(p Size) bool {
return m.m.Has(p)
}
func (m MapOfSizeToString) Get(p Size) string {
return m.m.Get(p).(types.String).String()
}
func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
v, ok := m.m.MaybeGet(p)
if !ok {
return "", false
}
return v.(types.String).String(), ok
}
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
}
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
func (m MapOfSizeToString) Iter(cb MapOfSizeToStringIterCallback) {
m.m.Iter(func(k, v types.Value) bool {
return cb(k.(Size), v.(types.String).String())
})
}
type MapOfSizeToStringIterAllCallback func(k Size, v string)
func (m MapOfSizeToString) IterAll(cb MapOfSizeToStringIterAllCallback) {
m.m.IterAll(func(k, v types.Value) {
cb(k.(Size), v.(types.String).String())
})
}
type MapOfSizeToStringFilterCallback func(k Size, v string) (keep bool)
func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeToString {
nm := NewMapOfSizeToString()
m.IterAll(func(k Size, v string) {
if cb(k, v) {
nm = nm.Set(k, v)
}
})
return nm
}
+26 -32
View File
@@ -9,70 +9,64 @@ import (
"github.com/attic-labs/noms/d"
"github.com/attic-labs/noms/datas"
"github.com/attic-labs/noms/dataset"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
var (
flags = datas.NewFlags()
inputID = flag.String("input-ds", "", "dataset to find photos within")
outputID = flag.String("output-ds", "", "dataset to store index in")
flags = datas.NewFlags()
inputRefFlag = flag.String("input-ref", "", "ref to root of a set of photos")
outputID = flag.String("output-ds", "", "dataset to store index in")
)
type targetRef interface {
TargetRef() ref.Ref
}
func main() {
flag.Parse()
store, ok := flags.CreateDataStore()
if !ok || *inputID == "" || *outputID == "" {
if !ok || *inputRefFlag == "" || *outputID == "" {
flag.Usage()
return
}
defer store.Close()
inputDS := dataset.NewDataset(store, *inputID)
if _, ok := inputDS.MaybeHead(); !ok {
log.Fatalf("No dataset named %s", *inputID)
var photoSet SetOfRefOfRemotePhoto
if d.Try(func() {
r := ref.Parse(*inputRefFlag)
photoSet = types.ReadValue(r, store).(SetOfRefOfRemotePhoto)
}) != nil {
log.Fatal("Invalid Ref: %s\n", *inputRefFlag)
}
outputDS := dataset.NewDataset(store, *outputID)
out := NewMapOfStringToSet()
out := NewMapOfStringToSetOfRefOfRemotePhoto()
t0 := time.Now()
numRefs := 0
numPhotos := 0
types.Some(inputDS.Head().Value().Ref(), store, func(f types.Future) (skip bool) {
photoSet.IterAll(func(r RefOfRemotePhoto) {
numRefs++
v := f.Deref(store)
if v, ok := v.(types.Map); ok {
name := v.Get(types.NewString("$name"))
if name == nil {
return
}
if !name.Equals(types.NewString("Photo")) && !name.Equals(types.NewString("RemotePhoto")) {
return
}
p := r.TargetValue(store)
tags := p.Tags()
skip = true
if !tags.Empty() {
numPhotos++
fmt.Println("Indexing", v.Ref())
fmt.Println("Indexing", p.Ref())
tags := SetOfStringFromVal(v.Get(types.NewString("tags")))
tags.Iter(func(item types.String) (stop bool) {
var s types.Set
if out.Has(item) {
s = out.Get(item)
} else {
s = types.NewSet()
}
out = out.Set(item, s.Insert(v))
return
tags.IterAll(func(item string) {
s, _ := out.MaybeGet(item)
out = out.Set(item, s.Insert(r))
})
}
return
})
_, ok = outputDS.Commit(out.NomsValue())
_, ok = outputDS.Commit(out)
d.Exp.True(ok, "Could not commit due to conflicting edit")
fmt.Printf("Indexed %v photos from %v refs in %v\n", numPhotos, numRefs, time.Now().Sub(t0))
-471
View File
@@ -1,471 +0,0 @@
// This file was generated by nomgen.
// To regenerate, run `go generate` in this package.
package main
import (
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
// RemotePhoto
type RemotePhoto struct {
m types.Map
}
func NewRemotePhoto() RemotePhoto {
return RemotePhoto{
types.NewMap(types.NewString("$name"), types.NewString("RemotePhoto")),
}
}
func RemotePhotoFromVal(v types.Value) RemotePhoto {
return RemotePhoto{v.(types.Map)}
}
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
func (s RemotePhoto) NomsValue() types.Map {
return s.m
}
func (s RemotePhoto) Equals(p RemotePhoto) bool {
return s.m.Equals(p.m)
}
func (s RemotePhoto) Ref() ref.Ref {
return s.m.Ref()
}
func (s RemotePhoto) Tags() SetOfString {
return SetOfStringFromVal(s.m.Get(types.NewString("tags")))
}
func (s RemotePhoto) SetTags(p SetOfString) RemotePhoto {
return RemotePhotoFromVal(s.m.Set(types.NewString("tags"), p.NomsValue()))
}
func (s RemotePhoto) Geoposition() Geoposition {
return GeopositionFromVal(s.m.Get(types.NewString("geoposition")))
}
func (s RemotePhoto) SetGeoposition(p Geoposition) RemotePhoto {
return RemotePhotoFromVal(s.m.Set(types.NewString("geoposition"), p.NomsValue()))
}
func (s RemotePhoto) Id() types.String {
return types.StringFromVal(s.m.Get(types.NewString("id")))
}
func (s RemotePhoto) SetId(p types.String) RemotePhoto {
return RemotePhotoFromVal(s.m.Set(types.NewString("id"), p))
}
func (s RemotePhoto) Title() types.String {
return types.StringFromVal(s.m.Get(types.NewString("title")))
}
func (s RemotePhoto) SetTitle(p types.String) RemotePhoto {
return RemotePhotoFromVal(s.m.Set(types.NewString("title"), p))
}
func (s RemotePhoto) Sizes() MapOfSizeToString {
return MapOfSizeToStringFromVal(s.m.Get(types.NewString("sizes")))
}
func (s RemotePhoto) SetSizes(p MapOfSizeToString) RemotePhoto {
return RemotePhotoFromVal(s.m.Set(types.NewString("sizes"), p.NomsValue()))
}
func (s RemotePhoto) Url() types.String {
return types.StringFromVal(s.m.Get(types.NewString("url")))
}
func (s RemotePhoto) SetUrl(p types.String) RemotePhoto {
return RemotePhotoFromVal(s.m.Set(types.NewString("url"), p))
}
// MapOfSizeToString
type MapOfSizeToString struct {
m types.Map
}
type MapOfSizeToStringIterCallback (func(k Size, v types.String) (stop bool))
func NewMapOfSizeToString() MapOfSizeToString {
return MapOfSizeToString{types.NewMap()}
}
func MapOfSizeToStringFromVal(p types.Value) MapOfSizeToString {
return MapOfSizeToString{p.(types.Map)}
}
func (m MapOfSizeToString) NomsValue() types.Map {
return m.m
}
func (m MapOfSizeToString) Equals(p MapOfSizeToString) bool {
return m.m.Equals(p.m)
}
func (m MapOfSizeToString) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfSizeToString) Empty() bool {
return m.m.Empty()
}
func (m MapOfSizeToString) Len() uint64 {
return m.m.Len()
}
func (m MapOfSizeToString) Has(p Size) bool {
return m.m.Has(p.NomsValue())
}
func (m MapOfSizeToString) Get(p Size) types.String {
return types.StringFromVal(m.m.Get(p.NomsValue()))
}
func (m MapOfSizeToString) Set(k Size, v types.String) MapOfSizeToString {
return MapOfSizeToStringFromVal(m.m.Set(k.NomsValue(), v))
}
// TODO: Implement SetM?
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
return MapOfSizeToStringFromVal(m.m.Remove(p.NomsValue()))
}
func (m MapOfSizeToString) Iter(cb MapOfSizeToStringIterCallback) {
m.m.Iter(func(k, v types.Value) bool {
return cb(SizeFromVal(k), types.StringFromVal(v))
})
}
// SetOfString
type SetOfString struct {
s types.Set
}
type SetOfStringIterCallback (func(p types.String) (stop bool))
func NewSetOfString() SetOfString {
return SetOfString{types.NewSet()}
}
func SetOfStringFromVal(p types.Value) SetOfString {
return SetOfString{p.(types.Set)}
}
func (s SetOfString) NomsValue() types.Set {
return s.s
}
func (s SetOfString) Equals(p SetOfString) bool {
return s.s.Equals(p.s)
}
func (s SetOfString) Ref() ref.Ref {
return s.s.Ref()
}
func (s SetOfString) Empty() bool {
return s.s.Empty()
}
func (s SetOfString) Len() uint64 {
return s.s.Len()
}
func (s SetOfString) Has(p types.String) bool {
return s.s.Has(p)
}
func (s SetOfString) Iter(cb SetOfStringIterCallback) {
s.s.Iter(func(v types.Value) bool {
return cb(types.StringFromVal(v))
})
}
func (s SetOfString) Insert(p ...types.String) SetOfString {
return SetOfString{s.s.Insert(s.fromElemSlice(p)...)}
}
func (s SetOfString) Remove(p ...types.String) SetOfString {
return SetOfString{s.s.Remove(s.fromElemSlice(p)...)}
}
func (s SetOfString) Union(others ...SetOfString) SetOfString {
return SetOfString{s.s.Union(s.fromStructSlice(others)...)}
}
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...)}
}
func (s SetOfString) Any() types.String {
return types.StringFromVal(s.s.Any())
}
func (s SetOfString) fromStructSlice(p []SetOfString) []types.Set {
r := make([]types.Set, len(p))
for i, v := range p {
r[i] = v.s
}
return r
}
func (s SetOfString) fromElemSlice(p []types.String) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = v
}
return r
}
// Size
type Size struct {
m types.Map
}
func NewSize() Size {
return Size{
types.NewMap(types.NewString("$name"), types.NewString("Size")),
}
}
func SizeFromVal(v types.Value) Size {
return Size{v.(types.Map)}
}
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
func (s Size) NomsValue() types.Map {
return s.m
}
func (s Size) Equals(p Size) bool {
return s.m.Equals(p.m)
}
func (s Size) Ref() ref.Ref {
return s.m.Ref()
}
func (s Size) Width() types.UInt32 {
return types.UInt32FromVal(s.m.Get(types.NewString("width")))
}
func (s Size) SetWidth(p types.UInt32) Size {
return SizeFromVal(s.m.Set(types.NewString("width"), p))
}
func (s Size) Height() types.UInt32 {
return types.UInt32FromVal(s.m.Get(types.NewString("height")))
}
func (s Size) SetHeight(p types.UInt32) Size {
return SizeFromVal(s.m.Set(types.NewString("height"), p))
}
// Photo
type Photo struct {
m types.Map
}
func NewPhoto() Photo {
return Photo{
types.NewMap(types.NewString("$name"), types.NewString("Photo")),
}
}
func PhotoFromVal(v types.Value) Photo {
return Photo{v.(types.Map)}
}
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
func (s Photo) NomsValue() types.Map {
return s.m
}
func (s Photo) Equals(p Photo) bool {
return s.m.Equals(p.m)
}
func (s Photo) Ref() ref.Ref {
return s.m.Ref()
}
func (s Photo) Tags() SetOfString {
return SetOfStringFromVal(s.m.Get(types.NewString("tags")))
}
func (s Photo) SetTags(p SetOfString) Photo {
return PhotoFromVal(s.m.Set(types.NewString("tags"), p.NomsValue()))
}
func (s Photo) Image() types.Blob {
return types.BlobFromVal(s.m.Get(types.NewString("image")))
}
func (s Photo) SetImage(p types.Blob) Photo {
return PhotoFromVal(s.m.Set(types.NewString("image"), p))
}
func (s Photo) Width() types.UInt32 {
return types.UInt32FromVal(s.m.Get(types.NewString("width")))
}
func (s Photo) SetWidth(p types.UInt32) Photo {
return PhotoFromVal(s.m.Set(types.NewString("width"), p))
}
func (s Photo) Geoposition() Geoposition {
return GeopositionFromVal(s.m.Get(types.NewString("geoposition")))
}
func (s Photo) SetGeoposition(p Geoposition) Photo {
return PhotoFromVal(s.m.Set(types.NewString("geoposition"), p.NomsValue()))
}
func (s Photo) Id() types.String {
return types.StringFromVal(s.m.Get(types.NewString("id")))
}
func (s Photo) SetId(p types.String) Photo {
return PhotoFromVal(s.m.Set(types.NewString("id"), p))
}
func (s Photo) Height() types.UInt32 {
return types.UInt32FromVal(s.m.Get(types.NewString("height")))
}
func (s Photo) SetHeight(p types.UInt32) Photo {
return PhotoFromVal(s.m.Set(types.NewString("height"), p))
}
func (s Photo) Title() types.String {
return types.StringFromVal(s.m.Get(types.NewString("title")))
}
func (s Photo) SetTitle(p types.String) Photo {
return PhotoFromVal(s.m.Set(types.NewString("title"), p))
}
func (s Photo) Url() types.String {
return types.StringFromVal(s.m.Get(types.NewString("url")))
}
func (s Photo) SetUrl(p types.String) Photo {
return PhotoFromVal(s.m.Set(types.NewString("url"), p))
}
// MapOfStringToSet
type MapOfStringToSet struct {
m types.Map
}
type MapOfStringToSetIterCallback (func(k types.String, v types.Set) (stop bool))
func NewMapOfStringToSet() MapOfStringToSet {
return MapOfStringToSet{types.NewMap()}
}
func MapOfStringToSetFromVal(p types.Value) MapOfStringToSet {
return MapOfStringToSet{p.(types.Map)}
}
func (m MapOfStringToSet) NomsValue() types.Map {
return m.m
}
func (m MapOfStringToSet) Equals(p MapOfStringToSet) bool {
return m.m.Equals(p.m)
}
func (m MapOfStringToSet) Ref() ref.Ref {
return m.m.Ref()
}
func (m MapOfStringToSet) Empty() bool {
return m.m.Empty()
}
func (m MapOfStringToSet) Len() uint64 {
return m.m.Len()
}
func (m MapOfStringToSet) Has(p types.String) bool {
return m.m.Has(p)
}
func (m MapOfStringToSet) Get(p types.String) types.Set {
return types.SetFromVal(m.m.Get(p))
}
func (m MapOfStringToSet) Set(k types.String, v types.Set) MapOfStringToSet {
return MapOfStringToSetFromVal(m.m.Set(k, v))
}
// TODO: Implement SetM?
func (m MapOfStringToSet) Remove(p types.String) MapOfStringToSet {
return MapOfStringToSetFromVal(m.m.Remove(p))
}
func (m MapOfStringToSet) Iter(cb MapOfStringToSetIterCallback) {
m.m.Iter(func(k, v types.Value) bool {
return cb(types.StringFromVal(k), types.SetFromVal(v))
})
}
// Geoposition
type Geoposition struct {
m types.Map
}
func NewGeoposition() Geoposition {
return Geoposition{
types.NewMap(types.NewString("$name"), types.NewString("Geoposition")),
}
}
func GeopositionFromVal(v types.Value) Geoposition {
return Geoposition{v.(types.Map)}
}
// TODO: This was going to be called Value() but it collides with root.value. We need some other place to put the built-in fields like Value() and Equals().
func (s Geoposition) NomsValue() types.Map {
return s.m
}
func (s Geoposition) Equals(p Geoposition) bool {
return s.m.Equals(p.m)
}
func (s Geoposition) Ref() ref.Ref {
return s.m.Ref()
}
func (s Geoposition) Latitude() types.Float32 {
return types.Float32FromVal(s.m.Get(types.NewString("latitude")))
}
func (s Geoposition) SetLatitude(p types.Float32) Geoposition {
return GeopositionFromVal(s.m.Set(types.NewString("latitude"), p))
}
func (s Geoposition) Longitude() types.Float32 {
return types.Float32FromVal(s.m.Get(types.NewString("longitude")))
}
func (s Geoposition) SetLongitude(p types.Float32) Geoposition {
return GeopositionFromVal(s.m.Set(types.NewString("longitude"), p))
}
+5
View File
@@ -0,0 +1,5 @@
alias Photo = import "../types/photo.noms"
using Map(String, Set(Ref(Photo.RemotePhoto)))
using Set(Ref(Photo.RemotePhoto))
using Set(String)
+356
View File
@@ -0,0 +1,356 @@
// This file was generated by nomdl/codegen.
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
// MapOfStringToSetOfRefOfRemotePhoto
type MapOfStringToSetOfRefOfRemotePhoto struct {
m types.Map
ref *ref.Ref
}
func NewMapOfStringToSetOfRefOfRemotePhoto() MapOfStringToSetOfRefOfRemotePhoto {
return MapOfStringToSetOfRefOfRemotePhoto{types.NewMap(), &ref.Ref{}}
}
type MapOfStringToSetOfRefOfRemotePhotoDef map[string]SetOfRefOfRemotePhotoDef
func (def MapOfStringToSetOfRefOfRemotePhotoDef) New() MapOfStringToSetOfRefOfRemotePhoto {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v.New())
}
return MapOfStringToSetOfRefOfRemotePhoto{types.NewMap(kv...), &ref.Ref{}}
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Def() MapOfStringToSetOfRefOfRemotePhotoDef {
def := make(map[string]SetOfRefOfRemotePhotoDef)
m.m.Iter(func(k, v types.Value) bool {
def[k.(types.String).String()] = v.(SetOfRefOfRemotePhoto).Def()
return false
})
return def
}
func MapOfStringToSetOfRefOfRemotePhotoFromVal(val types.Value) MapOfStringToSetOfRefOfRemotePhoto {
// TODO: Do we still need FromVal?
if val, ok := val.(MapOfStringToSetOfRefOfRemotePhoto); ok {
return val
}
// TODO: Validate here
return MapOfStringToSetOfRefOfRemotePhoto{val.(types.Map), &ref.Ref{}}
}
func (m MapOfStringToSetOfRefOfRemotePhoto) InternalImplementation() types.Map {
return m.m
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToSetOfRefOfRemotePhoto); ok {
return m.Ref() == other.Ref()
}
return false
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Ref() ref.Ref {
return types.EnsureRef(m.ref, m)
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Chunks() (futures []types.Future) {
futures = append(futures, m.TypeRef().Chunks()...)
futures = append(futures, m.m.Chunks()...)
return
}
// A Noms Value that describes MapOfStringToSetOfRefOfRemotePhoto.
var __typeRefForMapOfStringToSetOfRefOfRemotePhoto types.TypeRef
func (m MapOfStringToSetOfRefOfRemotePhoto) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToSetOfRefOfRemotePhoto
}
func init() {
__typeRefForMapOfStringToSetOfRefOfRemotePhoto = types.MakeCompoundTypeRef(types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeCompoundTypeRef(types.SetKind, types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(ref.Parse("sha1-8829255f15d0403222188a23b8ced0afdbee2a97"), 1))))
types.RegisterFromValFunction(__typeRefForMapOfStringToSetOfRefOfRemotePhoto, func(v types.Value) types.Value {
return MapOfStringToSetOfRefOfRemotePhotoFromVal(v)
})
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Empty() bool {
return m.m.Empty()
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Len() uint64 {
return m.m.Len()
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Has(p string) bool {
return m.m.Has(types.NewString(p))
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Get(p string) SetOfRefOfRemotePhoto {
return m.m.Get(types.NewString(p)).(SetOfRefOfRemotePhoto)
}
func (m MapOfStringToSetOfRefOfRemotePhoto) MaybeGet(p string) (SetOfRefOfRemotePhoto, bool) {
v, ok := m.m.MaybeGet(types.NewString(p))
if !ok {
return NewSetOfRefOfRemotePhoto(), false
}
return v.(SetOfRefOfRemotePhoto), ok
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Set(k string, v SetOfRefOfRemotePhoto) MapOfStringToSetOfRefOfRemotePhoto {
return MapOfStringToSetOfRefOfRemotePhoto{m.m.Set(types.NewString(k), v), &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToSetOfRefOfRemotePhoto) Remove(p string) MapOfStringToSetOfRefOfRemotePhoto {
return MapOfStringToSetOfRefOfRemotePhoto{m.m.Remove(types.NewString(p)), &ref.Ref{}}
}
type MapOfStringToSetOfRefOfRemotePhotoIterCallback func(k string, v SetOfRefOfRemotePhoto) (stop bool)
func (m MapOfStringToSetOfRefOfRemotePhoto) Iter(cb MapOfStringToSetOfRefOfRemotePhotoIterCallback) {
m.m.Iter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(SetOfRefOfRemotePhoto))
})
}
type MapOfStringToSetOfRefOfRemotePhotoIterAllCallback func(k string, v SetOfRefOfRemotePhoto)
func (m MapOfStringToSetOfRefOfRemotePhoto) IterAll(cb MapOfStringToSetOfRefOfRemotePhotoIterAllCallback) {
m.m.IterAll(func(k, v types.Value) {
cb(k.(types.String).String(), v.(SetOfRefOfRemotePhoto))
})
}
type MapOfStringToSetOfRefOfRemotePhotoFilterCallback func(k string, v SetOfRefOfRemotePhoto) (keep bool)
func (m MapOfStringToSetOfRefOfRemotePhoto) Filter(cb MapOfStringToSetOfRefOfRemotePhotoFilterCallback) MapOfStringToSetOfRefOfRemotePhoto {
nm := NewMapOfStringToSetOfRefOfRemotePhoto()
m.IterAll(func(k string, v SetOfRefOfRemotePhoto) {
if cb(k, v) {
nm = nm.Set(k, v)
}
})
return nm
}
// SetOfRefOfRemotePhoto
type SetOfRefOfRemotePhoto struct {
s types.Set
ref *ref.Ref
}
func NewSetOfRefOfRemotePhoto() SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{types.NewSet(), &ref.Ref{}}
}
type SetOfRefOfRemotePhotoDef map[ref.Ref]bool
func (def SetOfRefOfRemotePhotoDef) New() SetOfRefOfRemotePhoto {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfRemotePhoto(d)
i++
}
return SetOfRefOfRemotePhoto{types.NewSet(l...), &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Def() SetOfRefOfRemotePhotoDef {
def := make(map[ref.Ref]bool, s.Len())
s.s.Iter(func(v types.Value) bool {
def[v.(RefOfRemotePhoto).TargetRef()] = true
return false
})
return def
}
func SetOfRefOfRemotePhotoFromVal(val types.Value) SetOfRefOfRemotePhoto {
// TODO: Do we still need FromVal?
if val, ok := val.(SetOfRefOfRemotePhoto); ok {
return val
}
return SetOfRefOfRemotePhoto{val.(types.Set), &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) InternalImplementation() types.Set {
return s.s
}
func (s SetOfRefOfRemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(SetOfRefOfRemotePhoto); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s SetOfRefOfRemotePhoto) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s SetOfRefOfRemotePhoto) Chunks() (futures []types.Future) {
futures = append(futures, s.TypeRef().Chunks()...)
futures = append(futures, s.s.Chunks()...)
return
}
// A Noms Value that describes SetOfRefOfRemotePhoto.
var __typeRefForSetOfRefOfRemotePhoto types.TypeRef
func (m SetOfRefOfRemotePhoto) TypeRef() types.TypeRef {
return __typeRefForSetOfRefOfRemotePhoto
}
func init() {
__typeRefForSetOfRefOfRemotePhoto = types.MakeCompoundTypeRef(types.SetKind, types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(ref.Parse("sha1-8829255f15d0403222188a23b8ced0afdbee2a97"), 1)))
types.RegisterFromValFunction(__typeRefForSetOfRefOfRemotePhoto, func(v types.Value) types.Value {
return SetOfRefOfRemotePhotoFromVal(v)
})
}
func (s SetOfRefOfRemotePhoto) Empty() bool {
return s.s.Empty()
}
func (s SetOfRefOfRemotePhoto) Len() uint64 {
return s.s.Len()
}
func (s SetOfRefOfRemotePhoto) Has(p RefOfRemotePhoto) bool {
return s.s.Has(p)
}
type SetOfRefOfRemotePhotoIterCallback func(p RefOfRemotePhoto) (stop bool)
func (s SetOfRefOfRemotePhoto) Iter(cb SetOfRefOfRemotePhotoIterCallback) {
s.s.Iter(func(v types.Value) bool {
return cb(v.(RefOfRemotePhoto))
})
}
type SetOfRefOfRemotePhotoIterAllCallback func(p RefOfRemotePhoto)
func (s SetOfRefOfRemotePhoto) IterAll(cb SetOfRefOfRemotePhotoIterAllCallback) {
s.s.IterAll(func(v types.Value) {
cb(v.(RefOfRemotePhoto))
})
}
type SetOfRefOfRemotePhotoFilterCallback func(p RefOfRemotePhoto) (keep bool)
func (s SetOfRefOfRemotePhoto) Filter(cb SetOfRefOfRemotePhotoFilterCallback) SetOfRefOfRemotePhoto {
ns := NewSetOfRefOfRemotePhoto()
s.IterAll(func(v RefOfRemotePhoto) {
if cb(v) {
ns = ns.Insert(v)
}
})
return ns
}
func (s SetOfRefOfRemotePhoto) Insert(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Remove(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Union(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Subtract(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Any() RefOfRemotePhoto {
return s.s.Any().(RefOfRemotePhoto)
}
func (s SetOfRefOfRemotePhoto) fromStructSlice(p []SetOfRefOfRemotePhoto) []types.Set {
r := make([]types.Set, len(p))
for i, v := range p {
r[i] = v.s
}
return r
}
func (s SetOfRefOfRemotePhoto) fromElemSlice(p []RefOfRemotePhoto) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = v
}
return r
}
// RefOfRemotePhoto
type RefOfRemotePhoto struct {
target ref.Ref
ref *ref.Ref
}
func NewRefOfRemotePhoto(target ref.Ref) RefOfRemotePhoto {
return RefOfRemotePhoto{target, &ref.Ref{}}
}
func (r RefOfRemotePhoto) TargetRef() ref.Ref {
return r.target
}
func (r RefOfRemotePhoto) Ref() ref.Ref {
return types.EnsureRef(r.ref, r)
}
func (r RefOfRemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(RefOfRemotePhoto); ok {
return r.Ref() == other.Ref()
}
return false
}
func (r RefOfRemotePhoto) Chunks() []types.Future {
return r.TypeRef().Chunks()
}
func RefOfRemotePhotoFromVal(val types.Value) RefOfRemotePhoto {
// TODO: Do we still need FromVal?
if val, ok := val.(RefOfRemotePhoto); ok {
return val
}
return NewRefOfRemotePhoto(val.(types.Ref).TargetRef())
}
// A Noms Value that describes RefOfRemotePhoto.
var __typeRefForRefOfRemotePhoto types.TypeRef
func (m RefOfRemotePhoto) TypeRef() types.TypeRef {
return __typeRefForRefOfRemotePhoto
}
func init() {
__typeRefForRefOfRemotePhoto = types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(ref.Parse("sha1-8829255f15d0403222188a23b8ced0afdbee2a97"), 1))
types.RegisterFromValFunction(__typeRefForRefOfRemotePhoto, func(v types.Value) types.Value {
return RefOfRemotePhotoFromVal(v)
})
}
func (r RefOfRemotePhoto) TargetValue(cs chunks.ChunkSource) RemotePhoto {
return types.ReadValue(r.target, cs).(RemotePhoto)
}
func (r RefOfRemotePhoto) SetTargetValue(val RemotePhoto, cs chunks.ChunkSink) RefOfRemotePhoto {
return NewRefOfRemotePhoto(types.WriteValue(val, cs))
}