9 #ifndef H5FILE_MISC_HPP
10 #define H5FILE_MISC_HPP
14 #include <H5Fpublic.h>
16 #include "../H5Utility.hpp"
24 inline unsigned convert_open_flag(
unsigned openFlags) {
25 unsigned res_open = 0;
27 res_open |= H5F_ACC_RDONLY;
29 res_open |= H5F_ACC_RDWR;
31 res_open |= H5F_ACC_CREAT;
33 res_open |= H5F_ACC_TRUNC;
35 res_open |= H5F_ACC_EXCL;
41 inline File::File(
const std::string& filename,
unsigned openFlags,
43 : _filename(filename) {
45 openFlags = convert_open_flag(openFlags);
47 unsigned createMode = openFlags & (H5F_ACC_TRUNC | H5F_ACC_EXCL);
48 unsigned openMode = openFlags & (H5F_ACC_RDWR | H5F_ACC_RDONLY);
49 bool mustCreate = createMode > 0;
50 bool openOrCreate = (openFlags & H5F_ACC_CREAT) > 0;
56 std::unique_ptr<SilenceHDF5> silencer;
57 if (openOrCreate) silencer.reset(
new SilenceHDF5());
59 _hid = H5Fopen(_filename.c_str(), openMode, fileAccessProps.
getId());
65 createMode = H5F_ACC_EXCL;
67 HDF5ErrMapper::ToException<FileException>(
68 std::string(
"Unable to open file " + _filename));
72 if ((
_hid = H5Fcreate(_filename.c_str(), createMode, H5P_DEFAULT,
73 fileAccessProps.
getId())) < 0) {
74 HDF5ErrMapper::ToException<FileException>(
75 std::string(
"Unable to create file " + _filename));
84 if (H5Fflush(
_hid, H5F_SCOPE_GLOBAL) < 0) {
85 HDF5ErrMapper::ToException<FileException>(
86 std::string(
"Unable to flush file " + _filename));
void flush()
flush
Definition: H5File_misc.hpp:83
File(const std::string &filename, unsigned openFlags=ReadOnly, const FileAccessProps &fileAccessProps=FileDriver())
File.
Definition: H5File_misc.hpp:41
@ Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:37
@ Create
Open flag: Create non existing file.
Definition: H5File.hpp:43
@ ReadOnly
Open flag: Read only access.
Definition: H5File.hpp:33
@ ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:35
@ Excl
Open flag: Open will fail if file already exist.
Definition: H5File.hpp:39
const std::string & getName() const noexcept
Return the name of the file.
Definition: H5File_misc.hpp:79
bool isValid() const noexcept
isValid
Definition: H5Object_misc.hpp:51
hid_t _hid
Definition: H5Object.hpp:81
Base HDF5 property List.
Definition: H5PropertyList.hpp:46
hid_t getId() const
Definition: H5PropertyList.hpp:56
Utility class to disable HDF5 stack printing inside a scope.
Definition: H5Utility.hpp:20
Definition: H5_definitions.hpp:15