8#include "byte_string.hpp"
16namespace hi::inline v1 {
18enum class seek_whence {
begin, current,
end };
20enum class access_mode {
32 write_through = 0x8000,
33 create_directories = 0x10000,
35 open_for_read = open | read,
36 open_for_read_and_write = open | read | write,
37 truncate_or_create_for_write = create_directories | open | create | truncate | write
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));
59[[nodiscard]]
inline bool operator>=(access_mode lhs, access_mode rhs)
noexcept
61 return (lhs & rhs) == rhs;
72 file(
URL const& location, access_mode accessMode);
78 file& operator=(
file const& other) = delete;
79 file& operator=(
file&& other) = delete;
98 void rename(
URL 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);
149 return write(text.data(), ssize(text), offset);
161 return write(text.data(), ssize(text), offset);
172 return write(text.data(), ssize(text));
227 static void create_directory(
URL const& url,
bool hierarchy =
false);
229 static void create_directory_hierarchy(
URL const& url);
234 access_mode _access_mode;
242 file_handle _file_handle;
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
constexpr alignment operator|(horizontal_alignment lhs, vertical_alignment rhs) noexcept
Combine vertical and horizontal alignment.
Definition alignment.hpp:200
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.
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(URL const &url)
Get the size of a file on the file system.
file(URL const &location, access_mode accessMode)
Open a file at location.
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:21