Fixed support for automatic type saving in HDF5

This commit is contained in:
Guilhem Lavaux 2015-01-31 15:47:44 +01:00
parent 84e841814a
commit 44756de2a9
2 changed files with 40 additions and 8 deletions

View file

@ -210,31 +210,32 @@ namespace CosmoTool {
#define CTOOL_HDF5_INSERT_ELEMENT(r, STRUCT, element) \
{ \
CosmoTool::get_hdf5_data_type<BOOST_PP_TUPLE_ELEM(2, 0, element)> 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()); \
position = HOFFSET(STRUCT, BOOST_PP_TUPLE_ELEM(2, 1, element)); \
const char *field_name = BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, element)); \
std::cout << "Field " << field_name << " offset = " << position << endl; \
type.insertMember(field_name, position, t.type()); \
}
#define CTOOL_STRUCT_TYPE(STRUCT, TNAME, ATTRIBUTES) \
namespace CosmoTool { \
class CTOOL_HDF5_NAME(STRUCT) { \
class TNAME { \
public: \
H5::CompType type; \
\
CTOOL_HDF5_NAME(STRUCT)() : type(sizeof(STRUCT)) \
TNAME() : 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 const TNAME *ctype() \
{ \
static CTOOL_HDF5_NAME(STRUCT) singleton; \
static TNAME singleton; \
return &singleton; \
} \
}; \
template<> struct get_hdf5_data_type<STRUCT> { \
static H5::DataType type() { return CTOOL_HDF5_NAME(STRUCT)::ctype()->type; }; \
static H5::DataType type() { return TNAME::ctype()->type; }; \
}; \
};