From c38d49913241964be97ab8941bb50cf8c8c80f41 Mon Sep 17 00:00:00 2001 From: Eugen Wintersberger Date: Sat, 12 Jan 2019 21:09:48 +0100 Subject: [PATCH] Added data transform to the data transfer property list Update #318 --- src/h5cpp/property/dataset_transfer.cpp | 67 +++++++++++++++++++++++++ src/h5cpp/property/dataset_transfer.hpp | 34 +++++++++++++ test/property/dataset_transfer_test.cpp | 8 +++ 3 files changed, 109 insertions(+) diff --git a/src/h5cpp/property/dataset_transfer.cpp b/src/h5cpp/property/dataset_transfer.cpp index 1a9e6bc880..440b897575 100644 --- a/src/h5cpp/property/dataset_transfer.cpp +++ b/src/h5cpp/property/dataset_transfer.cpp @@ -29,6 +29,9 @@ #include #include #include +#include +#include +#include namespace hdf5 { namespace property { @@ -47,6 +50,70 @@ DatasetTransferList::DatasetTransferList(ObjectHandle &&handle) : } } +void DatasetTransferList::data_transform(const std::string &transform) const +{ + data_transform(transform.data()); +} + +void DatasetTransferList::data_transform(const char *transform) const +{ + herr_t status = H5Pset_data_transform(static_cast(*this),transform); + if(status<0) + { + error::Singleton::instance().throw_with_stack("Failure to set data transform expression!"); + } +} + +ssize_t DatasetTransferList::data_transform_size() const +{ + ssize_t size = H5Pget_data_transform(static_cast(*this),NULL,0); + if(size<0) + { + error::Singleton::instance().throw_with_stack("Failure to get the size of the data transform expression!"); + } + + return size; +} + +bool DatasetTransferList::has_data_transform() const +{ + ssize_t size = data_transform_size(); + if(size == 0) + { + return false; + } + else if(size > 0) + { + return true; + } + + return false; +} + +std::string DatasetTransferList::data_transform() const +{ + if(has_data_transform()) + { + std::vector buffer(data_transform_size()+1); + herr_t status = H5Pget_data_transform(static_cast(*this), + buffer.data(),buffer.size()+1); + if(status<0) + { + error::Singleton::instance().throw_with_stack("Failure to retrieve the data transformation expression!"); + } + + std::string expression(buffer.data(),buffer.size()-1); + + return expression; + } + else + { + return std::string(); + } +} + + + #ifdef WITH_MPI #ifdef __GNUC__ diff --git a/src/h5cpp/property/dataset_transfer.hpp b/src/h5cpp/property/dataset_transfer.hpp index 5ea3b2faf5..bebf8963cd 100644 --- a/src/h5cpp/property/dataset_transfer.hpp +++ b/src/h5cpp/property/dataset_transfer.hpp @@ -51,12 +51,46 @@ std::ostream &operator<<(std::ostream &stream,const MPIChunkOption &option); #endif class DLL_EXPORT DatasetTransferList : public List { + private: + ssize_t data_transform_size() const; public: + DatasetTransferList(); ~DatasetTransferList(); explicit DatasetTransferList(ObjectHandle &&handle); + //! + //! \brief set a data transform + //! + //! \param transform string with the transformation expression + //! + void data_transform(const std::string &transform) const; + + //! + //! \brief set a data transform + //! + //! \param transform pointer to the transform string + //! \param size length of the transformation string + //! + void data_transform(const char *transform) const; + + //! + //! \brief check if a data transform is set + //! + bool has_data_transform() const; + + //! + //! \brief get transform expression + //! + //! Returns a string with the expression representing the data transform. + //! If no data transform is set on the transfer property list an empty + //! string is returned. + //! + //! \return string with the transformation expression + //! + std::string data_transform() const; + #ifdef WITH_MPI void mpi_transfer_mode(MPITransferMode mode) const; MPITransferMode mpi_transfer_mode() const; diff --git a/test/property/dataset_transfer_test.cpp b/test/property/dataset_transfer_test.cpp index 00d0f79e05..9f19f39982 100644 --- a/test/property/dataset_transfer_test.cpp +++ b/test/property/dataset_transfer_test.cpp @@ -55,6 +55,14 @@ TEST(DatasetTransferList,test_as_default_argument) EXPECT_NO_THROW(test_function()); } +TEST(DatasetTransferList,test_data_transform) +{ + pl::DatasetTransferList dxpl; + std::string transform_expression="x+1"; + EXPECT_NO_THROW(dxpl.data_transform(transform_expression)); + EXPECT_EQ("x+1",dxpl.data_transform()); +} + #ifdef WITH_MPI TEST(DatasetTransferList, flags)