forked from freeconf/yang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta.go
262 lines (207 loc) · 4.9 KB
/
meta.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package meta
// /////////////////
// Interfaces
// ////////////////
// Definition represent nearly everythihng in YANG, more specifically, anything
// that can have an extention, which is nearly everything
type Meta interface {
HasExtensions
// Parent in the YANG schema tree
Parent() Meta
}
// HasExtensions is support by almost every structure. See YANG
// language extensions for more information
type HasExtensions interface {
// User customized YANG found in the body
Extensions() []*Extension
}
type hasAddExtension interface {
HasExtensions
addExtension(x *Extension)
}
type cloneable interface {
clone(parent Meta) interface{}
}
// Identifiable are things that have a unique identifier allowing it to be found
// in a list.
type Identifiable interface {
// Ident is short for identifier or name of item. Example: 'leaf foo {...' then 'foo' is ident
Ident() string
}
// Describable is anything that can have a description, oddly, most data definitions except
// 'case', 'input' or 'output'
type Describable interface {
// Description of meta item
Description() string
// Reference is a human-readable, cross-reference to some external source. Example: Item #89 of foo catalog"
Reference() string
setDescription(desc string)
setReference(ref string)
}
// Definition data structure defining details. This includes data definitions like
// container and leaf, but also notifications and actions
type Definition interface {
Meta
Identifiable
setParent(p Meta)
getOriginalParent() Definition
}
type HasPresence interface {
Meta
Presence() string
setPresence(string)
}
type HasUnique interface {
Meta
Unique() [][]string
setUnique([][]string)
}
type HasStatus interface {
Meta
// Status is useful to mark things deprecated
Status() Status
setStatus(s Status)
}
type HasDefinitions interface {
Definition
// Definition returns DataDefinition, Action or Notification by name
Definition(ident string) Definition
}
// HasDefinitions holds container, leaf, list, etc definitions which
// often (but not always) also hold notifications and actions
type HasDataDefinitions interface {
HasDefinitions
DataDefinitions() []Definition
addDataDefinition(Definition) error
// addDataDefinition will change parent, this won't and useful when moving around
// potentially recursive defintions where parent's children aren't always the child's
// parent.
addDataDefinitionWithoutOwning(Definition) error
popDataDefinitions() []Definition
}
type HasUnits interface {
Units() string
setUnits(units string)
}
type HasNotifications interface {
HasDataDefinitions
Notifications() map[string]*Notification
addNotification(*Notification) error
setNotifications(map[string]*Notification)
}
type HasActions interface {
HasDataDefinitions
Actions() map[string]*Rpc
addAction(a *Rpc) error
setActions(map[string]*Rpc)
}
type HasGroupings interface {
HasDataDefinitions
Groupings() map[string]*Grouping
addGrouping(g *Grouping) error
}
type HasAugments interface {
Augments() []*Augment
addAugments(*Augment)
}
type HasTypedefs interface {
Typedefs() map[string]*Typedef
addTypedef(t *Typedef) error
}
type HasIfFeatures interface {
IfFeatures() []*IfFeature
addIfFeature(*IfFeature)
}
type HasWhen interface {
When() *When
setWhen(*When)
}
type HasMusts interface {
Musts() []*Must
addMust(*Must)
setMusts([]*Must)
}
type HasConfig interface {
Config() bool
IsConfigSet() bool
setConfig(bool)
}
type HasMandatory interface {
Mandatory() bool
IsMandatorySet() bool
setMandatory(bool)
}
type HasDetails interface {
Definition
HasMandatory
HasConfig
}
type HasCases interface {
Definition
addCase(*ChoiceCase) error
}
type HasOrderedBy interface {
OrderedBy() OrderedBy
setOrderedBy(order OrderedBy)
}
type HasErrorMessage interface {
ErrorMessage() string
setErrorMessage(string)
ErrorAppTag() string
setErrorAppTag(string)
}
type HasMinMax interface {
MaxElements() int
IsMaxElementsSet() bool
setMaxElements(int)
MinElements() int
IsMinElementsSet() bool
setMinElements(int)
}
type HasUnbounded interface {
Unbounded() bool
IsUnboundedSet() bool
setUnbounded(bool)
}
type HasListDetails interface {
Definition
HasMinMax
HasUnbounded
HasOrderedBy
}
type HasDefault interface {
HasDefault() bool
addDefault(string)
DefaultValue() interface{}
setDefaultValue(interface{})
clearDefault()
}
type HasDefaultValue interface {
HasDefault
Default() string
setDefault(string)
}
type HasDefaultValues interface {
HasDefault
Default() []string
setDefault(d []string)
}
type Leafable interface {
Definition
HasDefault
HasUnits
HasType
}
type HasType interface {
Type() *Type
setType(*Type)
}
// Status is indication of definition obsolense
type Status int
const (
Current Status = iota
Deprecated
Obsolete
)
// Loader abstracts yang modules are loaded from file parsers.
type Loader func(parent *Module, name string, rev string, features FeatureSet, loader Loader) (*Module, error)