-
Notifications
You must be signed in to change notification settings - Fork 16
/
hdffile.hpp
67 lines (54 loc) · 1.4 KB
/
hdffile.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef hdffileH
#define hdffileH
#include <hdf5/hdfgroup.hpp>
#include <hdf5/hdf5/traits.hpp>
#include <string>
namespace hdf {
template<class HDFImpl=HDF5Traits>
class HDFFile : public HDFGroup<HDFImpl> {
public:
typedef HDFGroup<HDFImpl> HDFGroup_t;
enum Flags {
none = 0,
truncate = 1
};
/**
* Open the hdf5 file at the given location
* Truncates the file if flags == truncate
*/
HDFFile(const std::string & path, Flags flags = none) {
file = HDFImpl::open(path, flags==truncate);
HDFGroup_t::initFileGroup(*file);
};
~HDFFile() {
HDFGroup<HDFImpl>::group.reset();
}
private:
std::shared_ptr<typename HDFImpl::file_handle_type> file;
};
#ifdef H5_HAVE_PARALLEL
template<class HDFImpl=HDF5Traits>
class HDFParallelFile : public HDFGroup<HDFImpl> {
public:
typedef HDFGroup<HDFImpl> HDFGroup_t;
enum Flags {
none = 0,
truncate = 1
};
/**
* Open the hdf5 file at the given location
* Truncates the file if flags == truncate
*/
HDFParallelFile(const std::string & path, Flags flags = none) {
file = HDFImpl::parallel_open(path, flags==truncate);
HDFGroup_t::initFileGroup(*file);
};
~HDFParallelFile() {
HDFGroup<HDFImpl>::group.reset();
}
private:
std::shared_ptr<typename HDFImpl::parallel_file_handle_type> file;
};
#endif
}
#endif