forked from project-chip/alchemy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypedef.go
46 lines (38 loc) · 954 Bytes
/
typedef.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
package matter
import (
"github.com/project-chip/alchemy/asciidoc"
"github.com/project-chip/alchemy/matter/types"
)
type TypeDef struct {
entity
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Type *types.DataType `json:"type,omitempty"`
}
func NewTypeDef(source asciidoc.Element) *TypeDef {
return &TypeDef{
entity: entity{source: source},
}
}
func (*TypeDef) EntityType() types.EntityType {
return types.EntityTypeDef
}
func (s *TypeDef) Clone() *TypeDef {
ns := &TypeDef{Name: s.Name, Description: s.Description, Type: s.Type}
return ns
}
func (s *TypeDef) Inherit(parent *TypeDef) {
if len(s.Description) == 0 {
s.Description = parent.Description
}
s.Type = s.Type
}
type TypeDefSet []*TypeDef
func (ss TypeDefSet) Identifier(name string) (types.Entity, bool) {
for _, e := range ss {
if e.Name == name {
return e, true
}
}
return nil, false
}