7#include "byte_string.hpp"
16namespace hi::inline
v1 {
18enum class seek_whence {
begin, current,
end };
40[[nodiscard]]
constexpr access_mode operator|(access_mode
const& lhs, access_mode
const& rhs)
noexcept
42 return static_cast<access_mode
>(to_underlying(lhs) | to_underlying(rhs));
45[[nodiscard]]
constexpr access_mode operator&(access_mode
const& lhs, access_mode
const& rhs)
noexcept
47 return static_cast<access_mode>(to_underlying(lhs) & to_underlying(rhs));
50bool operator>=(access_mode
const& lhs, access_mode
const& rhs) =
delete;
52[[nodiscard]]
constexpr bool any(access_mode
const& rhs)
noexcept
54 return to_bool(to_underlying(rhs));
61 return (lhs & rhs) == rhs;
78 file& operator=(
file const& other) = delete;
79 file& operator=(
file&& other) = delete;
98 void rename(
std::filesystem::path const& destination,
bool overwrite_existing = true);
109 std::
size_t seek(ssize_t offset, seek_whence whence = seek_whence::begin);
115 return seek(0, seek_whence::current);
137 return write(bytes.data(), ssize(bytes), offset);
227 static void create_directory(std::filesystem::path
const& path,
bool hierarchy =
false);
229 static void create_directory_hierarchy(std::filesystem::path
const& path);
238 std::filesystem::path _path;
242 file_handle _file_handle;
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
DOXYGEN BUG.
Definition algorithm.hpp:15
access_mode
Definition file.hpp:20
@ 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.
@ 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.
A File object.
Definition file.hpp:66
std::u8string read_u8string(std::size_t max_size=10 '000 '000)
Read the whole file as a UTF-8 string.
bstring read_bstring(std::size_t size=10 '000 '000, ssize_t offset=-1)
Read bytes from the file.
std::string read_string(std::size_t max_size=10 '000 '000)
Read the whole file as a UTF-8 string.
file(std::filesystem::path const &path, access_mode access_mode=access_mode::open_for_read)
Open a file at location.
ssize_t write(std::span< std::byte const > bytes, std::size_t offset=-1)
Write data to a file.
Definition file.hpp:135
std::size_t write(void const *data, std::size_t size, ssize_t offset=-1)
Write data to a file.
ssize_t read(void *data, std::size_t size, ssize_t offset=-1)
Read data from a file.
static std::size_t file_size(std::filesystem::path const &path)
Get the size of a file on the file system.
ssize_t write(bstring_view text, ssize_t offset=-1)
Write data to a file.
Definition file.hpp:147
ssize_t write(std::string_view text)
Write data to a file.
Definition file.hpp:170
ssize_t write(bstring const &text, ssize_t offset=-1)
Write data to a file.
Definition file.hpp:159
Definition file_mapping.hpp:19
Definition file_view.hpp:22
A variant of text.
Definition label.hpp:37