-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.go
260 lines (215 loc) · 6.07 KB
/
class.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
package croot
// #include "croot/croot.h"
//
// #include <stdlib.h>
// #include <string.h>
//
import "C"
import (
"unsafe"
)
type Version int16
type Class interface {
Object
GetBaseClass(class string) Class
GetClassSize() int
GetClassVersion() Version
GetDataMember(name string) DataMember
}
// DataMember provides information about name of data member, its type, and
// comment field string.
type DataMember interface {
Object
GetArrayDim() int
GetClass() Class
GetDataType() DataType
GetFullTypeName() string
GetOffset() int
GetTypeName() string
IsaPointer() bool
IsBasic() bool
IsEnum() bool
IsPersistent() bool
IsSTLContainer() STLType
}
// STLType describes STL collections and some std classes.
type STLType int
// STLType values defined in ESTLType.h
const (
STLT_NotSTL STLType = 0
STLT_STLvector = 1
STLT_STLlist = 2
STLT_STLdeque = 3
STLT_STLmap = 4
STLT_STLmultimap = 5
STLT_STLset = 6
STLT_STLmultiset = 7
STLT_STLbitset = 8
STLT_STLforwardlist = 9
STLT_STLunorderedset = 10
STLT_STLunorderedmultiset = 11
STLT_STLunorderedmap = 12
STLT_STLunorderedmultimap = 13
STLT_STLend = 14
STLT_STLany = 300 /* TVirtualStreamerInfo::kSTL */
STLT_STLstring = 365 /* TVirtualStreamerInfo::kSTLstring */
)
// DataType provides basic data type description.
type DataType interface {
Object
GetFullTypeName() string
GetType() DataTypeKind
GetTypeName() string
Size() int
Property() int64
}
// DataTypeKind describes basic data types
type DataTypeKind int
// DataTypeKind defined in TDataType.h -- EDataType
const (
DTK_Char DataTypeKind = 1
DTK_UChar = 11
DTK_Short = 2
DTK_UShort = 12
DTK_Int = 3
DTK_UInt = 13
DTK_Long = 4
DTK_ULong = 14
DTK_Float = 5
DTK_Double = 8
DTK_Double32 = 9
DTK_char = 10
DTK_Bool = 18
DTK_Long64 = 16
DTK_ULong64 = 17
DTK_Other = -1
DTK_NoType = 0
DTK_Float16 = 19
DTK_Counter = 6
DTK_CharStar = 7
DTK_Bits = 15 /* for compatibility with TStreamerInfo */
DTK_Void = 20
DTK_DataTypeAliasUnsigned = 21
DTK_DataTypeAliasSignedChar = 22
// could add "long int" etc
DTK_NumDataTypes DataTypeKind = 23
)
type classImpl struct {
c C.CRoot_Class
}
func GetClass(name string) Class {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
c := C.CRoot_Class_GetClass(cname)
if c == nil {
return nil
}
return &classImpl{c: c}
}
func (c *classImpl) GetBaseClass(name string) Class {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
base := C.CRoot_Class_GetBaseClass(c.c, cname)
if base == nil {
return nil
}
return &classImpl{c: base}
}
func (c *classImpl) GetClassSize() int {
return int(C.CRoot_Class_GetClassSize(c.c))
}
func (c *classImpl) GetClassVersion() Version {
return Version(C.CRoot_Class_GetClassVersion(c.c))
}
func (c *classImpl) GetDataMember(name string) DataMember {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
mbr := C.CRoot_Class_GetDataMember(c.c, cname)
if mbr == nil {
return nil
}
return &dataMemberImpl{c: mbr}
}
type dataMemberImpl struct {
c C.CRoot_DataMember
}
func (dm *dataMemberImpl) GetArrayDim() int {
return int(C.CRoot_DataMember_GetArrayDim(dm.c))
}
func (dm *dataMemberImpl) GetClass() Class {
cls := C.CRoot_DataMember_GetClass(dm.c)
if cls == nil {
return nil
}
return &classImpl{c: cls}
}
func (dm *dataMemberImpl) GetDataType() DataType {
dt := C.CRoot_DataMember_GetDataType(dm.c)
if dt == nil {
return nil
}
return &dataTypeImpl{c: dt}
}
func (dm *dataMemberImpl) GetFullTypeName() string {
cname := C.CRoot_DataMember_GetFullTypeName(dm.c)
// we dont own cname
// defer C.free(unsafe.Pointer(cname))
return C.GoString(cname)
}
func (dm *dataMemberImpl) GetOffset() int {
o := C.CRoot_DataMember_GetOffset(dm.c)
return int(o)
}
func (dm *dataMemberImpl) GetTypeName() string {
cname := C.CRoot_DataMember_GetTypeName(dm.c)
// we dont own cname
// defer C.free(unsafe.Pointer(cname))
return C.GoString(cname)
}
func (dm *dataMemberImpl) IsaPointer() bool {
o := C.CRoot_DataMember_IsaPointer(dm.c)
return c2bool(o)
}
func (dm *dataMemberImpl) IsBasic() bool {
o := C.CRoot_DataMember_IsBasic(dm.c)
return c2bool(o)
}
func (dm *dataMemberImpl) IsEnum() bool {
o := C.CRoot_DataMember_IsEnum(dm.c)
return c2bool(o)
}
func (dm *dataMemberImpl) IsPersistent() bool {
o := C.CRoot_DataMember_IsPersistent(dm.c)
return c2bool(o)
}
func (dm *dataMemberImpl) IsSTLContainer() STLType {
o := C.CRoot_DataMember_IsSTLContainer(dm.c)
return STLType(o)
}
type dataTypeImpl struct {
c C.CRoot_DataType
}
func (dt *dataTypeImpl) GetFullTypeName() string {
cname := C.CRoot_DataType_GetFullTypeName(dt.c)
// we dont own cname
// defer C.free(unsafe.Pointer(cname))
return C.GoString(cname)
}
func (dt *dataTypeImpl) GetType() DataTypeKind {
kind := C.CRoot_DataType_GetType(dt.c)
return DataTypeKind(kind)
}
func (dt *dataTypeImpl) GetTypeName() string {
cname := C.CRoot_DataType_GetTypeName(dt.c)
// we dont own cname
// defer C.free(unsafe.Pointer(cname))
return C.GoString(cname)
}
func (dt *dataTypeImpl) Size() int {
o := C.CRoot_DataType_Size(dt.c)
return int(o)
}
func (dt *dataTypeImpl) Property() int64 {
o := C.CRoot_DataType_Property(dt.c)
return int64(o)
}