11#include "../byte_string.hpp"
12#include "../utility/module.hpp"
19namespace hi {
inline namespace v1 {
57 return static_cast<access_mode>(to_underlying(lhs) | to_underlying(rhs));
62 return static_cast<access_mode>(to_underlying(lhs) & to_underlying(rhs));
65[[nodiscard]]
constexpr bool to_bool(
access_mode const& rhs)
noexcept
67 return to_bool(to_underlying(rhs));
87 [[nodiscard]]
virtual bool closed() = 0;
88 virtual void close() = 0;
89 virtual void flush() = 0;
90 virtual void rename(std::filesystem::path
const& destination,
bool overwrite_existing) = 0;
121 return _pimpl->access_mode();
128 return _pimpl->close();
137 return _pimpl->flush();
147 void rename(std::filesystem::path
const& destination,
bool overwrite_existing =
true)
149 return _pimpl->rename(destination, overwrite_existing);
156 return _pimpl->size();
166 return _pimpl->seek(offset, whence);
184 return _pimpl->write(data,
size);
196 return _pimpl->read(data,
size);
204 void write(std::span<std::byte const> bytes)
206 return write(bytes.data(), ssize(bytes));
216 return write(text.data(), ssize(text));
226 return write(text.data(), ssize(text));
236 return write(text.data(), ssize(text));
253 hilet bytes_read =
read(r.data(), size_);
254 r.resize(bytes_read);
273 if (size_ > max_size) {
274 throw io_error(
"read_string() requires the file size to be smaler than max_size.");
280 hilet bytes_read =
read(r.data(), size_);
281 r.resize(bytes_read);
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:184
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
seek_whence
The position in the file to seek from.
Definition file.hpp:24
access_mode
The mode in which way to open a file.
Definition file.hpp:35
@ current
Continue from the current position.
@ end
Start from the end of the file.
@ begin
Start from the beginning of the file.
@ truncate
After the file has been opened, truncate it.
@ read_lock
Lock the file for reading, i.e. shared-lock.
@ sequential
Hint that the data should be prefetched.
@ create
Create file if it does not exist, or fail.
@ open
Open file if it exist, or fail.
@ random
Hint the data should not be prefetched.
@ open_for_read_and_write
Default open a file for reading and writing.
@ open_for_read
Default open a file for reading.
@ write_through
Hint that writes should be send directly to disk.
@ write_lock
Lock the file for writing, i.e. exclusive-lock.
@ no_reuse
Hint that the data should not be cached.
@ rename
Allow renaming an open file.
@ read
Allow read access to a file.
@ write
Allow write access to a file.
@ create_directories
Create directory hierarchy, if the file could not be created.
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A File object.
Definition file.hpp:105
void rename(std::filesystem::path const &destination, bool overwrite_existing=true)
Rename an open file.
Definition file.hpp:147
std::size_t read(void *data, std::size_t size)
Read data from a file.
Definition file.hpp:194
std::size_t get_seek()
Get the current seek location.
Definition file.hpp:171
std::string read_string(std::size_t max_size=10 '000 '000)
Read a UTF-8 string from the file.
Definition file.hpp:268
std::size_t seek(std::ptrdiff_t offset, seek_whence whence=seek_whence::begin)
Set the seek location.
Definition file.hpp:164
void write(bstring const &text)
Write data to a file.
Definition file.hpp:224
void write(std::span< std::byte const > bytes)
Write data to a file.
Definition file.hpp:204
void close()
Close the file.
Definition file.hpp:126
std::size_t size() const
Return the size of the file.
Definition file.hpp:154
void flush()
Flush and block until all data is physically written to disk.
Definition file.hpp:135
void write(bstring_view text)
Write data to a file.
Definition file.hpp:214
file(std::filesystem::path const &path, access_mode access_mode=access_mode::open_for_read)
Open a file at location.
bstring read_bstring(std::size_t max_size=10 '000 '000)
Read bytes from the file.
Definition file.hpp:245
void write(std::string_view text)
Write data to a file.
Definition file.hpp:234
void write(void const *data, std::size_t size)
Write data to a file.
Definition file.hpp:182
Map a file into virtual memory.
Definition file_view.hpp:97
Exception thrown during I/O on an error.
Definition exception.hpp:174