@@ -3,6 +3,7 @@ use std::default::Default;
33use libhdf5_sys:: {
44 h5d:: H5Dopen2 ,
55 h5g:: { H5G_info_t , H5Gcreate2 , H5Gget_info , H5Gopen2 } ,
6+ h5i:: { H5I_FILE , H5I_GROUP } ,
67 h5l:: { H5Lcreate_hard , H5Lcreate_soft , H5Ldelete , H5Lmove , H5L_SAME_LOC } ,
78 h5p:: { H5Pcreate , H5Pset_create_intermediate_group } ,
89} ;
@@ -22,20 +23,24 @@ fn make_lcpl() -> Result<PropertyList> {
2223 } )
2324}
2425
26+ define_object_type ! ( Container : Location , "container" , |id_type| id_type == H5I_FILE
27+ || id_type == H5I_GROUP ) ;
28+
2529/// A trait for HDF5 objects that can contain other objects (file, group).
26- pub trait Container : Location {
30+ impl Container {
2731 /// Returns the number of objects in the container (or 0 if the container is invalid).
28- fn len ( & self ) -> u64 {
32+ pub fn len ( & self ) -> u64 {
2933 group_info ( self . id ( ) ) . map ( |info| info. nlinks ) . unwrap_or ( 0 )
3034 }
3135
3236 /// Returns true if the container has no linked objects (or if the container is invalid).
33- fn is_empty ( & self ) -> bool {
37+ pub fn is_empty ( & self ) -> bool {
3438 self . len ( ) == 0
3539 }
3640
3741 /// Create a new group in a file or group.
38- fn create_group ( & self , name : & str ) -> Result < Group > {
42+ pub fn create_group ( & self , name : & str ) -> Result < Group > {
43+ // TODO: &mut self?
3944 h5lock ! ( {
4045 let lcpl = make_lcpl( ) ?;
4146 let name = to_cstring( name) ?;
@@ -50,13 +55,14 @@ pub trait Container: Location {
5055 }
5156
5257 /// Opens an existing group in a file or group.
53- fn group ( & self , name : & str ) -> Result < Group > {
58+ pub fn group ( & self , name : & str ) -> Result < Group > {
5459 let name = to_cstring ( name) ?;
5560 Group :: from_id ( h5try ! ( H5Gopen2 ( self . id( ) , name. as_ptr( ) , H5P_DEFAULT ) ) )
5661 }
5762
5863 /// Creates a soft link. Note: `src` and `dst` are relative to the current object.
59- fn link_soft ( & self , src : & str , dst : & str ) -> Result < ( ) > {
64+ pub fn link_soft ( & self , src : & str , dst : & str ) -> Result < ( ) > {
65+ // TODO: &mut self?
6066 h5lock ! ( {
6167 let lcpl = make_lcpl( ) ?;
6268 let src = to_cstring( src) ?;
@@ -67,7 +73,8 @@ pub trait Container: Location {
6773 }
6874
6975 /// Creates a hard link. Note: `src` and `dst` are relative to the current object.
70- fn link_hard ( & self , src : & str , dst : & str ) -> Result < ( ) > {
76+ pub fn link_hard ( & self , src : & str , dst : & str ) -> Result < ( ) > {
77+ // TODO: &mut self?
7178 let src = to_cstring ( src) ?;
7279 let dst = to_cstring ( dst) ?;
7380 h5call ! ( H5Lcreate_hard (
@@ -82,7 +89,8 @@ pub trait Container: Location {
8289 }
8390
8491 /// Relinks an object. Note: `name` and `path` are relative to the current object.
85- fn relink ( & self , name : & str , path : & str ) -> Result < ( ) > {
92+ pub fn relink ( & self , name : & str , path : & str ) -> Result < ( ) > {
93+ // TODO: &mut self?
8694 let name = to_cstring ( name) ?;
8795 let path = to_cstring ( path) ?;
8896 h5call ! ( H5Lmove (
@@ -97,18 +105,19 @@ pub trait Container: Location {
97105 }
98106
99107 /// Removes a link to an object from this file or group.
100- fn unlink ( & self , name : & str ) -> Result < ( ) > {
108+ pub fn unlink ( & self , name : & str ) -> Result < ( ) > {
109+ // TODO: &mut self?
101110 let name = to_cstring ( name) ?;
102111 h5call ! ( H5Ldelete ( self . id( ) , name. as_ptr( ) , H5P_DEFAULT ) ) . and ( Ok ( ( ) ) )
103112 }
104113
105114 /// Instantiates a new dataset builder.
106- fn new_dataset < T : H5Type > ( & self ) -> DatasetBuilder < T > {
107- DatasetBuilder :: < T > :: new :: < Self > ( self )
115+ pub fn new_dataset < T : H5Type > ( & self ) -> DatasetBuilder < T > {
116+ DatasetBuilder :: < T > :: new ( self )
108117 }
109118
110119 /// Opens an existing dataset in the file or group.
111- fn dataset ( & self , name : & str ) -> Result < Dataset > {
120+ pub fn dataset ( & self , name : & str ) -> Result < Dataset > {
112121 let name = to_cstring ( name) ?;
113122 Dataset :: from_id ( h5try ! ( H5Dopen2 ( self . id( ) , name. as_ptr( ) , H5P_DEFAULT ) ) )
114123 }
0 commit comments