Hey, that’s pretty cool! Thanks for sharing that. Nope, I haven’t tried that.
Alas, I don’t think I can use it either because I need finer grained control over properties controlling dataset creation and transfer and type conversion. If an hid_t for creation props and another hid_t for transfer props were provided as optional args to these routines, that could potentially make them more generally useful t cases like mine. The H5CPP interface looks really useful for common/simple cases, but I would rather that templatization of HDF5 compile-time types NOT to be too closely coupled with other aspects of data set creation and I/O (or container classes). Thanks again for sharing though. Mark "Hdf-forum on behalf of Steven Varga" wrote: hello, did you try H5CPP<http://h5cpp.ca/>? You can find the implemented functionality in the code base or freely use the C++14 template library for vectors, and armadillo matrices. The github page is here<https://github.com/steven-varga/h5cpp> At this stage the profiled templates can handle armadillo vectors, matrices and cubes, as well stl vectors and structs. best, steven On Mon, Feb 5, 2018 at 6:03 PM, Miller, Mark C. <[email protected]<mailto:[email protected]>> wrote: Hi All, I am wondering if anyone else in C++ coding of HDF5 has run into the following problem… I have a templatized function that writes an HDF5 dataset… template <class T> static void WriteVecToHDF5(hid_t fid, char const *name, std::vector<T> const &vec, int d2size) { hsize_t siz2d[2] = {(hsize_t) vec.size() / d2size, d2size}; hid_t spid = H5Screate_simple(d2size>1?2:1, siz2d, 0); hid_t dsid = H5Dcreate(fid, name, HDF5Type<T>().Type(), spid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(dsid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &vec[0]); H5Dclose(dsid); H5Sclose(spid); } I would like the template instantiation to then return the correct H5T_NATIVE_XXX type so WriteVecToHDF5<int>(…) produces a call to H5Dcreae, there in bold red with H5T_NATIVE_INT, etc. There does not appear to be any support in the HDF5 implementation for this. Am I missing something? Below is what I did (for int, float and double but can easily be expanded to cover all primitive types) and am wondering if others find this useful enough (or something like it) that it ought to be included in HDF5 C++ interface? // base class template <class T> class HDF5TypeBase { public: HDF5TypeBase() {} ; virtual ~HDF5TypeBase() {}; }; // base class for type-specific template specializations to follow template <class T> class HDF5Type : public HDF5TypeBase<T> { public: HDF5Type() : HDF5TypeBase<T>() {}; virtual ~HDF5Type() {}; virtual hid_t Type() const { return H5T_NATIVE_HERR; }; }; // int, H5T_NATIVE_INT specialization template <> class HDF5Type<int> : public HDF5TypeBase<int> { public: HDF5Type() : HDF5TypeBase<int>() {}; virtual ~HDF5Type() {}; virtual hid_t Type() const { return H5T_NATIVE_INT; }; }; // float, H5T_NATIVE_FLOAT specialization template <> class HDF5Type<float> : public HDF5TypeBase<float> { public: HDF5Type() : HDF5TypeBase<float>() {}; virtual ~HDF5Type() {}; virtual hid_t Type() const { return H5T_NATIVE_FLOAT; }; }; // double, H5T_NATIVE_DOUBLE specialization template <> class HDF5Type<double> : public HDF5TypeBase<double> { public: HDF5Type() : HDF5TypeBase<double>() {}; virtual ~HDF5Type() {}; virtual hid_t Type() const { return H5T_NATIVE_DOUBLE; }; }; This permits in the HDF5Type<T>().Type(), bold red, in the snipit above, to actually work -- Mark C. Miller, LLNL "In the end, we will remember not the words of our enemies but the silence of our friends" - MLK _______________________________________________ Hdf-forum is for HDF software users discussion. [email protected]<mailto:[email protected]> http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org Twitter: https://twitter.com/hdf5
_______________________________________________ Hdf-forum is for HDF software users discussion. [email protected] http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org Twitter: https://twitter.com/hdf5
