diff --git a/modules/c++/hdf5.lite/include/hdf5/lite/HDF5Exception.h b/modules/c++/hdf5.lite/include/hdf5/lite/HDF5Exception.h index 74079b59e..3428f752c 100644 --- a/modules/c++/hdf5.lite/include/hdf5/lite/HDF5Exception.h +++ b/modules/c++/hdf5.lite/include/hdf5/lite/HDF5Exception.h @@ -46,9 +46,9 @@ namespace lite */ CODA_OSS_DECLARE_EXCEPTION(HDF5); -CODA_OSS_DECLARE_EXTENDED_EXCEPTION(DataSet, hdf5::lite::HDF5Exception) -CODA_OSS_DECLARE_EXTENDED_EXCEPTION(DataSpace, hdf5::lite::HDF5Exception) -CODA_OSS_DECLARE_EXTENDED_EXCEPTION(DataType, hdf5::lite::HDF5Exception) +CODA_OSS_DECLARE_EXTENDED_EXCEPTION(Dataset, hdf5::lite::HDF5Exception) +CODA_OSS_DECLARE_EXTENDED_EXCEPTION(Dataspace, hdf5::lite::HDF5Exception) +CODA_OSS_DECLARE_EXTENDED_EXCEPTION(Datatype, hdf5::lite::HDF5Exception) } } diff --git a/modules/c++/hdf5.lite/source/Read.cpp b/modules/c++/hdf5.lite/source/Read.cpp index f7a462b01..1598d3a90 100644 --- a/modules/c++/hdf5.lite/source/Read.cpp +++ b/modules/c++/hdf5.lite/source/Read.cpp @@ -33,31 +33,35 @@ static void read(const H5::DataSet& dataset, std::vector& result) { + static_assert(sizeof(double) * 8 == 64, "'double' should be 64-bits"); // IEEE_F64LE + const auto mem_type = dataset.getDataType(); - if (mem_type != H5::PredType::NATIVE_DOUBLE) + if (mem_type != H5::PredType::IEEE_F64LE) { - const except::Context context("mem_type != IEEE_F64LE", __FILE__, __LINE__, "read"); - throw hdf5::lite::DataSetException(context); + const except::Context context("getDataType() != IEEE_F64LE", __FILE__, __LINE__, "read"); + throw hdf5::lite::DatasetException(context); } dataset.read(result.data(), mem_type); } static void read(const H5::DataSet& dataset, std::vector& result) { + static_assert(sizeof(float) * 8 == 32, "'float' should be 32-bits"); // IEEE_F32LE + const auto mem_type = dataset.getDataType(); - if (mem_type != H5::PredType::NATIVE_FLOAT) + if (mem_type != H5::PredType::IEEE_F32LE) { - const except::Context context("mem_type != IEEE_F32LE", __FILE__, __LINE__, "read"); - throw hdf5::lite::DataSetException(context); + const except::Context context("getDataType() != IEEE_F32LE", __FILE__, __LINE__, "read"); + throw hdf5::lite::DatasetException(context); } dataset.read(result.data(), mem_type); } template -static types::RowCol readDatasetT(const H5::DataSet& dataset, H5T_class_t type_class, - std::vector& result) +static types::RowCol readDatasetT(const H5::DataSet& dataset, std::vector& result) { - if (type_class != dataset.getTypeClass()) + if (dataset.getTypeClass() != H5T_FLOAT) { - throw std::invalid_argument("getTypeClass() returned wrong value."); + const except::Context context("getTypeClass() != H5T_FLOAT", __FILE__, __LINE__, "readDatasetT"); + throw hdf5::lite::DatatypeException(context); } const auto retval = hdf5::lite::details::getSimpleExtentSize(dataset); @@ -72,13 +76,11 @@ static types::RowCol readDatasetT(const H5::DataSet& dataset, H5T_class_ inline types::RowCol readDataset_(const H5::DataSet& dataset, std::vector& result) { - static_assert(sizeof(float) * 8 == 32, "'float' should be 32-bits"); // IEEE_F32LE - return readDatasetT(dataset, H5T_FLOAT, result); + return readDatasetT(dataset, result); } inline types::RowCol readDataset_(const H5::DataSet& dataset, std::vector& result) { - static_assert(sizeof(double) * 8 == 64, "'double' should be 64-bits"); // IEEE_F64LE - return readDatasetT(dataset, H5T_FLOAT, result); + return readDatasetT(dataset, result); } template static types::RowCol readFile_(const coda_oss::filesystem::path& fileName, const std::string& datasetName, diff --git a/modules/c++/hdf5.lite/source/hdf5.lite.cpp b/modules/c++/hdf5.lite/source/hdf5.lite.cpp index 609e6da30..2493de79f 100644 --- a/modules/c++/hdf5.lite/source/hdf5.lite.cpp +++ b/modules/c++/hdf5.lite/source/hdf5.lite.cpp @@ -49,18 +49,18 @@ void hdf5::lite::details::try_catch_H5Exceptions_(std::function f, // catch failure caused by the DataSet operations catch (const H5::DataSetIException& error) { - throw hdf5::lite::DataSetException(make_Context(error, file, line)); + throw hdf5::lite::DatasetException(make_Context(error, file, line)); } // catch failure caused by the DataSpace operations catch (const H5::DataSpaceIException& error) { - throw hdf5::lite::DataSpaceException(make_Context(error, file, line)); + throw hdf5::lite::DataspaceException(make_Context(error, file, line)); } // catch failure caused by the DataType operations catch (const H5::DataTypeIException& error) { - throw hdf5::lite::DataTypeException(make_Context(error, file, line)); + throw hdf5::lite::DatatypeException(make_Context(error, file, line)); } } diff --git a/modules/c++/hdf5.lite/unittests/test_hdf5read.cpp b/modules/c++/hdf5.lite/unittests/test_hdf5read.cpp index 9abc451e3..9d7b05a76 100644 --- a/modules/c++/hdf5.lite/unittests/test_hdf5read.cpp +++ b/modules/c++/hdf5.lite/unittests/test_hdf5read.cpp @@ -119,7 +119,7 @@ TEST_CASE(test_hdf5Read_nested_small_wrongType) std::vector data; TEST_SPECIFIC_EXCEPTION( hdf5::lite::readFile(path, "/Data/1/bar/cat/a/r", data), - hdf5::lite::DataSetException); + hdf5::lite::DatasetException); } TEST_MAIN(