forked from davyxu/tabtoy
/
filedesc.go
58 lines (42 loc) · 1.14 KB
/
filedesc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package model
type FileDescriptor struct {
Name string
DescriptorByName map[string]*Descriptor
Descriptors []*Descriptor
Pragma *MetaInfo
}
func (self *FileDescriptor) MatchTag(tag string) bool {
if !self.Pragma.ContainKey("OutputTag") {
return true
}
return self.Pragma.ContainValue("OutputTag", tag)
}
// 取行类型的结构
func (self *FileDescriptor) RowDescriptor() *Descriptor {
for _, d := range self.Descriptors {
if d.Usage == DescriptorUsage_RowType {
return d
}
}
return nil
}
func (self *FileDescriptor) Add(def *Descriptor) bool {
if _, ok := self.DescriptorByName[def.Name]; ok {
return false
//panic("duplicate buildin type")
}
// Descriptor会在每个表对应的FileDescriptor中和CombineFileDescriptor中同时存在
// 这里忽略CombineFileDescriptor, 保持原有文件类型
if def.File == nil {
def.File = self
}
self.Descriptors = append(self.Descriptors, def)
self.DescriptorByName[def.Name] = def
return true
}
func NewFileDescriptor() *FileDescriptor {
return &FileDescriptor{
DescriptorByName: make(map[string]*Descriptor),
Pragma: NewMetaInfo(),
}
}