![]() |
Arene Base
Fundamental Utilities For Safety Critical C++
|
An RAII wrapper around a POSIX file handle with unique-ownership semantics. More...
Public Member Functions | |
| file_handle () noexcept | |
| Default construct with an invalid value. | |
| file_handle (file_handle &&other) noexcept | |
Transfer ownership of the handle from other to *this. | |
| file_handle (file_handle const &)=delete | |
| Not copyable. | |
| file_handle (os_file_handle const file_descriptor) noexcept | |
| Take ownership of the specified handle. | |
| ~file_handle () | |
| Close the handle if there is one. | |
| auto | close () noexcept -> result< void, error_code > |
| Close the file handle, if there is one. | |
| auto | flush () const noexcept -> result< void, error_code > |
| Flush the file handle. | |
| auto | get_fd () const noexcept -> os_file_handle |
| Get the wrapped handle. | |
| auto | operator= (file_handle &&other) noexcept -> file_handle & |
Take ownership of the file handle from other. | |
| auto | operator= (file_handle const &) -> file_handle &=delete |
| Not copyable. | |
| 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. | |
| void | release () noexcept |
| Release ownership of the handle, if held. | |
| 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 buffer. Updates the sequential access position to the end of the read data. | |
| 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. | |
| 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 sequential access position. Updates the sequential access position to the end of the written data. | |
| auto | size () const noexcept -> result< std::uint64_t, error_code > |
| Get the size of the open file. | |
| auto | valid () const noexcept -> bool |
| Check if the handle currently holds a file descriptor. | |
| 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 position in the file. | |
Static Public Attributes | |
| static constexpr os_file_handle | invalid_handle_value {-1} |
| An invalid handle value. | |
An RAII wrapper around a POSIX file handle with unique-ownership semantics.
|
inlinenoexcept |
Default construct with an invalid value.
get_fd() == invalid_handle_value
|
inlineexplicitnoexcept |
Take ownership of the specified handle.
| file_descriptor | The file handle to own |
get_fd() == file_description | arene::base::filesystem::file_handle::~file_handle | ( | ) |
Close the handle if there is one.
valid() == true , the file descriptor will be closed using underlying OS mechanisms.
|
inlinenoexcept |
Transfer ownership of the handle from other to *this.
| other | the other file_handle to take ownership from |
|
delete |
Not copyable.
|
noexcept |
Close the file handle, if there is one.
result that is either:error_code indicating the reason for failure if the handle could not be closed.
|
noexcept |
Flush the file handle.
result that is either:error_code indicating the reason for failure if the flush failed.
|
inlinenoexcept |
Get the wrapped handle.
|
inlinenoexcept |
Take ownership of the file handle from other.
| other | the other file_handle to take ownership from |
*this *this held a file handle before assignment, it is closed. get_fd() will return the value previously held by other
|
delete |
Not copyable.
|
noexcept |
Read from the file handle, starting at the specified position, into the provided buffer.
| buffer | A view onto a buffer to write the read bytes into into. The read will never be larger then the provided span. |
| position | The position in the file to read from |
result holding either:buffer that is a view onto to the actual data read.error_code indicating the reason for failure to read.
|
inlinenoexcept |
Release ownership of the handle, if held.
get_fd() == invalid_handle_value .
|
noexcept |
Read from the file handle, starting at the current sequential access position, into the provided buffer. Updates the sequential access position to the end of the read data.
| buffer | The buffer to read into. The read will never be larger then the provided buffer. |
result holding either:buffer that is a view onto to the actual data read.error_code indicating the reason for failure to read.
|
noexcept |
Move the sequential access position to the specified offset from the start of the file.
| position | The position in the file to use for subsequent sequential access |
result that is either:error_code indicating the reason for failure if the seek failed.
|
noexcept |
Write data from the provided buffer to the file referenced by the handle, starting at the current sequential access position. Updates the sequential access position to the end of the written data.
| data | The data to write |
result holding either:data that refers to the remaining unwritten data for a successful write, if any. If all data was written, this span will be empty.error_code indicating the reason for failure to write.
|
noexcept |
Get the size of the open file.
result holding the file size on success, or an error_code indicating the reason for failure.
|
inlinenoexcept |
Check if the handle currently holds a file descriptor.
get_fd() != invalid_handle_value .
|
noexcept |
Write data from the provided buffer to the file referenced by the handle, starting at the specified position in the file.
| data | The data to write |
| position | The position in the file to write at |
result holding either:data that refers to the remaining unwritten data for a successful write, if any. If all data was written, this span will be empty.error_code indicating the reason for failure to write.
|
staticconstexpr |
An invalid handle value.