15#include "../H5Utility.hpp"
24inline 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;
50 openFlags = convert_open_flag(openFlags);
52 unsigned createMode = openFlags & (H5F_ACC_TRUNC | H5F_ACC_EXCL);
53 unsigned openMode = openFlags & (H5F_ACC_RDWR | H5F_ACC_RDONLY);
54 bool mustCreate = createMode > 0;
55 bool openOrCreate = (openFlags & H5F_ACC_CREAT) > 0;
61 std::unique_ptr<SilenceHDF5> silencer;
65 _hid = H5Fopen(filename.c_str(), openMode, fileAccessProps.
getId());
72 createMode = H5F_ACC_EXCL;
75 std::string(
"Unable to open file " + filename));
79 auto fcpl = fileCreateProps.
getId();
80 auto fapl = fileAccessProps.
getId();
81 if ((
_hid = H5Fcreate(filename.c_str(), createMode, fcpl, fapl)) < 0) {
87 if (_filename.empty()) {
88 _filename = details::get_name(
89 [
this](
char* buffer,
size_t length) {
return H5Fget_name(
getId(), buffer, length); });
102 return fileVer.getVersion();
105#if H5_VERSION_GE(1, 10, 1)
106inline H5F_fspace_strategy_t File::getFileSpaceStrategy()
const {
108 FileSpaceStrategy spaceStrategy(fcpl);
109 return spaceStrategy.getStrategy();
112inline hsize_t File::getFileSpacePageSize()
const {
115 if (getFileSpaceStrategy() != H5F_FSPACE_STRATEGY_PAGE) {
117 std::string(
"Cannot obtain page size as paged allocation is not used."));
120 return FileSpacePageSize(fcpl).getPageSize();
125 if (H5Fflush(
_hid, H5F_SCOPE_GLOBAL) < 0) {
File class.
Definition H5File.hpp:24
FileCreateProps getCreatePropertyList() const
Get the list of properties for creation of this file.
Definition H5File.hpp:104
std::pair< H5F_libver_t, H5F_libver_t > getVersionBounds() const
Returns the HDF5 version compatibility bounds.
Definition H5File_misc.hpp:99
void flush()
flush
Definition H5File_misc.hpp:124
FileAccessProps getAccessPropertyList() const
Get the list of properties for accession of this file.
Definition H5File.hpp:109
hsize_t getMetadataBlockSize() const
Returns the block size for metadata in bytes.
Definition H5File_misc.hpp:94
@ Truncate
Open flag: Truncate a file if already existing.
Definition H5File.hpp:34
@ Create
Open flag: Create non existing file.
Definition H5File.hpp:40
@ ReadOnly
Open flag: Read only access.
Definition H5File.hpp:30
@ ReadWrite
Open flag: Read Write access.
Definition H5File.hpp:32
@ Excl
Open flag: Open will fail if file already exist.
Definition H5File.hpp:36
const std::string & getName() const noexcept
Return the name of the file.
Definition H5File_misc.hpp:86
Configure the version bounds for the file.
Definition H5PropertyList.hpp:246
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:65
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:61
hid_t _hid
Definition H5Object.hpp:105
HDF5 property Lists.
Definition H5PropertyList.hpp:79
Utility class to disable HDF5 stack printing inside a scope.
Definition H5Utility.hpp:24
Definition H5_definitions.hpp:15
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:42