Grid 0.7.0
Hdf5Type.h
Go to the documentation of this file.
1#ifndef GRID_SERIALISATION_HDF5_TYPE_H
2#define GRID_SERIALISATION_HDF5_TYPE_H
3
4#include <H5Cpp.h>
5#include <complex>
6#include <memory>
7
8#ifdef H5_NO_NAMESPACE
9#define H5NS
10#else
11#define H5NS H5
12#endif
13
14#define HDF5_NATIVE_TYPE(predType, cType)\
15template <>\
16class Hdf5Type<cType>\
17{\
18public:\
19 static inline const H5NS::DataType & type(void)\
20 {\
21 return H5NS::PredType::predType;\
22 }\
23 static constexpr bool isNative = true;\
24};
25
26#define DEFINE_HDF5_NATIVE_TYPES \
27HDF5_NATIVE_TYPE(NATIVE_B8, bool);\
28HDF5_NATIVE_TYPE(NATIVE_CHAR, char);\
29HDF5_NATIVE_TYPE(NATIVE_SCHAR, signed char);\
30HDF5_NATIVE_TYPE(NATIVE_UCHAR, unsigned char);\
31HDF5_NATIVE_TYPE(NATIVE_SHORT, short);\
32HDF5_NATIVE_TYPE(NATIVE_USHORT, unsigned short);\
33HDF5_NATIVE_TYPE(NATIVE_INT, int);\
34HDF5_NATIVE_TYPE(NATIVE_UINT, unsigned int);\
35HDF5_NATIVE_TYPE(NATIVE_LONG, long);\
36HDF5_NATIVE_TYPE(NATIVE_ULONG, unsigned long);\
37HDF5_NATIVE_TYPE(NATIVE_LLONG, long long);\
38HDF5_NATIVE_TYPE(NATIVE_ULLONG, unsigned long long);\
39HDF5_NATIVE_TYPE(NATIVE_FLOAT, float);\
40HDF5_NATIVE_TYPE(NATIVE_DOUBLE, double);\
41HDF5_NATIVE_TYPE(NATIVE_LDOUBLE, long double);
42
43namespace Grid
44{
45 template <typename T> class Hdf5Type
46 {
47 public:
48 static constexpr bool isNative = false;
49 };
50
52
53 template <typename R>
54 class Hdf5Type<Grid::complex<R> >
55 {
56 public:
57 static inline const H5NS::DataType & type(void)
58 {
59 if (typePtr_ == nullptr)
60 {
61 typePtr_.reset(new H5NS::CompType(sizeof(Grid::complex<R>)));
62 typePtr_->insertMember("re", 0, Hdf5Type<R>::type());
63 typePtr_->insertMember("im", sizeof(R), Hdf5Type<R>::type());
64 }
65
66 return *typePtr_;
67 }
68 static constexpr bool isNative = false;
69 private:
70 static std::unique_ptr<H5NS::CompType> typePtr_;
71 };
72
73 template <typename R>
74 std::unique_ptr<H5NS::CompType> Hdf5Type<Grid::complex<R>>::typePtr_ = nullptr;
75
76}
77
78#undef HDF5_NATIVE_TYPE
79
80#endif /* GRID_SERIALISATION_HDF5_TYPE_H */
std::complex< T > complex
Definition Simd.h:82
static std::unique_ptr< H5NS::CompType > typePtr_
Definition Hdf5Type.h:70
static const H5NS::DataType & type(void)
Definition Hdf5Type.h:57
static constexpr bool isNative
Definition Hdf5Type.h:68
static constexpr bool isNative
Definition Hdf5Type.h:48
std::unique_ptr< H5NS::CompType > Hdf5Type< Grid::complex< R > >::typePtr_
Definition Hdf5Type.h:74
DEFINE_HDF5_NATIVE_TYPES
Definition Hdf5Type.h:51