1
1
use ffi:: h5d:: H5Dopen2 ;
2
2
use ffi:: h5g:: { H5G_info_t , H5Gget_info , H5Gcreate2 , H5Gopen2 } ;
3
- use ffi:: h5i:: hid_t;
4
3
use ffi:: h5l:: { H5Lmove , H5Lcreate_soft , H5Lcreate_hard , H5Ldelete , H5L_SAME_LOC } ;
5
4
use ffi:: h5p:: { H5Pcreate , H5Pset_create_intermediate_group , H5P_DEFAULT } ;
6
5
use globals:: H5P_LINK_CREATE ;
@@ -9,18 +8,13 @@ use dataset::{Dataset, DatasetBuilder};
9
8
use datatype:: ToDatatype ;
10
9
use error:: Result ;
11
10
use group:: Group ;
12
- use handle :: { ID , FromID } ;
13
- use location :: Location ;
11
+ use location :: LocationType ;
12
+ use object :: { Object , ObjectID } ;
14
13
use plist:: PropertyList ;
15
14
use util:: to_cstring;
16
15
17
16
use std:: default:: Default ;
18
17
19
- fn group_info ( id : hid_t ) -> Result < H5G_info_t > {
20
- let info: * mut H5G_info_t = & mut H5G_info_t :: default ( ) ;
21
- h5call ! ( H5Gget_info ( id, info) ) . and ( Ok ( unsafe { * info } ) )
22
- }
23
-
24
18
fn make_lcpl ( ) -> Result < PropertyList > {
25
19
h5lock ! ( {
26
20
let lcpl = PropertyList :: from_id( h5try!( H5Pcreate ( * H5P_LINK_CREATE ) ) ) ?;
@@ -29,19 +23,26 @@ fn make_lcpl() -> Result<PropertyList> {
29
23
}
30
24
31
25
/// A trait for HDF5 objects that can contain other objects (file, group).
32
- pub trait Container : Location {
26
+ pub trait ContainerType : LocationType { }
27
+
28
+ impl < T : ContainerType > Object < T > {
29
+ fn group_info ( & self ) -> Result < H5G_info_t > {
30
+ let info: * mut H5G_info_t = & mut H5G_info_t :: default ( ) ;
31
+ h5call ! ( H5Gget_info ( self . id( ) , info) ) . and ( Ok ( unsafe { * info } ) )
32
+ }
33
+
33
34
/// Returns the number of objects in the container (or 0 if the container is invalid).
34
- fn len ( & self ) -> u64 {
35
- group_info ( self . id ( ) ) . map ( |info| info. nlinks ) . unwrap_or ( 0 )
35
+ pub fn len ( & self ) -> u64 {
36
+ self . group_info ( ) . map ( |info| info. nlinks ) . unwrap_or ( 0 )
36
37
}
37
38
38
39
/// Returns true if the container has no linked objects (or if the container is invalid).
39
- fn is_empty ( & self ) -> bool {
40
+ pub fn is_empty ( & self ) -> bool {
40
41
self . len ( ) == 0
41
42
}
42
43
43
44
/// Create a new group in a file or group.
44
- fn create_group ( & self , name : & str ) -> Result < Group > {
45
+ pub fn create_group ( & self , name : & str ) -> Result < Group > {
45
46
h5lock ! ( {
46
47
let lcpl = make_lcpl( ) ?;
47
48
let name = to_cstring( name) ?;
@@ -52,14 +53,14 @@ pub trait Container: Location {
52
53
}
53
54
54
55
/// Opens an existing group in a file or group.
55
- fn group ( & self , name : & str ) -> Result < Group > {
56
+ pub fn group ( & self , name : & str ) -> Result < Group > {
56
57
let name = to_cstring ( name) ?;
57
58
Group :: from_id ( h5try ! ( H5Gopen2 (
58
59
self . id( ) , name. as_ptr( ) , H5P_DEFAULT ) ) )
59
60
}
60
61
61
62
/// Creates a soft link. Note: `src` and `dst` are relative to the current object.
62
- fn link_soft ( & self , src : & str , dst : & str ) -> Result < ( ) > {
63
+ pub fn link_soft ( & self , src : & str , dst : & str ) -> Result < ( ) > {
63
64
h5lock ! ( {
64
65
let lcpl = make_lcpl( ) ?;
65
66
let src = to_cstring( src) ?;
@@ -71,7 +72,7 @@ pub trait Container: Location {
71
72
}
72
73
73
74
/// Creates a hard link. Note: `src` and `dst` are relative to the current object.
74
- fn link_hard ( & self , src : & str , dst : & str ) -> Result < ( ) > {
75
+ pub fn link_hard ( & self , src : & str , dst : & str ) -> Result < ( ) > {
75
76
let src = to_cstring ( src) ?;
76
77
let dst = to_cstring ( dst) ?;
77
78
h5call ! ( H5Lcreate_hard (
@@ -80,7 +81,7 @@ pub trait Container: Location {
80
81
}
81
82
82
83
/// Relinks an object. Note: `name` and `path` are relative to the current object.
83
- fn relink ( & self , name : & str , path : & str ) -> Result < ( ) > {
84
+ pub fn relink ( & self , name : & str , path : & str ) -> Result < ( ) > {
84
85
let name = to_cstring ( name) ?;
85
86
let path = to_cstring ( path) ?;
86
87
h5call ! ( H5Lmove (
@@ -89,20 +90,20 @@ pub trait Container: Location {
89
90
}
90
91
91
92
/// Removes a link to an object from this file or group.
92
- fn unlink ( & self , name : & str ) -> Result < ( ) > {
93
+ pub fn unlink ( & self , name : & str ) -> Result < ( ) > {
93
94
let name = to_cstring ( name) ?;
94
95
h5call ! ( H5Ldelete (
95
96
self . id( ) , name. as_ptr( ) , H5P_DEFAULT
96
97
) ) . and ( Ok ( ( ) ) )
97
98
}
98
99
99
100
/// Instantiates a new dataset builder.
100
- fn new_dataset < T : ToDatatype > ( & self ) -> DatasetBuilder < T > {
101
- DatasetBuilder :: < T > :: new :: < Self > ( self )
101
+ pub fn new_dataset < D : ToDatatype > ( & self ) -> DatasetBuilder < D > {
102
+ DatasetBuilder :: < D > :: new ( & self )
102
103
}
103
104
104
105
/// Opens an existing dataset in the file or group.
105
- fn dataset ( & self , name : & str ) -> Result < Dataset > {
106
+ pub fn dataset ( & self , name : & str ) -> Result < Dataset > {
106
107
let name = to_cstring ( name) ?;
107
108
Dataset :: from_id ( h5try ! ( H5Dopen2 (
108
109
self . id( ) , name. as_ptr( ) , H5P_DEFAULT ) ) )
@@ -112,10 +113,8 @@ pub trait Container: Location {
112
113
#[ cfg( test) ]
113
114
mod tests {
114
115
use error:: silence_errors;
115
- use handle :: ID ;
116
+ use object :: ObjectID ;
116
117
use test:: with_tmp_file;
117
- use super :: Container ;
118
- use location:: Location ;
119
118
120
119
#[ test]
121
120
pub fn test_group ( ) {
0 commit comments