-
Notifications
You must be signed in to change notification settings - Fork 16
/
h5i.go
69 lines (59 loc) · 1.43 KB
/
h5i.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
package hdf5
// #include "hdf5.h"
// #include "hdf5_hl.h"
// #include <stdlib.h>
// #include <string.h>
import "C"
import (
"unsafe"
)
type IType C.H5I_type_t
const (
FILE IType = C.H5I_FILE
GROUP IType = C.H5I_GROUP
DATATYPE IType = C.H5I_DATATYPE
DATASPACE IType = C.H5I_DATASPACE
DATASET IType = C.H5I_DATASET
ATTRIBUTE IType = C.H5I_ATTR
BAD_ID IType = C.H5I_BADID
)
// Identifier is a simple wrapper around a C hid_t. It has basic methods
// which apply to every type in the go-hdf5 API.
type Identifier struct {
id C.hid_t
}
// A Location embeds Identifier. Dataset, Datatype and Group are all Locations.
type Location struct {
Identifier
}
// Id returns the int value of an identifier.
func (i Identifier) Id() int {
return int(i.id)
}
// Name returns the full name of the Identifier
func (i Identifier) Name() string {
sz := int(C.H5Iget_name(i.id, nil, 0)) + 1
if sz < 0 {
return ""
}
buf := string(make([]byte, sz))
c_buf := C.CString(buf)
defer C.free(unsafe.Pointer(c_buf))
sz = int(C.H5Iget_name(i.id, c_buf, C.size_t(sz)))
if sz < 0 {
return ""
}
return C.GoString(c_buf)
}
// File returns the file associated with this Identifier.
func (i Identifier) File() *File {
fid := C.H5Iget_file_id(i.id)
if fid < 0 {
return nil
}
return &File{CommonFG{Location{Identifier{fid}}}}
}
// Type returns the type of the identifier.
func (i Identifier) Type() IType {
return IType(C.H5Iget_type(i.id))
}