Skip to content

Commit

Permalink
Added data transform to the data transfer property list
Browse files Browse the repository at this point in the history
Update #318
  • Loading branch information
eugenwintersberger committed Jan 12, 2019
1 parent 4f44420 commit c38d499
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/h5cpp/property/dataset_transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <h5cpp/property/property_class.hpp>
#include <h5cpp/error/error.hpp>
#include <sstream>
#include <algorithm>
#include <vector>
#include <iterator>

namespace hdf5 {
namespace property {
Expand All @@ -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<hid_t>(*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<hid_t>(*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<char> buffer(data_transform_size()+1);
herr_t status = H5Pget_data_transform(static_cast<hid_t>(*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__
Expand Down
34 changes: 34 additions & 0 deletions src/h5cpp/property/dataset_transfer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/property/dataset_transfer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c38d499

Please sign in to comment.