Added support for enum type in HDF5

This commit is contained in:
Guilhem Lavaux 2015-02-16 10:59:33 +01:00
parent 188af485c9
commit 22aa572370
2 changed files with 79 additions and 1 deletions

View file

@ -146,6 +146,34 @@ namespace CosmoTool {
}
};
class hdf5_BoolType
{
public:
H5::EnumType type;
hdf5_BoolType()
: type(sizeof(bool))
{
bool v;
v = true;
type.insert("TRUE", &v);
v = false;
type.insert("FALSE", &v);
}
static const hdf5_BoolType *ctype()
{
static hdf5_BoolType singleton;
return &singleton;
}
};
template<> struct get_hdf5_data_type<bool> {
static H5::DataType type() {
return hdf5_BoolType::ctype()->type;
}
};
template<typename ArrayType>
void hdf5_write_array(H5::CommonFG& fg, const std::string& data_set_name, const ArrayType& data )
@ -295,6 +323,38 @@ namespace CosmoTool { \
}; \
};
#define CTOOL_HDF5_INSERT_ENUM_ELEMENT(r, STRUCT, element) \
{ \
const char *field_name = BOOST_PP_STRINGIZE(element); \
STRUCT a = element; \
type.insert(field_name, &a); \
}
#define CTOOL_ENUM_TYPE(STRUCT, TNAME, ATTRIBUTES) \
namespace CosmoTool { \
class TNAME { \
public: \
H5::EnumType type; \
\
TNAME() : type(sizeof(STRUCT)) \
{ \
long position; \
BOOST_PP_SEQ_FOR_EACH(CTOOL_HDF5_INSERT_ENUM_ELEMENT, STRUCT, ATTRIBUTES) \
} \
\
static const TNAME *ctype() \
{ \
static TNAME singleton; \
return &singleton; \
} \
}; \
template<> struct get_hdf5_data_type<STRUCT> { \
static H5::DataType type() { return TNAME::ctype()->type; }; \
}; \
};
#define CTOOL_ARRAY_TYPE(ARRAY_TYPE, DIM, TNAME) \
namespace CosmoTool { \
class TNAME { \