hdf5_dataset::hdf5_dataset ( hdf5_file &file, std::string const& path, hdf5_datatype const& datatype, hdf5_dataspace const& dataspace ) : path_(path) { // Check if name exists in this file. htri_t status = H5Lexists(file.get_id(), path.c_str(), H5P_DEFAULT); if(status > 0) { // Full path exists. // Attempt to open it as a dataset set_id(H5Dopen2(file.get_id(), path.c_str(), H5P_DEFAULT)); if(get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataset_access_error, path.c_str() ) ); } } else if(status == 0){ // Final link in path does not exist. // Create the dataset. set_id(H5Dcreate2( file.get_id(), path.c_str(), datatype.get_id(), dataspace.get_id(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) ); if(get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataset_create_error, path.c_str() ) ); } } else { // intermediate link does not exist, or other error boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_bad_path_error, path.c_str() ) ); } }
void hdf5_datatype::reclaim_buffer(hdf5_dataspace const& dataspace, void* buffer) { herr_t status = H5Dvlen_reclaim( get_id(), dataspace.get_id(), H5P_DEFAULT, buffer ); if(status < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_access_error ) ); } }