11#include "../byte_string.hpp"
20namespace hi {
inline namespace v1 {
58 return static_cast<access_mode>(to_underlying(lhs) | to_underlying(rhs));
63 return static_cast<access_mode>(to_underlying(lhs) & to_underlying(rhs));
66[[nodiscard]]
constexpr bool to_bool(
access_mode const& rhs)
noexcept
68 return to_bool(to_underlying(rhs));
88 [[nodiscard]]
virtual bool closed() = 0;
89 virtual void close() = 0;
90 virtual void flush() = 0;
91 virtual void rename(std::filesystem::path
const& destination,
bool overwrite_existing) = 0;
122 return _pimpl->access_mode();
129 return _pimpl->close();
138 return _pimpl->flush();
148 void rename(std::filesystem::path
const& destination,
bool overwrite_existing =
true)
150 return _pimpl->rename(destination, overwrite_existing);
157 return _pimpl->size();
167 return _pimpl->seek(offset, whence);
185 return _pimpl->write(data,
size);
197 return _pimpl->read(data,
size);
205 void write(std::span<std::byte const> bytes)
207 return write(bytes.data(), ssize(bytes));
217 return write(text.data(), ssize(text));
227 return write(text.data(), ssize(text));
237 return write(text.data(), ssize(text));
254 hilet bytes_read =
read(r.data(), size_);
255 r.resize(bytes_read);
274 if (size_ > max_size) {
275 throw io_error(
"read_string() requires the file size to be smaler than max_size.");
281 hilet bytes_read =
read(r.data(), size_);
282 r.resize(bytes_read);
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:87
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
seek_whence
The position in the file to seek from.
Definition file.hpp:25
access_mode
The mode in which way to open a file.
Definition file.hpp:36
@ 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:15
geometry/margins.hpp
Definition assert.hpp:18
Exception thrown during I/O on an error.
Definition exception.hpp:85
A File object.
Definition file.hpp:106
void rename(std::filesystem::path const &destination, bool overwrite_existing=true)
Rename an open file.
Definition file.hpp:148
std::size_t read(void *data, std::size_t size)
Read data from a file.
Definition file.hpp:195
std::size_t get_seek()
Get the current seek location.
Definition file.hpp:172
std::string read_string(std::size_t max_size=10 '000 '000)
Read a UTF-8 string from the file.
Definition file.hpp:269
std::size_t seek(std::ptrdiff_t offset, seek_whence whence=seek_whence::begin)
Set the seek location.
Definition file.hpp:165
void write(bstring const &text)
Write data to a file.
Definition file.hpp:225
void write(std::span< std::byte const > bytes)
Write data to a file.
Definition file.hpp:205
void close()
Close the file.
Definition file.hpp:127
std::size_t size() const
Return the size of the file.
Definition file.hpp:155
void flush()
Flush and block until all data is physically written to disk.
Definition file.hpp:136
void write(bstring_view text)
Write data to a file.
Definition file.hpp:215
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:246
void write(std::string_view text)
Write data to a file.
Definition file.hpp:235
void write(void const *data, std::size_t size)
Write data to a file.
Definition file.hpp:183
Map a file into virtual memory.
Definition file_view.hpp:97