5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_FILESYSTEM_FILE_HANDLE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_FILESYSTEM_FILE_HANDLE_HPP_
29 using os_file_handle = int;
46 explicit file_handle(os_file_handle
const file_descriptor) noexcept
47 : fd_(file_descriptor) {}
78 auto get_fd() const noexcept -> os_file_handle {
return fd_; }
Public export header for the byte subpackage.
A class representing a filesystem error value. Intended to be a wrapper around errno.
Definition error_code.hpp:33
auto operator=(file_handle const &) -> file_handle &=delete
Not copyable.
static constexpr os_file_handle invalid_handle_value
An invalid handle value.
Definition file_handle.hpp:35
auto write_at(span< byte const > data, std::uint64_t const position) const noexcept -> result< span< byte const >, error_code >
Write data from the provided buffer to the file referenced by the handle, starting at the specified p...
Definition file_handle.cpp:64
auto get_fd() const noexcept -> os_file_handle
Get the wrapped handle.
Definition file_handle.hpp:78
auto valid() const noexcept -> bool
Check if the handle currently holds a file descriptor.
Definition file_handle.hpp:87
~file_handle()
Close the handle if there is one.
Definition file_handle.cpp:41
auto sequential_write(span< byte const > data) const noexcept -> result< span< byte const >, error_code >
Write data from the provided buffer to the file referenced by the handle, starting at the current seq...
Definition file_handle.cpp:120
file_handle(os_file_handle const file_descriptor) noexcept
Take ownership of the specified handle.
Definition file_handle.hpp:46
void release() noexcept
Release ownership of the handle, if held.
Definition file_handle.hpp:82
auto sequential_read(span< byte > buffer) const noexcept -> result< span< byte >, error_code >
Read from the file handle, starting at the current sequential access position, into the provided buff...
Definition file_handle.cpp:134
auto operator=(file_handle &&other) noexcept -> file_handle &
Take ownership of the file handle from other.
Definition file_handle.hpp:63
auto sequential_seek(std::uint64_t const position) const noexcept -> result< void, error_code >
Move the sequential access position to the specified offset from the start of the file.
Definition file_handle.cpp:148
auto read_at(span< byte > buffer, std::uint64_t const position) const noexcept -> result< span< byte >, error_code >
Read from the file handle, starting at the specified position, into the provided buffer.
Definition file_handle.cpp:46
file_handle(file_handle &&other) noexcept
Transfer ownership of the handle from other to *this.
Definition file_handle.hpp:55
file_handle(file_handle const &)=delete
Not copyable.
auto close() noexcept -> result< void, error_code >
Close the file handle, if there is one.
Definition file_handle.cpp:94
auto flush() const noexcept -> result< void, error_code >
Flush the file handle.
Definition file_handle.cpp:82
file_handle() noexcept
Default construct with an invalid value.
Definition file_handle.hpp:40
A sum type which can hold either a value or an error. Similar to std::expected.
Definition result.hpp:104
A backport of std::span for C++14. Provides a view over a contiguous range of elements of type T.
Definition span.hpp:315
Definition directory_handle.cpp:39
Definition accumulate.hpp:37
constexpr std::integral_constant< std::size_t, N > array< T, N >::size
Definition array.hpp:534
::std::uint64_t uint64_t
A 64-bit unsigned integer type.
Definition integer_types.hpp:46
Definition accumulate.hpp:36
void swap(pair< T1, T2 > &lhs, pair< T1, T2 > &rhs) noexcept(arene::base::is_nothrow_swappable_v< T1 > &&arene::base::is_nothrow_swappable_v< T2 >)
Swap a pair with another instance of the same type. Swaps lhs.first with rhs.first and swaps lhs....
Definition pair.hpp:448
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
constexpr auto exchange(T &target, U &&source) noexcept(is_nothrow_move_constructible_v< T > &&is_nothrow_assignable_v< T &, U && >) -> T
Assign a new value to an object and return the old value. Implements std::exchange.
Definition exchange.hpp:33
::uint64_t uint64_t
A 64-bit unsigned integer type.
Definition cstdint.hpp:47
Public export header for the result subpackage.
Public export header for span.hpp.