25inline unsigned convert_open_flag(
unsigned openFlags) {
26 unsigned res_open = 0;
28 res_open |= H5F_ACC_RDONLY;
30 res_open |= H5F_ACC_RDWR;
32 res_open |= H5F_ACC_CREAT;
34 res_open |= H5F_ACC_TRUNC;
36 res_open |= H5F_ACC_EXCL;
51 openFlags = convert_open_flag(openFlags);
53 unsigned createMode = openFlags & (H5F_ACC_TRUNC | H5F_ACC_EXCL);
54 unsigned openMode = openFlags & (H5F_ACC_RDWR | H5F_ACC_RDONLY);
55 bool mustCreate = createMode > 0;
56 bool openOrCreate = (openFlags & H5F_ACC_CREAT) > 0;
62 std::unique_ptr<SilenceHDF5> silencer;
66 _hid = detail::nothrow::h5f_open(filename.c_str(), openMode, fileAccessProps.
getId());
73 createMode = H5F_ACC_EXCL;
76 std::string(
"Unable to open file " + filename));
80 auto fcpl = fileCreateProps.
getId();
81 auto fapl = fileAccessProps.
getId();
82 _hid = detail::h5f_create(filename.c_str(), createMode, fcpl, fapl);
86 if (_filename.empty()) {
87 _filename = details::get_name([
this](
char* buffer,
size_t length) {
88 return detail::h5f_get_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 detail::h5f_flush(
_hid, H5F_SCOPE_GLOBAL);
129 hsize_t sizeValue = 0;
130 detail::h5f_get_filesize(
_hid, &sizeValue);
131 return static_cast<size_t>(sizeValue);
135 return static_cast<size_t>(detail::h5f_get_freespace(
_hid));
File class.
Definition H5File.hpp:24
FileCreateProps getCreatePropertyList() const
Get the list of properties for creation of this file.
Definition H5File.hpp:104
size_t getFileSize() const
Get the size of this file in bytes.
Definition H5File_misc.hpp:128
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
size_t getFreeSpace() const
Get the amount of tracked, unused space in bytes.
Definition H5File_misc.hpp:134
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:85
Configure the version bounds for the file.
Definition H5PropertyList.hpp:342
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:69
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:65
hid_t _hid
Definition H5Object.hpp:105
HDF5 property Lists.
Definition H5PropertyList.hpp:160
Utility class to disable HDF5 stack printing inside a scope.
Definition H5Utility.hpp:24
Definition H5_definitions.hpp:22
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:43