16 #ifdef ALPS_SINGLE_THREAD 17 #define ALPS_HDF5_LOCK_MUTEX 19 #define ALPS_HDF5_LOCK_MUTEX boost::lock_guard<boost::recursive_mutex> guard(mutex_); 22 #ifdef H5_HAVE_THREADSAFE 23 #define ALPS_HDF5_FAKE_THREADSAFETY 25 #define ALPS_HDF5_FAKE_THREADSAFETY ALPS_HDF5_LOCK_MUTEX 28 #define ALPS_HDF5_NATIVE_INTEGRAL_TYPES \ 29 char, signed char, unsigned char, \ 30 short, unsigned short, \ 31 int, unsigned, long, unsigned long, \ 32 long long, unsigned long long, \ 33 float, double, long double, \ 36 #define ALPS_HDF5_FOREACH_NATIVE_TYPE_INTEGRAL(CALLBACK, ARG) \ 38 CALLBACK(signed char, ARG) \ 39 CALLBACK(unsigned char, ARG) \ 40 CALLBACK(short, ARG) \ 41 CALLBACK(unsigned short, ARG) \ 43 CALLBACK(unsigned, ARG) \ 45 CALLBACK(unsigned long, ARG) \ 46 CALLBACK(long long, ARG) \ 47 CALLBACK(unsigned long long, ARG) \ 48 CALLBACK(float, ARG) \ 49 CALLBACK(double, ARG) \ 50 CALLBACK(long double, ARG) \ 57 template<
typename T>
struct native_ptr_converter {
58 native_ptr_converter(std::size_t) {}
59 inline T
const * apply(T
const * v) {
64 template<>
struct native_ptr_converter<std::string> {
65 std::vector<char const *> data;
66 native_ptr_converter(std::size_t
size): data(size) {}
67 inline char const *
const * apply(std::string
const * v) {
68 for (std::vector<char const *>::iterator it = data.begin(); it != data.end(); ++it)
69 *it = v[it - data.begin()].c_str();
74 inline herr_t noop(hid_t) {
82 std::string invoke(hid_t
id) {
83 std::ostringstream buffer;
84 buffer <<
"HDF5 error: " << cast<std::string>(id) << std::endl;
85 H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, callback, &buffer);
91 static herr_t callback(
unsigned n, H5E_error2_t
const * desc,
void * buffer) {
92 *
reinterpret_cast<std::ostringstream *
>(buffer)
94 << cast<std::string>(n)
95 <<
" " << desc->file_name
97 << cast<std::string>(desc->line)
108 template<herr_t(*F)(h
id_t)>
class resource {
110 resource(): _id(-1) {}
111 resource(hid_t
id): _id(
id) {
117 if(_id < 0 || (_id = F(_id)) < 0) {
118 std::cerr <<
"Error in " 126 <<
error().invoke(_id)
132 operator hid_t()
const {
136 resource<F> & operator=(hid_t
id) {
146 typedef resource<H5Gclose> group_type;
147 typedef resource<H5Dclose> data_type;
148 typedef resource<H5Aclose> attribute_type;
149 typedef resource<H5Sclose> space_type;
150 typedef resource<H5Tclose> type_type;
151 typedef resource<H5Pclose> property_type;
152 typedef resource<noop> error_type;
154 inline hid_t check_group(hid_t
id) { group_type unused(
id);
return unused; }
155 inline hid_t check_data(hid_t
id) { data_type unused(
id);
return unused; }
156 inline hid_t check_attribute(hid_t
id) { attribute_type unused(
id);
return unused; }
157 inline hid_t check_space(hid_t
id) { space_type unused(
id);
return unused; }
158 inline hid_t check_type(hid_t
id) { type_type unused(
id);
return unused; }
159 inline hid_t check_property(hid_t
id) { property_type unused(
id);
return unused; }
160 inline hid_t check_error(hid_t
id) { error_type unused(
id);
return unused; }
162 inline hid_t get_native_type(
char) {
return H5Tcopy(H5T_NATIVE_CHAR); }
163 inline hid_t get_native_type(
signed char) {
return H5Tcopy(H5T_NATIVE_SCHAR); }
164 inline hid_t get_native_type(
unsigned char) {
return H5Tcopy(H5T_NATIVE_UCHAR); }
165 inline hid_t get_native_type(
short) {
return H5Tcopy(H5T_NATIVE_SHORT); }
166 inline hid_t get_native_type(
unsigned short) {
return H5Tcopy(H5T_NATIVE_USHORT); }
167 inline hid_t get_native_type(
int) {
return H5Tcopy(H5T_NATIVE_INT); }
168 inline hid_t get_native_type(
unsigned) {
return H5Tcopy(H5T_NATIVE_UINT); }
169 inline hid_t get_native_type(
long) {
return H5Tcopy(H5T_NATIVE_LONG); }
170 inline hid_t get_native_type(
unsigned long) {
return H5Tcopy(H5T_NATIVE_ULONG); }
171 inline hid_t get_native_type(
long long) {
return H5Tcopy(H5T_NATIVE_LLONG); }
172 inline hid_t get_native_type(
unsigned long long) {
return H5Tcopy(H5T_NATIVE_ULLONG); }
173 inline hid_t get_native_type(
float) {
return H5Tcopy(H5T_NATIVE_FLOAT); }
174 inline hid_t get_native_type(
double) {
return H5Tcopy(H5T_NATIVE_DOUBLE); }
175 inline hid_t get_native_type(
long double) {
return H5Tcopy(H5T_NATIVE_LDOUBLE); }
176 inline hid_t get_native_type(
bool) {
return H5Tcopy(H5T_NATIVE_SCHAR); }
177 inline hid_t get_native_type(std::string) {
178 hid_t type_id = H5Tcopy(H5T_C_S1);
179 detail::check_error(H5Tset_size(type_id, H5T_VARIABLE));
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
error_type< T >::type error(T const &arg)
#define ALPS_STRINGIFY(arg)