diff --git a/src/hdf5_array.hpp b/src/hdf5_array.hpp index 455d4b7..fc1a727 100644 --- a/src/hdf5_array.hpp +++ b/src/hdf5_array.hpp @@ -44,6 +44,9 @@ knowledge of the CeCILL license and that you accept its terms. #include #include #include +#include +#include +#include #include #include @@ -59,7 +62,7 @@ namespace CosmoTool { template struct get_hdf5_data_type { - static H5::PredType type() + static H5::DataType type() { BOOST_MPL_ASSERT_MSG(0, Unknown_HDF5_data_type, ()); return H5::PredType::NATIVE_DOUBLE; @@ -68,7 +71,7 @@ namespace CosmoTool { #define HDF5_TYPE(tl, thdf5) \ template struct get_hdf5_data_type >::type> \ - { static H5::PredType type() { return H5::PredType::thdf5; }; } + { static H5::DataType type() { return H5::PredType::thdf5; }; } HDF5_TYPE(char , NATIVE_CHAR); HDF5_TYPE(long long , NATIVE_LLONG); @@ -202,6 +205,39 @@ namespace CosmoTool { hdf5_read_array(fg, data_set_name, data, hdf5_ComplexType::ctype()->type); } + +#define CTOOL_HDF5_NAME(STRUCT) BOOST_PP_CAT(hdf5_,STRUCT) +#define CTOOL_HDF5_INSERT_ELEMENT(r, STRUCT, element) \ + { \ + CosmoTool::get_hdf5_data_type t; \ + position = offsetof(STRUCT, BOOST_PP_TUPLE_ELEM(2, 1, element)); \ + type.insertMember(BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, element)), position, t.type()); \ + } + +#define CTOOL_STRUCT_TYPE(STRUCT, TNAME, ATTRIBUTES) \ +namespace CosmoTool { \ + class CTOOL_HDF5_NAME(STRUCT) { \ + public: \ + H5::CompType type; \ + \ + CTOOL_HDF5_NAME(STRUCT)() : type(sizeof(STRUCT)) \ + { \ + long position; \ + BOOST_PP_SEQ_FOR_EACH(CTOOL_HDF5_INSERT_ELEMENT, STRUCT, ATTRIBUTES) \ + type.pack(); \ + } \ + \ + static const CTOOL_HDF5_NAME(STRUCT) *ctype() \ + { \ + static CTOOL_HDF5_NAME(STRUCT) singleton; \ + return &singleton; \ + } \ + }; \ + template<> struct get_hdf5_data_type { \ + static H5::DataType type() { return CTOOL_HDF5_NAME(STRUCT)::ctype()->type; }; \ + }; \ +}; + }; #endif