Migrate to use nomsdl codegen.

Use shared RemotePhoto object that flick examples uses. Add GeoPos information.
This commit is contained in:
Dan Willhite
2015-10-30 17:17:07 -07:00
parent 3e5c03887a
commit fd7a8973ce
7 changed files with 1803 additions and 228 deletions

View File

@@ -11,19 +11,15 @@ import (
"net"
"net/http"
"os"
"sort"
"strings"
"sync"
"time"
"strconv"
"strings"
"time"
"github.com/attic-labs/noms/Godeps/_workspace/src/golang.org/x/oauth2"
"github.com/attic-labs/noms/Godeps/_workspace/src/golang.org/x/oauth2/google"
"github.com/attic-labs/noms/clients/util"
"github.com/attic-labs/noms/d"
"github.com/attic-labs/noms/dataset"
"github.com/attic-labs/noms/marshal"
"github.com/attic-labs/noms/types"
)
@@ -60,33 +56,37 @@ func main() {
}
defer ds.Close()
var cu types.Value
var currentUser *User
if commit, ok := ds.MaybeHead(); ok {
cu = commit.Value()
currentUserRef := commit.Value().(RefOfUser)
cu := currentUserRef.TargetValue(ds.Store())
currentUser = &cu
}
c, refreshToken := doAuthentication(cu)
authHTTPClient = c
var refreshToken string
authHTTPClient, refreshToken = doAuthentication(currentUser)
// set start after authentication so we don't count that time
start = time.Now()
var nomsUser types.Value
var user *User
if *albumIDFlag != "" {
newNomsUser, newNomsAlbum, _ := getAlbum(*albumIDFlag)
if cu != nil {
nomsUser = mergeInCurrentAlbums(cu, newNomsUser, newNomsAlbum)
newUser := getSingleAlbum(*albumIDFlag)
if currentUser != nil {
user = mergeInCurrentAlbums(currentUser, newUser)
} else {
nomsUser = newNomsUser
user = newUser
}
printStats(newNomsUser)
} else {
nomsUser = getAlbums()
printStats(nomsUser)
user = getAlbums()
}
nomsUser = setValueInNomsMap(nomsUser, "RefreshToken", types.NewString(refreshToken))
_, ok := ds.Commit(nomsUser)
printStats(user)
*user = user.SetRefreshToken(refreshToken)
userRef := types.WriteValue(user, ds.Store())
fmt.Printf("userRef: %s\n", userRef)
_, ok := ds.Commit(NewRefOfUser(userRef))
d.Exp.True(ok, "Could not commit due to conflicting edit")
}
@@ -111,55 +111,57 @@ func picasaUsage() {
fmt.Fprintf(os.Stderr, "\n%s\n\n", credentialSteps)
}
func getAlbum(albumID string) (nomsUser types.Value, nomsAlbum types.Value, nomsPhotoList types.Value) {
func getSingleAlbum(albumID string) *User {
aj := AlbumJSON{}
path := fmt.Sprintf("user/default/albumid/%s?alt=json&max-results=0", albumID)
callPicasaAPI(authHTTPClient, path, &aj)
u := User{ID: aj.Feed.UserID.V, Name: aj.Feed.UserName.V}
a := Album{ID: aj.Feed.ID.V, Title: aj.Feed.Title.V, NumPhotos: aj.Feed.NumPhotos.V}
nomsPhotoList = getPhotos(a, 1)
nomsAlbum = marshal.Marshal(a)
nomsAlbum = setValueInNomsMap(nomsAlbum, "Photos", nomsPhotoList)
nomsUser = marshal.Marshal(u)
nomsUser = setValueInNomsMap(nomsUser, "Albums", types.NewList(nomsAlbum))
return nomsUser, nomsAlbum, nomsPhotoList
u := UserDef{Id: aj.Feed.UserID.V, Name: aj.Feed.UserName.V}.New()
albums := NewMapOfStringToAlbum()
albums = getAlbum(0, aj.Feed.ID.V, aj.Feed.Title.V, uint32(aj.Feed.NumPhotos.V), albums)
types.WriteValue(albums, ds.Store())
u = u.SetAlbums(albums)
return &u
}
func getAlbums() (nomsUser types.Value) {
aj := AlbumListJSON{}
callPicasaAPI(authHTTPClient, "user/default?alt=json", &aj)
user := User{ID: aj.Feed.UserID.V, Name: aj.Feed.UserName.V}
func getAlbums() *User {
alj := AlbumListJSON{}
callPicasaAPI(authHTTPClient, "user/default?alt=json", &alj)
if !*quietFlag {
fmt.Printf("Found %d albums\n", len(aj.Feed.Entry))
fmt.Printf("Found %d albums\n", len(alj.Feed.Entry))
}
var nomsAlbumList = types.NewList()
for i, entry := range aj.Feed.Entry {
a := Album{ID: entry.ID.V, Title: entry.Title.V, NumPhotos: entry.NumPhotos.V}
nomsPhotoList := getPhotos(a, i)
nomsAlbum := marshal.Marshal(a)
nomsAlbum = setValueInNomsMap(nomsAlbum, "Photos", nomsPhotoList)
nomsAlbumList = nomsAlbumList.Append(nomsAlbum)
albums := NewMapOfStringToAlbum()
user := UserDef{Id: alj.Feed.UserID.V, Name: alj.Feed.UserName.V}.New()
for i, entry := range alj.Feed.Entry {
albums = getAlbum(i, entry.ID.V, entry.Title.V, uint32(entry.NumPhotos.V), albums)
}
nomsUser = marshal.Marshal(user)
nomsUser = setValueInNomsMap(nomsUser, "Albums", nomsAlbumList)
return nomsUser
types.WriteValue(albums, ds.Store())
user = user.SetAlbums(albums)
return &user
}
func getPhotos(album Album, albumIndex int) (nomsPhotoList types.List) {
if album.NumPhotos <= 0 {
return types.NewList()
func getAlbum(albumIndex int, albumId, albumTitle string, numPhotos uint32, albums MapOfStringToAlbum) MapOfStringToAlbum {
a := AlbumDef{Id: albumId, Title: albumTitle, NumPhotos: uint32(numPhotos)}.New()
remotePhotoRefs := getRemotePhotoRefs(&a, albumIndex)
r := types.WriteValue(remotePhotoRefs, ds.Store())
a = a.SetPhotos(NewRefOfSetOfRefOfRemotePhoto(r))
return albums.Set(a.Id(), a)
}
func getRemotePhotoRefs(album *Album, albumIndex int) *SetOfRefOfRemotePhoto {
if album.NumPhotos() <= 0 {
return nil
}
photos := make([]Photo, 0, album.NumPhotos)
remotePhotoRefs := NewSetOfRefOfRemotePhoto()
if !*quietFlag {
fmt.Printf("Album #%d: %q contains %d photos... ", albumIndex, album.Title, album.NumPhotos)
fmt.Printf("Album #%d: %q contains %d photos... ", albumIndex, album.Title(), album.NumPhotos())
}
for startIndex, foundPhotos := 0, true; album.NumPhotos > len(photos) && foundPhotos; startIndex += 1000 {
for startIndex, foundPhotos := 0, true; uint64(album.NumPhotos()) > remotePhotoRefs.Len() && foundPhotos; startIndex += 1000 {
foundPhotos = false
aj := AlbumJSON{}
path := fmt.Sprintf("user/default/albumid/%s?alt=json&max-results=1000", album.ID)
path := fmt.Sprintf("user/default/albumid/%s?alt=json&max-results=1000", album.Id())
if !*smallFlag {
path = fmt.Sprintf("%s%s", path, "&imgmax=d")
}
@@ -172,120 +174,54 @@ func getPhotos(album Album, albumIndex int) (nomsPhotoList types.List) {
tags := splitTags(e.MediaGroup.Tags.V)
height, _ := strconv.Atoi(e.Height.V)
width, _ := strconv.Atoi(e.Width.V)
p := Photo{
NomsName: "Photo",
Height: int(height),
ID: e.ID.V,
Tags: tags,
Title: e.Title.V,
URL: e.Content.Src,
Width: int(width),
}
photos = append(photos, p)
size := SizeDef{Height: uint32(height), Width: uint32(width)}
sizes := MapOfSizeToStringDef{}
sizes[size] = e.Content.Src
geoPos := toGeopos(e.Geo.Point.Pos.V)
p := RemotePhotoDef{
Id: e.ID.V,
Title: e.Title.V,
Geoposition: geoPos,
Url: e.Content.Src,
Sizes: sizes,
Tags: tags,
}.New()
r := types.WriteValue(p, ds.Store())
remotePhotoRefs = remotePhotoRefs.Insert(NewRefOfRemotePhoto(r))
}
}
pChan, rChan := getImageFetcher(len(photos))
for i, p := range photos {
pChan <- PhotoMessage{i, p}
}
close(pChan)
refMessages := make([]RefMessage, 0, album.NumPhotos)
for rm := range rChan {
refMessages = append(refMessages, rm)
}
sort.Sort(ByIndex(refMessages))
nomsPhotoList = types.NewList()
for _, refMsg := range refMessages {
nomsPhotoList = nomsPhotoList.Append(types.NewRef(refMsg.Ref))
}
if !*quietFlag {
fmt.Printf("fetched %d, elapsed time: %.2f secs\n", nomsPhotoList.Len(), time.Now().Sub(start).Seconds())
fmt.Printf("fetched %d, elapsed time: %.2f secs\n", remotePhotoRefs.Len(), time.Now().Sub(start).Seconds())
}
return nomsPhotoList
return &remotePhotoRefs
}
func getImageFetcher(numPhotos int) (pChan chan PhotoMessage, rChan chan RefMessage) {
pChan = make(chan PhotoMessage, numPhotos)
rChan = make(chan RefMessage)
var wg sync.WaitGroup
n := min(numPhotos, maxProcs)
for i := 0; i < n; i++ {
wg.Add(1)
go func(fid int) {
for msg := range pChan {
msg.Photo.Image = getImage(msg.Photo.URL)
nomsPhoto := marshal.Marshal(msg.Photo)
ref := types.WriteValue(nomsPhoto, ds.Store())
rChan <- RefMessage{msg.Index, ref}
}
wg.Done()
}(i)
}
go func() {
wg.Wait()
close(rChan)
}()
return
}
func getImage(url string) *bytes.Reader {
pr := getImageReader(url)
defer pr.Close()
buf, err := ioutil.ReadAll(pr)
d.Chk.NoError(err)
return bytes.NewReader(buf)
}
func getImageReader(url string) io.ReadCloser {
r, err := cachingHTTPClient.Get(url)
d.Chk.NoError(err)
return r.Body
}
func printStats(nomsUser types.Value) {
func printStats(user *User) {
if !*quietFlag {
numPhotos := uint64(0)
nomsAlbums := getValueInNomsMap(nomsUser, "Albums").(types.List)
for i := uint64(0); i < nomsAlbums.Len(); i++ {
nomsAlbum := nomsAlbums.Get(i)
nomsPhotos := getValueInNomsMap(nomsAlbum, "Photos").(types.List)
numPhotos = numPhotos + nomsPhotos.Len()
}
albums := user.Albums()
albums.IterAll(func(id string, album Album) {
setOfRefOfPhotos := album.Photos().TargetValue(ds.Store())
numPhotos = numPhotos + setOfRefOfPhotos.Len()
})
fmt.Printf("Imported %d album(s), %d photo(s), time: %.2f\n", nomsAlbums.Len(), numPhotos, time.Now().Sub(start).Seconds())
fmt.Printf("Imported %d album(s), %d photo(s), time: %.2f\n", albums.Len(), numPhotos, time.Now().Sub(start).Seconds())
}
}
func mergeInCurrentAlbums(cu, newNomsUser, newNomsAlbum types.Value) (nomsUser types.Value) {
newAlbumID := getValueInNomsMap(newNomsAlbum, "ID").(types.String).String()
oldNomsAlbums := getValueInNomsMap(cu, "Albums").(types.List)
newNomsAlbums := types.NewList()
inserted := false
for i := uint64(0); i < uint64(oldNomsAlbums.Len()); i++ {
oldNomsAlbum := oldNomsAlbums.Get(i)
oldAlbumID := getValueInNomsMap(oldNomsAlbum, "ID").(types.String).String()
if newAlbumID != oldAlbumID {
newNomsAlbums = newNomsAlbums.Append(oldNomsAlbum)
} else {
inserted = true
newNomsAlbums = newNomsAlbums.Append(newNomsAlbum)
}
}
if !inserted {
newNomsAlbums = newNomsAlbums.Append(newNomsAlbum)
}
nomsUser = setValueInNomsMap(newNomsUser, "Albums", newNomsAlbums)
return
func mergeInCurrentAlbums(curUser *User, newUser *User) *User {
albums := curUser.Albums()
newUser.Albums().IterAll(func(id string, a Album) {
albums = albums.Set(id, a)
})
*newUser = newUser.SetAlbums(albums)
return newUser
}
func doAuthentication(currentUser types.Value) (c *http.Client, rt string) {
func doAuthentication(currentUser *User) (c *http.Client, rt string) {
if !*forceAuthFlag && currentUser != nil {
rt = getValueInNomsMap(currentUser, "RefreshToken").(types.String).String()
rt = currentUser.RefreshToken()
c = tryRefreshToken(rt)
}
if c == nil {
@@ -399,13 +335,21 @@ func baseConfig(redirectURL string) *oauth2.Config {
}
// General utility functions
func getValueInNomsMap(m types.Value, field string) types.Value {
return m.(types.Map).Get(types.NewString(field))
}
func setValueInNomsMap(m types.Value, field string, value types.Value) types.Value {
return m.(types.Map).Set(types.NewString(field), value)
func toGeopos(s string) GeopositionDef {
s1 := strings.TrimSpace(s)
geoPos := GeopositionDef{Latitude: 0.0, Longitude: 0.0}
if s1 != "" {
slice := strings.Split(s1, " ")
lat, err := strconv.ParseFloat(slice[0], 32)
if err == nil {
geoPos.Latitude = float32(lat)
}
lon, err := strconv.ParseFloat(slice[1], 32)
if err == nil {
geoPos.Longitude = float32(lon)
}
}
return geoPos
}
func toJSON(str interface{}) string {
@@ -414,13 +358,6 @@ func toJSON(str interface{}) string {
return string(v)
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func splitTags(s string) map[string]bool {
tags := map[string]bool{}
for _, s := range strings.Split(s, ",") {

View File

@@ -0,0 +1,21 @@
alias Img = import "../common/photo.noms"
struct User {
Id: String
Name: String
Albums: Map(String, Album)
RefreshToken: String
OAuthToken: String
OAuthSecret: String
}
struct Album {
Id: String
Title: String
NumPhotos: UInt32
Photos: Ref(Set(Ref(Img.RemotePhoto)))
}
using Map(String, Album)
using Set(Img.RemotePhoto)
using Ref(User)

View File

@@ -0,0 +1,895 @@
// 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"
)
var __mainPackageInFile_picasa_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("User",
[]types.Field{
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Name", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Albums", types.MakeCompoundTypeRef(types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(ref.Ref{}, 1)), false},
types.Field{"RefreshToken", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"OAuthToken", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"OAuthSecret", types.MakePrimitiveTypeRef(types.StringKind), false},
},
types.Choices{},
),
types.MakeStructTypeRef("Album",
[]types.Field{
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
types.Field{"NumPhotos", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
types.Field{"Photos", types.MakeCompoundTypeRef(types.RefKind, types.MakeCompoundTypeRef(types.SetKind, types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(ref.Parse("sha1-00419ebbb418539af67238164b20341913efeb4d"), 0)))), false},
},
types.Choices{},
),
}, []ref.Ref{
ref.Parse("sha1-00419ebbb418539af67238164b20341913efeb4d"),
})
__mainPackageInFile_picasa_CachedRef = types.RegisterPackage(&p)
}
// User
type User struct {
m types.Map
ref *ref.Ref
}
func NewUser() User {
return User{types.NewMap(
types.NewString("Id"), types.NewString(""),
types.NewString("Name"), types.NewString(""),
types.NewString("Albums"), NewMapOfStringToAlbum(),
types.NewString("RefreshToken"), types.NewString(""),
types.NewString("OAuthToken"), types.NewString(""),
types.NewString("OAuthSecret"), types.NewString(""),
), &ref.Ref{}}
}
type UserDef struct {
Id string
Name string
Albums MapOfStringToAlbumDef
RefreshToken string
OAuthToken string
OAuthSecret string
}
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("Albums"), def.Albums.New(),
types.NewString("RefreshToken"), types.NewString(def.RefreshToken),
types.NewString("OAuthToken"), types.NewString(def.OAuthToken),
types.NewString("OAuthSecret"), types.NewString(def.OAuthSecret),
), &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.Albums = s.m.Get(types.NewString("Albums")).(MapOfStringToAlbum).Def()
d.RefreshToken = s.m.Get(types.NewString("RefreshToken")).(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()
return
}
var __typeRefForUser types.TypeRef
func (m User) TypeRef() types.TypeRef {
return __typeRefForUser
}
func init() {
__typeRefForUser = types.MakeTypeRef(__mainPackageInFile_picasa_CachedRef, 0)
types.RegisterFromValFunction(__typeRefForUser, func(v types.Value) types.Value {
return UserFromVal(v)
})
}
func UserFromVal(val types.Value) User {
// TODO: Do we still need FromVal?
if val, ok := val.(User); ok {
return val
}
// TODO: Validate here
return User{val.(types.Map), &ref.Ref{}}
}
func (s User) InternalImplementation() types.Map {
return s.m
}
func (s User) Equals(other types.Value) bool {
if other, ok := other.(User); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s User) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s User) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, s.m.Chunks()...)
return
}
func (s User) Id() string {
return s.m.Get(types.NewString("Id")).(types.String).String()
}
func (s User) SetId(val string) User {
return User{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
}
func (s User) Name() string {
return s.m.Get(types.NewString("Name")).(types.String).String()
}
func (s User) SetName(val string) User {
return User{s.m.Set(types.NewString("Name"), types.NewString(val)), &ref.Ref{}}
}
func (s User) Albums() MapOfStringToAlbum {
return s.m.Get(types.NewString("Albums")).(MapOfStringToAlbum)
}
func (s User) SetAlbums(val MapOfStringToAlbum) User {
return User{s.m.Set(types.NewString("Albums"), val), &ref.Ref{}}
}
func (s User) RefreshToken() string {
return s.m.Get(types.NewString("RefreshToken")).(types.String).String()
}
func (s User) SetRefreshToken(val string) User {
return User{s.m.Set(types.NewString("RefreshToken"), types.NewString(val)), &ref.Ref{}}
}
func (s User) OAuthToken() string {
return s.m.Get(types.NewString("OAuthToken")).(types.String).String()
}
func (s User) SetOAuthToken(val string) User {
return User{s.m.Set(types.NewString("OAuthToken"), types.NewString(val)), &ref.Ref{}}
}
func (s User) OAuthSecret() string {
return s.m.Get(types.NewString("OAuthSecret")).(types.String).String()
}
func (s User) SetOAuthSecret(val string) User {
return User{s.m.Set(types.NewString("OAuthSecret"), types.NewString(val)), &ref.Ref{}}
}
// Album
type Album struct {
m types.Map
ref *ref.Ref
}
func NewAlbum() Album {
return Album{types.NewMap(
types.NewString("Id"), types.NewString(""),
types.NewString("Title"), types.NewString(""),
types.NewString("NumPhotos"), types.UInt32(0),
types.NewString("Photos"), NewRefOfSetOfRefOfRemotePhoto(ref.Ref{}),
), &ref.Ref{}}
}
type AlbumDef struct {
Id string
Title string
NumPhotos uint32
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("NumPhotos"), types.UInt32(def.NumPhotos),
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.NumPhotos = uint32(s.m.Get(types.NewString("NumPhotos")).(types.UInt32))
d.Photos = s.m.Get(types.NewString("Photos")).(RefOfSetOfRefOfRemotePhoto).TargetRef()
return
}
var __typeRefForAlbum types.TypeRef
func (m Album) TypeRef() types.TypeRef {
return __typeRefForAlbum
}
func init() {
__typeRefForAlbum = types.MakeTypeRef(__mainPackageInFile_picasa_CachedRef, 1)
types.RegisterFromValFunction(__typeRefForAlbum, func(v types.Value) types.Value {
return AlbumFromVal(v)
})
}
func AlbumFromVal(val types.Value) Album {
// TODO: Do we still need FromVal?
if val, ok := val.(Album); ok {
return val
}
// TODO: Validate here
return Album{val.(types.Map), &ref.Ref{}}
}
func (s Album) InternalImplementation() types.Map {
return s.m
}
func (s Album) Equals(other types.Value) bool {
if other, ok := other.(Album); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s Album) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s Album) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, s.m.Chunks()...)
return
}
func (s Album) Id() string {
return s.m.Get(types.NewString("Id")).(types.String).String()
}
func (s Album) SetId(val string) Album {
return Album{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
}
func (s Album) Title() string {
return s.m.Get(types.NewString("Title")).(types.String).String()
}
func (s Album) SetTitle(val string) Album {
return Album{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
}
func (s Album) NumPhotos() uint32 {
return uint32(s.m.Get(types.NewString("NumPhotos")).(types.UInt32))
}
func (s Album) SetNumPhotos(val uint32) Album {
return Album{s.m.Set(types.NewString("NumPhotos"), types.UInt32(val)), &ref.Ref{}}
}
func (s Album) Photos() RefOfSetOfRefOfRemotePhoto {
return s.m.Get(types.NewString("Photos")).(RefOfSetOfRefOfRemotePhoto)
}
func (s Album) SetPhotos(val RefOfSetOfRefOfRemotePhoto) Album {
return Album{s.m.Set(types.NewString("Photos"), val), &ref.Ref{}}
}
// MapOfStringToAlbum
type MapOfStringToAlbum struct {
m types.Map
ref *ref.Ref
}
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 {
return val
}
// TODO: Validate here
return MapOfStringToAlbum{val.(types.Map), &ref.Ref{}}
}
func (m MapOfStringToAlbum) InternalImplementation() types.Map {
return m.m
}
func (m MapOfStringToAlbum) Equals(other types.Value) bool {
if other, ok := other.(MapOfStringToAlbum); ok {
return m.Ref() == other.Ref()
}
return false
}
func (m MapOfStringToAlbum) Ref() ref.Ref {
return types.EnsureRef(m.ref, m)
}
func (m MapOfStringToAlbum) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, m.TypeRef().Chunks()...)
chunks = append(chunks, m.m.Chunks()...)
return
}
// A Noms Value that describes MapOfStringToAlbum.
var __typeRefForMapOfStringToAlbum types.TypeRef
func (m MapOfStringToAlbum) TypeRef() types.TypeRef {
return __typeRefForMapOfStringToAlbum
}
func init() {
__typeRefForMapOfStringToAlbum = types.MakeCompoundTypeRef(types.MapKind, types.MakePrimitiveTypeRef(types.StringKind), types.MakeTypeRef(__mainPackageInFile_picasa_CachedRef, 1))
types.RegisterFromValFunction(__typeRefForMapOfStringToAlbum, func(v types.Value) types.Value {
return MapOfStringToAlbumFromVal(v)
})
}
func (m MapOfStringToAlbum) Empty() bool {
return m.m.Empty()
}
func (m MapOfStringToAlbum) Len() uint64 {
return m.m.Len()
}
func (m MapOfStringToAlbum) Has(p string) bool {
return m.m.Has(types.NewString(p))
}
func (m MapOfStringToAlbum) Get(p string) Album {
return m.m.Get(types.NewString(p)).(Album)
}
func (m MapOfStringToAlbum) MaybeGet(p string) (Album, bool) {
v, ok := m.m.MaybeGet(types.NewString(p))
if !ok {
return NewAlbum(), false
}
return v.(Album), ok
}
func (m MapOfStringToAlbum) Set(k string, v Album) MapOfStringToAlbum {
return MapOfStringToAlbum{m.m.Set(types.NewString(k), v), &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToAlbum) Remove(p string) MapOfStringToAlbum {
return MapOfStringToAlbum{m.m.Remove(types.NewString(p)), &ref.Ref{}}
}
type MapOfStringToAlbumIterCallback func(k string, v Album) (stop bool)
func (m MapOfStringToAlbum) Iter(cb MapOfStringToAlbumIterCallback) {
m.m.Iter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(Album))
})
}
type MapOfStringToAlbumIterAllCallback func(k string, v Album)
func (m MapOfStringToAlbum) IterAll(cb MapOfStringToAlbumIterAllCallback) {
m.m.IterAll(func(k, v types.Value) {
cb(k.(types.String).String(), v.(Album))
})
}
type MapOfStringToAlbumFilterCallback func(k string, v Album) (keep bool)
func (m MapOfStringToAlbum) Filter(cb MapOfStringToAlbumFilterCallback) MapOfStringToAlbum {
nm := NewMapOfStringToAlbum()
m.IterAll(func(k string, v Album) {
if cb(k, v) {
nm = nm.Set(k, v)
}
})
return nm
}
// SetOfRemotePhoto
type SetOfRemotePhoto struct {
s types.Set
ref *ref.Ref
}
func NewSetOfRemotePhoto() SetOfRemotePhoto {
return SetOfRemotePhoto{types.NewSet(), &ref.Ref{}}
}
func SetOfRemotePhotoFromVal(val types.Value) SetOfRemotePhoto {
// TODO: Do we still need FromVal?
if val, ok := val.(SetOfRemotePhoto); ok {
return val
}
return SetOfRemotePhoto{val.(types.Set), &ref.Ref{}}
}
func (s SetOfRemotePhoto) InternalImplementation() types.Set {
return s.s
}
func (s SetOfRemotePhoto) Equals(other types.Value) bool {
if other, ok := other.(SetOfRemotePhoto); ok {
return s.Ref() == other.Ref()
}
return false
}
func (s SetOfRemotePhoto) Ref() ref.Ref {
return types.EnsureRef(s.ref, s)
}
func (s SetOfRemotePhoto) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, s.s.Chunks()...)
return
}
// A Noms Value that describes SetOfRemotePhoto.
var __typeRefForSetOfRemotePhoto types.TypeRef
func (m SetOfRemotePhoto) TypeRef() types.TypeRef {
return __typeRefForSetOfRemotePhoto
}
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)
})
}
func (s SetOfRemotePhoto) Empty() bool {
return s.s.Empty()
}
func (s SetOfRemotePhoto) Len() uint64 {
return s.s.Len()
}
func (s SetOfRemotePhoto) Has(p RemotePhoto) bool {
return s.s.Has(p)
}
type SetOfRemotePhotoIterCallback func(p RemotePhoto) (stop bool)
func (s SetOfRemotePhoto) Iter(cb SetOfRemotePhotoIterCallback) {
s.s.Iter(func(v types.Value) bool {
return cb(v.(RemotePhoto))
})
}
type SetOfRemotePhotoIterAllCallback func(p RemotePhoto)
func (s SetOfRemotePhoto) IterAll(cb SetOfRemotePhotoIterAllCallback) {
s.s.IterAll(func(v types.Value) {
cb(v.(RemotePhoto))
})
}
type SetOfRemotePhotoFilterCallback func(p RemotePhoto) (keep bool)
func (s SetOfRemotePhoto) Filter(cb SetOfRemotePhotoFilterCallback) SetOfRemotePhoto {
ns := NewSetOfRemotePhoto()
s.IterAll(func(v RemotePhoto) {
if cb(v) {
ns = ns.Insert(v)
}
})
return ns
}
func (s SetOfRemotePhoto) Insert(p ...RemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{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 SetOfRemotePhoto) Union(others ...SetOfRemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{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 SetOfRemotePhoto) Any() RemotePhoto {
return s.s.Any().(RemotePhoto)
}
func (s SetOfRemotePhoto) fromStructSlice(p []SetOfRemotePhoto) []types.Set {
r := make([]types.Set, len(p))
for i, v := range p {
r[i] = v.s
}
return r
}
func (s SetOfRemotePhoto) fromElemSlice(p []RemotePhoto) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = v
}
return r
}
// RefOfUser
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() []ref.Ref {
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_picasa_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() []ref.Ref {
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-00419ebbb418539af67238164b20341913efeb4d"), 0))))
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 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() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, 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-00419ebbb418539af67238164b20341913efeb4d"), 0)))
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() []ref.Ref {
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-00419ebbb418539af67238164b20341913efeb4d"), 0))
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))
}

3
clients/picasa/rungen.go Normal file
View File

@@ -0,0 +1,3 @@
package main
//go:generate go run ../../nomdl/codegen/codegen.go -package=main -out-dir=.

View File

@@ -0,0 +1,558 @@
// 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_00419eb_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("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{"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_00419eb_CachedRef = types.RegisterPackage(&p)
}
// 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_00419eb_CachedRef, 0)
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() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, 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_00419eb_CachedRef, 1)
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() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, 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{}}
}
// 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() (chunks []ref.Ref) {
chunks = append(chunks, m.TypeRef().Chunks()...)
chunks = append(chunks, 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 {
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() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, 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
}

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() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, 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() (chunks []ref.Ref) {
chunks = append(chunks, s.TypeRef().Chunks()...)
chunks = append(chunks, 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{}}
}

View File

@@ -1,68 +1,5 @@
package main
import (
"bytes"
"github.com/attic-labs/noms/ref"
)
// Photo is represents all the info about images that we download from picasa
// including the image itself
type Photo struct {
NomsName string `noms:"$name"`
Height int `noms:"height"`
ID string `noms:"ID"`
Image *bytes.Reader `noms:"image"`
Tags map[string]bool `noms:"tags"`
Title string `noms:"title"`
URL string `noms:"URL"`
Width int `noms:"width"`
}
// Album represents all the info about picassa albums including the list of
// photos it contains
type Album struct {
ID string
Title string
NumPhotos int
}
// User represents the user who authenticated and a list of albums.
type User struct {
ID string
Name string
Albums []Album
}
// PhotoMessage is used for communicating with Go routines that fetch photos
type PhotoMessage struct {
Index int
Photo Photo
}
// RefMessage is used for communicating results of photo fetch back to func main() {
// program
type RefMessage struct {
Index int
Ref ref.Ref
}
// ByIndex is used for sorting RefMessages by index field
type ByIndex []RefMessage
func (slice ByIndex) Len() int {
return len(slice)
}
func (slice ByIndex) Less(i, j int) bool {
return slice[i].Index < slice[j].Index
}
func (slice ByIndex) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}
// AlbumJSON is used for unmarshalling results from picasa 'list photos on album' api
type AlbumJSON struct {
Feed struct {
UserName struct {
@@ -108,6 +45,13 @@ type AlbumJSON struct {
Width struct {
V string `json:"$t"`
} `json:"gphoto$wIDth"`
Geo struct {
Point struct {
Pos struct {
V string `json:"$t"`
} `json:"gml$pos"`
} `json:"gml$Point"`
} `json:"georss$where"`
}
}
}