hdf5_dataset::hdf5_dataset( hdf5_file const& file, std::string const& path ) : 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 { // path does not exist, or other error boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_bad_path_error, path.c_str() ) ); } }
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() ) ); } }
hdf5_dataspace::hdf5_dataspace(hdf5_dataset const& dataset) : hdf5_object(H5Dget_space(dataset.get_id())) { if(dataset.get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataset_access_error ) ); } if(get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataspace_access_error ) ); } }
void hdf5_datatype::resize(std::size_t new_size) { if(H5Tset_size(get_id(), new_size) < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_set_size_error ) ); } }
hdf5_dataspace::hdf5_dataspace(hdf5_annotation const& annotation) : hdf5_object(H5Aget_space(annotation.get_id())) { if(annotation.get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_annotation_access_error ) ); } if(get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataspace_access_error ) ); } }
void hdf5_dataspace::close_impl() { if(H5Sclose(get_id()) < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataspace_close_error ) ); } }
hdf5_datatype::hdf5_datatype(hdf5_dataset const& dataset) : hdf5_object(H5Dget_type(dataset.get_id())), type_class_(H5Tget_class(get_id())) { if(dataset.get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataset_access_error ) ); } if(get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_access_error ) ); } }
hdf5_datatype::hdf5_datatype(hdf5_annotation const& annotation) : hdf5_object(H5Aget_type(annotation.get_id())), type_class_(H5Tget_class(get_id())) { if(annotation.get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_annotation_access_error ) ); } if(get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_access_error ) ); } }
void hdf5_dataset::close_impl() { if(H5Dclose(get_id()) < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataset_close_error, path_.c_str() ) ); } }
size_t hdf5_datatype::get_size() const { size_t size = H5Tget_size(get_id()); if(!size) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_access_error ) ); } return size; }
void hdf5_datatype::set_encoding(H5T_cset_t encoding) { herr_t status = H5Tset_cset(get_id(), encoding); if(status < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_set_charset_error ) ); } }
hdf5_datatype::hdf5_datatype(hid_t type) : hdf5_object(type), type_class_(H5Tget_class(type)) { if(type_class_ == H5T_NO_CLASS) { // error occurred boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_access_error ) ); } set_id(H5Tcopy(type)); if(get_id() < 0) { // error occurred boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_create_error ) ); } }
bool hdf5_datatype::is_variable_length_string() const { htri_t status = H5Tis_variable_str(get_id()); if(status < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_access_error ) ); } else if(status == 0) { return false; } return true; }
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 ) ); } }
hdf5_datatype::hdf5_datatype(H5T_class_t type_class) : hdf5_object(), type_class_(type_class) { if(type_class == H5T_STRING) { // go for C-style string, special treatment set_id(H5Tcopy(H5T_C_S1)); } else set_id(H5Tcreate(type_class, 1)); if(get_id() < 0) { // error occurred boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_create_error ) ); } }
void hdf5_dataset::read(hdf5_datatype const& type, void* buffer) { herr_t status = H5Dread( get_id(), type.get_id(), H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer ); if(status < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataset_read_error ) ); } }
hdf5_dataspace::hdf5_dataspace(std::size_t size) : hdf5_object() { if(size == 1) { set_id(H5Screate(H5S_SCALAR)); } else { hsize_t dims = size; set_id(H5Screate_simple(1, &dims, NULL)); } if(get_id() < 0) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_dataspace_create_error ) ); } }