-
Notifications
You must be signed in to change notification settings - Fork 8
/
reflection.go
82 lines (67 loc) · 1.95 KB
/
reflection.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
package tiledb
import (
"reflect"
)
// genericType returns the reflect.Type for T
func genericType[T any]() reflect.Type {
return reflect.TypeOf((*T)(nil)).Elem()
}
// datatypeOfDimensionFromIndex returns for a dimension the Datatype and whether it is of variable size
func datatypeOfDimensionFromIndex(arr *Array, dimIdx uint32) (Datatype, bool, error) {
schema, err := arr.Schema()
if err != nil {
return Datatype(0), false, err
}
defer schema.Free()
domain, err := schema.Domain()
if err != nil {
return Datatype(0), false, err
}
defer domain.Free()
dimension, err := domain.DimensionFromIndex(uint(dimIdx))
if err != nil {
return Datatype(0), false, err
}
defer dimension.Free()
datatype, err := dimension.Type()
if err != nil {
return Datatype(0), false, err
}
cellValNum, err := dimension.CellValNum()
if err != nil {
return Datatype(0), false, err
}
return datatype, cellValNum == TILEDB_VAR_NUM, nil
}
// datatypeOfDimensionFromName returns for a dimension the Datatype and whether it is of variable size
func datatypeOfDimensionFromName(arr *Array, dimName string) (Datatype, bool, error) {
schema, err := arr.Schema()
if err != nil {
return Datatype(0), false, err
}
domain, err := schema.Domain()
if err != nil {
return Datatype(0), false, err
}
dimension, err := domain.DimensionFromName(dimName)
if err != nil {
return Datatype(0), false, err
}
datatype, err := dimension.Type()
if err != nil {
return Datatype(0), false, err
}
cellValNum, err := dimension.CellValNum()
if err != nil {
return Datatype(0), false, err
}
return datatype, cellValNum == TILEDB_VAR_NUM, nil
}
// addressableValue copies the value of `val` into an addressable location.
// This is used to return a Value that can always give as an UnsafePointer reflectively.
func addressableValue(val any) reflect.Value {
valVal := reflect.ValueOf(val)
pointable := reflect.New(valVal.Type())
pointable.Elem().Set(valVal)
return pointable
}