forked from grafana/grafana-plugin-sdk-go
/
field_type_enum.go
168 lines (136 loc) · 3.39 KB
/
field_type_enum.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
package data
// this supports the enum type
// it is different than the rest since it is backed by
// a uint16 but maps to the EnumItemIndex type, and has special semantics and interacts with the metadata
// Unlike the other fields it can not be easily generated
type enumVector []EnumItemIndex
type EnumItemIndex uint16
func newEnumVector(n int) *enumVector {
v := enumVector(make([]EnumItemIndex, n))
return &v
}
func newEnumVectorWithValues(s []EnumItemIndex) *enumVector {
v := make([]EnumItemIndex, len(s))
copy(v, s)
return (*enumVector)(&v)
}
func (v *enumVector) Set(idx int, i interface{}) {
(*v)[idx] = i.(EnumItemIndex)
}
func (v *enumVector) SetConcrete(idx int, i interface{}) {
v.Set(idx, i)
}
func (v *enumVector) Append(i interface{}) {
*v = append(*v, i.(EnumItemIndex))
}
func (v *enumVector) At(i int) interface{} {
return (*v)[i]
}
func (v *enumVector) PointerAt(i int) interface{} {
return &(*v)[i]
}
func (v *enumVector) Len() int {
return len(*v)
}
func (v *enumVector) CopyAt(i int) interface{} {
return (*v)[i]
}
func (v *enumVector) ConcreteAt(i int) (interface{}, bool) {
return v.At(i), true
}
func (v *enumVector) Type() FieldType {
return vectorFieldType(v)
}
func (v *enumVector) Extend(i int) {
*v = append(*v, make([]EnumItemIndex, i)...)
}
func (v *enumVector) Insert(i int, val interface{}) {
switch {
case i < v.Len():
v.Extend(1)
copy((*v)[i+1:], (*v)[i:])
v.Set(i, val)
case i == v.Len():
v.Append(val)
case i > v.Len():
panic("Invalid index; vector length should be greater or equal to that index")
}
}
func (v *enumVector) Delete(i int) {
*v = append((*v)[:i], (*v)[i+1:]...)
}
type nullableEnumVector []*EnumItemIndex
func newNullableEnumVector(n int) *nullableEnumVector {
v := nullableEnumVector(make([]*EnumItemIndex, n))
return &v
}
func newNullableEnumVectorWithValues(s []*EnumItemIndex) *nullableEnumVector {
v := make([]*EnumItemIndex, len(s))
copy(v, s)
return (*nullableEnumVector)(&v)
}
func (v *nullableEnumVector) Set(idx int, i interface{}) {
if i == nil {
(*v)[idx] = nil
return
}
(*v)[idx] = i.(*EnumItemIndex)
}
func (v *nullableEnumVector) SetConcrete(idx int, i interface{}) {
val := i.(EnumItemIndex)
(*v)[idx] = &val
}
func (v *nullableEnumVector) Append(i interface{}) {
if i == nil {
*v = append(*v, nil)
return
}
*v = append(*v, i.(*EnumItemIndex))
}
func (v *nullableEnumVector) At(i int) interface{} {
return (*v)[i]
}
func (v *nullableEnumVector) CopyAt(i int) interface{} {
if (*v)[i] == nil {
var g *EnumItemIndex
return g
}
g := *(*v)[i]
return &g
}
func (v *nullableEnumVector) ConcreteAt(i int) (interface{}, bool) {
var g EnumItemIndex
val := (*v)[i]
if val == nil {
return g, false
}
g = *val
return g, true
}
func (v *nullableEnumVector) PointerAt(i int) interface{} {
return &(*v)[i]
}
func (v *nullableEnumVector) Len() int {
return len(*v)
}
func (v *nullableEnumVector) Type() FieldType {
return vectorFieldType(v)
}
func (v *nullableEnumVector) Extend(i int) {
*v = append(*v, make([]*EnumItemIndex, i)...)
}
func (v *nullableEnumVector) Insert(i int, val interface{}) {
switch {
case i < v.Len():
v.Extend(1)
copy((*v)[i+1:], (*v)[i:])
v.Set(i, val)
case i == v.Len():
v.Append(val)
case i > v.Len():
panic("Invalid index; vector length should be greater or equal to that index")
}
}
func (v *nullableEnumVector) Delete(i int) {
*v = append((*v)[:i], (*v)[i+1:]...)
}