-
Notifications
You must be signed in to change notification settings - Fork 35
/
wrapper.go
149 lines (124 loc) · 4.47 KB
/
wrapper.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
// Copyright 2017 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rootio
import (
"reflect"
)
// wobject wrapps a type created from a Streamer and implements the
// following interfaces:
// - rootio.Object
// - rootio.ROOTMarshaler
// - rootio.ROOTUnmarshaler
type wobject struct {
v interface{}
class func(recv interface{}) string
unmarshal func(recv interface{}, r *RBuffer) error
marshal func(recv interface{}, w *WBuffer) (int, error)
}
func (obj *wobject) Class() string {
return obj.class(obj.v)
}
func (obj *wobject) UnmarshalROOT(r *RBuffer) error {
return obj.unmarshal(obj.v, r)
}
func (obj *wobject) MarshalROOT(w *WBuffer) (int, error) {
return obj.marshal(obj.v, w)
}
var (
_ Object = (*wobject)(nil)
_ ROOTMarshaler = (*wobject)(nil)
_ ROOTUnmarshaler = (*wobject)(nil)
)
var builtins = map[string]reflect.Type{
"TObject": reflect.TypeOf((*tobject)(nil)).Elem(),
"TString": reflect.TypeOf(""),
"TNamed": reflect.TypeOf((*tnamed)(nil)).Elem(),
"TList": reflect.TypeOf((*tlist)(nil)).Elem(),
"TObjArray": reflect.TypeOf((*tobjarray)(nil)).Elem(),
"TObjString": reflect.TypeOf((*tobjstring)(nil)).Elem(),
"TTree": reflect.TypeOf((*ttree)(nil)).Elem(),
"TBranch": reflect.TypeOf((*tbranch)(nil)).Elem(),
"TBranchElement": reflect.TypeOf((*tbranchElement)(nil)).Elem(),
}
var cxxbuiltins = map[string]reflect.Type{
"bool": reflect.TypeOf(false),
/*
"uint": reflect.TypeOf(uint(0)),
"uint8": reflect.TypeOf(uint8(0)),
"uint16": reflect.TypeOf(uint16(0)),
"uint32": reflect.TypeOf(uint32(0)),
"uint64": reflect.TypeOf(uint64(0)),
"int": reflect.TypeOf(int(0)),
"int8": reflect.TypeOf(int8(0)),
"int16": reflect.TypeOf(int16(0)),
"int32": reflect.TypeOf(int32(0)),
"int64": reflect.TypeOf(int64(0)),
"float32": reflect.TypeOf(float32(0)),
"float64": reflect.TypeOf(float64(0)),
*/
// C/C++ builtins
"unsigned": reflect.TypeOf(uint(0)),
"unsigned char": reflect.TypeOf(uint8(0)),
"unsigned short": reflect.TypeOf(uint16(0)),
"unsigned int": reflect.TypeOf(uint32(0)),
"unsigned long": reflect.TypeOf(uint64(0)),
//"int": reflect.TypeOf(int(0)),
"char": reflect.TypeOf(int8(0)),
"short": reflect.TypeOf(int16(0)),
"int": reflect.TypeOf(int32(0)),
"long": reflect.TypeOf(int64(0)),
"float": reflect.TypeOf(float32(0)),
"double": reflect.TypeOf(float64(0)),
"string": reflect.TypeOf(""),
// ROOT builtins
"Bool_t": reflect.TypeOf(true),
"Byte_t": reflect.TypeOf(uint8(0)),
"Char_t": reflect.TypeOf(int8(0)),
"UChar_t": reflect.TypeOf(uint8(0)),
"Short_t": reflect.TypeOf(int16(0)),
"UShort_t": reflect.TypeOf(uint16(0)),
"Int_t": reflect.TypeOf(int32(0)),
"UInt_t": reflect.TypeOf(uint32(0)),
"Seek_t": reflect.TypeOf(int64(0)), // FIXME(sbinet): not portable
"Long_t": reflect.TypeOf(int64(0)), // FIXME(sbinet): not portable
"ULong_t": reflect.TypeOf(uint64(0)), // FIXME(sbinet): not portable
"Long64_t": reflect.TypeOf(int64(0)),
"ULong64_t": reflect.TypeOf(uint64(0)),
"Float_t": reflect.TypeOf(float32(0)),
"Float16_t": reflect.TypeOf(Float16(0)),
"Double_t": reflect.TypeOf(float64(0)),
"Double32_t": reflect.TypeOf(Double32(0)),
"Version_t": reflect.TypeOf(int16(0)),
"Option_t": reflect.TypeOf(""),
"Ssiz_t": reflect.TypeOf(int(0)),
"Real_t": reflect.TypeOf(float32(0)),
"Axis_t": reflect.TypeOf(float64(0)),
"Stat_t": reflect.TypeOf(float64(0)),
"Font_t": reflect.TypeOf(int16(0)),
"Style_t": reflect.TypeOf(int16(0)),
"Marker_t": reflect.TypeOf(int16(0)),
"Width_t": reflect.TypeOf(int16(0)),
"Color_t": reflect.TypeOf(int16(0)),
"SCoord_t": reflect.TypeOf(int16(0)),
"Coord_t": reflect.TypeOf(float64(0)),
"Angle_t": reflect.TypeOf(float32(0)),
"Size_t": reflect.TypeOf(float32(0)),
}
var gotype2ROOTEnum = map[reflect.Type]int32{
reflect.TypeOf(int8(0)): kChar,
reflect.TypeOf(int16(0)): kShort,
reflect.TypeOf(int32(0)): kInt,
reflect.TypeOf(int64(0)): kLong,
// reflect.TypeOf(int64(0)): kLong64,
reflect.TypeOf(float32(0)): kFloat,
reflect.TypeOf(float64(0)): kDouble,
reflect.TypeOf(uint8(0)): kUChar,
// reflect.TypeOf(uint8(0)): kCharStar,
reflect.TypeOf(uint16(0)): kUShort,
reflect.TypeOf(uint32(0)): kUInt,
reflect.TypeOf(uint64(0)): kULong,
// reflect.TypeOf(uint64(0)): kULong64,
reflect.TypeOf(false): kBool,
reflect.TypeOf(Double32(0)): kDouble32,
}