forked from sbinet/go-hdf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h5p.go
63 lines (53 loc) · 1.21 KB
/
h5p.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
package hdf5
// #include "hdf5.h"
// #include <stdlib.h>
// #include <string.h>
// inline static
// hid_t _go_hdf5_H5P_DEFAULT() { return H5P_DEFAULT; }
import "C"
import (
"fmt"
"runtime"
)
type PropType C.hid_t
type PropList struct {
Identifier
}
var (
P_DEFAULT *PropList = newPropList(C._go_hdf5_H5P_DEFAULT())
)
func newPropList(id C.hid_t) *PropList {
p := &PropList{Identifier{id}}
runtime.SetFinalizer(p, (*PropList).finalizer)
return p
}
func (p *PropList) finalizer() {
if err := p.Close(); err != nil {
panic(fmt.Errorf("error closing PropList: %s", err))
}
}
// NewPropList creates a new PropList as an instance of a property list class.
func NewPropList(cls_id PropType) (*PropList, error) {
hid := C.H5Pcreate(C.hid_t(cls_id))
if err := checkID(hid); err != nil {
return nil, err
}
return newPropList(hid), nil
}
// Close terminates access to a PropList.
func (p *PropList) Close() error {
if p.id == 0 {
return nil
}
err := h5err(C.H5Pclose(p.id))
p.id = 0
return err
}
// Copy copies an existing PropList to create a new PropList.
func (p *PropList) Copy() (*PropList, error) {
hid := C.H5Pcopy(p.id)
if err := checkID(hid); err != nil {
return nil, err
}
return newPropList(hid), nil
}