10#define H5FILE_MISC_HPP
16#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;
41inline File::File(
const std::string& filename,
unsigned openFlags,
44 openFlags = convert_open_flag(openFlags);
46 unsigned createMode = openFlags & (H5F_ACC_TRUNC | H5F_ACC_EXCL);
47 unsigned openMode = openFlags & (H5F_ACC_RDWR | H5F_ACC_RDONLY);
48 bool mustCreate = createMode > 0;
49 bool openOrCreate = (openFlags & H5F_ACC_CREAT) > 0;
55 std::unique_ptr<SilenceHDF5> silencer;
56 if (openOrCreate) silencer.reset(
new SilenceHDF5());
58 _hid = H5Fopen(filename.c_str(), openMode, fileAccessProps.getId(
false));
64 createMode = H5F_ACC_EXCL;
66 HDF5ErrMapper::ToException<FileException>(
67 std::string(
"Unable to open file " + filename));
71 if ((_hid = H5Fcreate(filename.c_str(), createMode, H5P_DEFAULT,
72 fileAccessProps.getId(
false))) < 0) {
73 HDF5ErrMapper::ToException<FileException>(
74 std::string(
"Unable to create file " + filename +
75 ". Probably you don't have permissions, incorrect directory or the file is busy by another process"));
79inline bool File::operator==(
const File& other)
const {
80#if (H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 12)
81 unsigned long fileNumLeft, fileNumRight;
83 if (H5Fget_fileno(_hid, &fileNumLeft) < 0){
84 HDF5ErrMapper::ToException<FileException>(
85 std::string(
"Unable to get file number for " + getFileName()));
88 if (H5Fget_fileno(other.
getId(
false), &fileNumRight) < 0){
89 HDF5ErrMapper::ToException<FileException>(
90 std::string(
"Unable to get file number for " + other.getFileName()));
92 return fileNumLeft == fileNumRight;
98inline bool File::operator!=(
const File& other)
const {
99 return !(*
this == other);
Definition H5PropertyList.hpp:152
File class.
Definition H5File.hpp:25
@ Truncate
Open flag: Truncate a file if already existing.
Definition H5File.hpp:41
@ Excl
Open flag: Open will fail if file already exist.
Definition H5File.hpp:43
@ ReadWrite
Open flag: Read Write access.
Definition H5File.hpp:39
@ ReadOnly
Open flag: Read only access.
Definition H5File.hpp:37
@ Create
Open flag: Create non existing file.
Definition H5File.hpp:47
ObjectInfo getObjectInfo() const
Retrieve several infos about the current object (address, dates, etc)
Definition H5Object_misc.hpp:204
hid_t getId(const bool &increaseRefCount=false) const noexcept
getId
Definition H5Object_misc.hpp:172
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:162
Utility class to disable HDF5 stack printing inside a scope.
Definition H5Utility.hpp:20