Added managed of generic structures directly by the HDF5 array core
This commit is contained in:
parent
1b971e96c0
commit
2e2224982b
@ -44,6 +44,9 @@ knowledge of the CeCILL license and that you accept its terms.
|
|||||||
#include <boost/multi_array.hpp>
|
#include <boost/multi_array.hpp>
|
||||||
#include <boost/type_traits/is_same.hpp>
|
#include <boost/type_traits/is_same.hpp>
|
||||||
#include <boost/type_traits/is_floating_point.hpp>
|
#include <boost/type_traits/is_floating_point.hpp>
|
||||||
|
#include <boost/preprocessor/cat.hpp>
|
||||||
|
#include <boost/preprocessor/stringize.hpp>
|
||||||
|
#include <boost/preprocessor/seq/for_each.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <H5Cpp.h>
|
#include <H5Cpp.h>
|
||||||
|
|
||||||
@ -59,7 +62,7 @@ namespace CosmoTool {
|
|||||||
|
|
||||||
template<typename T, class Enable = void> struct get_hdf5_data_type
|
template<typename T, class Enable = void> struct get_hdf5_data_type
|
||||||
{
|
{
|
||||||
static H5::PredType type()
|
static H5::DataType type()
|
||||||
{
|
{
|
||||||
BOOST_MPL_ASSERT_MSG(0, Unknown_HDF5_data_type, ());
|
BOOST_MPL_ASSERT_MSG(0, Unknown_HDF5_data_type, ());
|
||||||
return H5::PredType::NATIVE_DOUBLE;
|
return H5::PredType::NATIVE_DOUBLE;
|
||||||
@ -68,7 +71,7 @@ namespace CosmoTool {
|
|||||||
|
|
||||||
#define HDF5_TYPE(tl, thdf5) \
|
#define HDF5_TYPE(tl, thdf5) \
|
||||||
template<typename T> struct get_hdf5_data_type<T, typename boost::enable_if<boost::is_same<T, tl> >::type> \
|
template<typename T> struct get_hdf5_data_type<T, typename boost::enable_if<boost::is_same<T, tl> >::type> \
|
||||||
{ static H5::PredType type() { return H5::PredType::thdf5; }; }
|
{ static H5::DataType type() { return H5::PredType::thdf5; }; }
|
||||||
|
|
||||||
HDF5_TYPE(char , NATIVE_CHAR);
|
HDF5_TYPE(char , NATIVE_CHAR);
|
||||||
HDF5_TYPE(long long , NATIVE_LLONG);
|
HDF5_TYPE(long long , NATIVE_LLONG);
|
||||||
@ -202,6 +205,39 @@ namespace CosmoTool {
|
|||||||
hdf5_read_array(fg, data_set_name, data, hdf5_ComplexType<T>::ctype()->type);
|
hdf5_read_array(fg, data_set_name, data, hdf5_ComplexType<T>::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<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()); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#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<STRUCT> { \
|
||||||
|
static H5::DataType type() { return CTOOL_HDF5_NAME(STRUCT)::ctype()->type; }; \
|
||||||
|
}; \
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user