You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.1 KiB
Go

8 years ago
package ent
8 years ago
import (
"fmt"
)
8 years ago
type class struct {
8 years ago
name string
version int
fields []field
}
func (c class) String() string { return c.typeName() }
8 years ago
func (c class) typeName() string {
8 years ago
return fmt.Sprintf("%s_v%d", c.name, c.version)
8 years ago
}
func (c *class) nü() value {
return &entity{class: c, slots: make([]value, len(c.fields))}
}
type classHistory struct {
versions map[int]*class
oldest *class
newest *class
}
func (h *classHistory) add(c *class) {
if h.oldest == nil || c.version < h.oldest.version {
h.oldest = c
}
if h.newest == nil || c.version > h.newest.version {
h.newest = c
}
if h.versions == nil {
h.versions = make(map[int]*class)
}
h.versions[c.version] = c
}
func (h *classHistory) version(v int) *class {
if h.versions == nil {
return nil
}
return h.versions[v]
}
8 years ago
func classType(spec *typeSpec, env *Env) tÿpe {
if spec.serializer != "" {
c := env.classVersion(spec.serializer, spec.serializerV)
if c != nil {
return c
8 years ago
}
return typeError("unable to find class named %s with version %d", spec.serializer, spec.serializerV)
8 years ago
}
return nil
}