hdf5serie  2.0.0
HDF5 Serie
utils.h
1#ifndef _HDF5SERIE_UTILS_H_
2#define _HDF5SERIE_UTILS_H_
3
4#include "interface.h"
5#include "toh5type.h"
6#include <boost/core/demangle.hpp>
7#include <vector>
8#include <cstdlib>
9
10namespace H5 {
11
12class VecStr {
13 public:
14 VecStr(size_t size) : arr(size, nullptr) {}
15 ~VecStr() {
16 for(auto & it : arr)
17 free(it);
18 }
19 void alloc(size_t i, size_t size) { free(arr[i]); arr[i]=static_cast<char*>(malloc((size+1)*sizeof(char))); }
20 char *&operator[](size_t i) { return arr[i]; }
21 private:
22 std::vector<char*> arr;
23};
24
25template<class T>
26ScopedHID getMemDataTypeID(ScopedHID filedt, const std::string &path, const std::string &className) {
27 // HDF5 does not convert between different string character encodings but be only support reading of ASCII and UTF-8 file data
28 // to UTF-8 memory data, so we can always the file datatype.
29 if(H5Tget_class(filedt) == H5T_STRING && std::is_same_v<T,std::string>)
30 return filedt;
31 // for anything else we just the type T and HDF5 does the conversion
32 return ScopedHID(H5Tcopy(toH5Type<T>()), &H5Tclose);
33}
34
35}
36
37#endif
Definition: interface.h:78
Definition: utils.h:12