HighFive 3.0.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5File.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3 *
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 *
8 */
9#pragma once
10
11#include <string>
12#include <type_traits>
13
14#include "H5Object.hpp"
15#include "H5PropertyList.hpp"
18
19namespace HighFive {
20
21
25class File: public Object, public NodeTraits<File>, public AnnotateTraits<File> {
26 public:
28
29 enum class AccessMode {
30 None = 0x00u,
32 ReadOnly = 0x01u,
34 ReadWrite = 0x02u,
36 Truncate = 0x04u,
38 Excl = 0x08u,
40 Debug = 0x10u,
42 Create = 0x20u,
47 };
48
52 constexpr static AccessMode Excl = AccessMode::Excl;
57
65 explicit File(const std::string& filename,
66 AccessMode openFlags = ReadOnly,
67 const FileAccessProps& fileAccessProps = FileAccessProps::Default());
68
77 File(const std::string& filename,
78 AccessMode openFlags,
79 const FileCreateProps& fileCreateProps,
80 const FileAccessProps& fileAccessProps = FileAccessProps::Default());
81
85 const std::string& getName() const;
86
87
89 std::string getPath() const noexcept {
90 return "/";
91 }
92
94 hsize_t getMetadataBlockSize() const;
95
97 std::pair<H5F_libver_t, H5F_libver_t> getVersionBounds() const;
98
99#if H5_VERSION_GE(1, 10, 1)
101 H5F_fspace_strategy_t getFileSpaceStrategy() const;
102
104 hsize_t getFileSpacePageSize() const;
105#endif
106
112 void flush();
113
116 return details::get_plist<FileCreateProps>(*this, H5Fget_create_plist);
117 }
118
121 return details::get_plist<FileAccessProps>(*this, H5Fget_access_plist);
122 }
123
125 size_t getFileSize() const;
126
133 size_t getFreeSpace() const;
134
135 protected:
136 File() = default;
137 using Object::Object;
138
139 private:
140 mutable std::string _filename{};
141
142 template <typename>
143 friend class PathTraits;
144};
145
147 using int_t = std::underlying_type<File::AccessMode>::type;
148 return static_cast<File::AccessMode>(static_cast<int_t>(lhs) | static_cast<int_t>(rhs));
149}
150
152 using int_t = std::underlying_type<File::AccessMode>::type;
153 return static_cast<File::AccessMode>(static_cast<int_t>(lhs) & static_cast<int_t>(rhs));
154}
155
157 using int_t = std::underlying_type<File::AccessMode>::type;
158 return static_cast<File::AccessMode>(static_cast<int_t>(lhs) ^ static_cast<int_t>(rhs));
159}
160
162 using int_t = std::underlying_type<File::AccessMode>::type;
163 return static_cast<File::AccessMode>(~static_cast<int_t>(mode));
164}
165
167 lhs = lhs | rhs;
168 return lhs;
169}
170
172 lhs = lhs & rhs;
173 return lhs;
174}
175
177 lhs = lhs ^ rhs;
178 return lhs;
179}
180
181inline bool any(File::AccessMode mode) {
182 return mode != File::AccessMode::None;
183}
184
185
186} // namespace HighFive
187
188// H5File is the main user constructible -> bring in implementation headers
190#include "bits/H5File_misc.hpp"
Definition H5Annotate_traits.hpp:18
File class.
Definition H5File.hpp:25
FileCreateProps getCreatePropertyList() const
Get the list of properties for creation of this file.
Definition H5File.hpp:115
size_t getFileSize() const
Get the size of this file in bytes.
Definition H5File_misc.hpp:128
static constexpr AccessMode Truncate
Definition H5File.hpp:51
static constexpr AccessMode Create
Definition H5File.hpp:54
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
static constexpr AccessMode ReadOnly
Definition H5File.hpp:49
size_t getFreeSpace() const
Get the amount of tracked, unused space in bytes.
Definition H5File_misc.hpp:134
AccessMode
Definition H5File.hpp:29
@ Excl
Open flag: Open will fail if file already exist.
@ ReadOnly
Open flag: Read only access.
@ OpenOrCreate
Derived open flag: Opens RW or exclusively creates.
@ Create
Open flag: Create non existing file.
@ ReadWrite
Open flag: Read Write access.
@ Debug
Open flag: Open in debug mode.
@ Truncate
Open flag: Truncate a file if already existing.
@ Overwrite
Derived open flag: common write mode (=ReadWrite|Create|Truncate)
FileAccessProps getAccessPropertyList() const
Get the list of properties for accession of this file.
Definition H5File.hpp:120
hsize_t getMetadataBlockSize() const
Returns the block size for metadata in bytes.
Definition H5File_misc.hpp:94
static constexpr AccessMode Excl
Definition H5File.hpp:52
File()=default
static const ObjectType type
Definition H5File.hpp:27
static constexpr AccessMode OpenOrCreate
Definition H5File.hpp:56
const std::string & getName() const
Return the name of the file.
Definition H5File_misc.hpp:85
static constexpr AccessMode ReadWrite
Definition H5File.hpp:50
static constexpr AccessMode Overwrite
Definition H5File.hpp:55
static constexpr AccessMode Debug
Definition H5File.hpp:53
std::string getPath() const noexcept
Object path of a File is always "/".
Definition H5File.hpp:89
NodeTraits: Base class for Group and File.
Definition H5Node_traits.hpp:28
Definition H5Object.hpp:35
Object()
Definition H5Object_misc.hpp:19
Definition H5Path_traits.hpp:16
HDF5 property Lists.
Definition H5PropertyList.hpp:158
static const PropertyList< T > & Default() noexcept
Return the Default property type object.
Definition H5PropertyList.hpp:176
Definition assert_compatible_spaces.hpp:15
File::AccessMode operator&=(File::AccessMode &lhs, File::AccessMode rhs)
Definition H5File.hpp:171
bool any(File::AccessMode mode)
Definition H5File.hpp:181
File::AccessMode operator^=(File::AccessMode &lhs, File::AccessMode rhs)
Definition H5File.hpp:176
File::AccessMode operator~(File::AccessMode mode)
Definition H5File.hpp:161
DataTypeClass operator|(DataTypeClass lhs, DataTypeClass rhs)
Definition H5DataType.hpp:46
DataTypeClass operator&(DataTypeClass lhs, DataTypeClass rhs)
Definition H5DataType.hpp:51
ObjectType
Enum of the types of objects (H5O api)
Definition H5Object.hpp:24
const File::AccessMode & operator|=(File::AccessMode &lhs, File::AccessMode rhs)
Definition H5File.hpp:166
File::AccessMode operator^(File::AccessMode lhs, File::AccessMode rhs)
Definition H5File.hpp:156