HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions
hi::v1::file Class Reference

#include <hikogui/file/file_intf.hpp>

Public Member Functions

 file (file const &other) noexcept=default
 
 file (file &&other) noexcept=default
 
fileoperator= (file const &other) noexcept=default
 
fileoperator= (file &&other) noexcept=default
 
 file (std::filesystem::path const &path, access_mode access_mode=access_mode::open_for_read)
 Open a file at location.
 
hi::access_mode access_mode () const noexcept
 
std::shared_ptr< detail::file_implpimpl () const noexcept
 
void close ()
 Close the file.
 
void flush ()
 Flush and block until all data is physically written to disk.
 
void rename (std::filesystem::path const &destination, bool overwrite_existing=true)
 Rename an open file.
 
std::size_t size () const
 Return the size of the file.
 
std::size_t seek (std::ptrdiff_t offset, seek_whence whence=seek_whence::begin)
 Set the seek location.
 
std::size_t get_seek ()
 Get the current seek location.
 
void write (void const *data, std::size_t size)
 Write data to a file.
 
std::size_t read (void *data, std::size_t size)
 Read data from a file.
 
void write (std::span< std::byte const > bytes)
 Write data to a file.
 
void write (bstring_view text)
 Write data to a file.
 
void write (bstring const &text)
 Write data to a file.
 
void write (std::string_view text)
 Write data to a file.
 
bstring read_bstring (std::size_t max_size=10 '000 '000)
 Read bytes from the file.
 
std::string read_string (std::size_t max_size=10 '000 '000)
 Read a UTF-8 string from the file.
 

Detailed Description

A File object.

Constructor & Destructor Documentation

◆ file()

hi::v1::file::file ( std::filesystem::path const & path,
access_mode access_mode = access_mode::open_for_read )
inline

Open a file at location.

Parameters
pathThe path to the file to open.
access_modeaccess-mode to open the file.

Member Function Documentation

◆ close()

void hi::v1::file::close ( )
inline

Close the file.

◆ flush()

void hi::v1::file::flush ( )
inline

Flush and block until all data is physically written to disk.

Flushing is required before renaming a file, to prevent data corruption when the computer crashes during the rename.

◆ get_seek()

std::size_t hi::v1::file::get_seek ( )
inline

Get the current seek location.

◆ read()

std::size_t hi::v1::file::read ( void * data,
std::size_t size )
inline

Read data from a file.

Parameters
dataPointer to a buffer to read into.
sizeThe number of bytes to read.
Returns
The number of bytes read.
Exceptions
io_error

◆ read_bstring()

bstring hi::v1::file::read_bstring ( std::size_t max_size = 10'000'000)
inline

Read bytes from the file.

Parameters
max_sizeThe maximum number of bytes to read.
Returns
Data as a byte string, may return less then the requested size.
Exceptions
io_errorOn IO error.

◆ read_string()

std::string hi::v1::file::read_string ( std::size_t max_size = 10'000'000)
inline

Read a UTF-8 string from the file.

Because of complications with reading UTF-8 string with sequences it is only allowed to read from the start of the file.

Note
It is undefined bahavior when the seek pointer is not zero.
Parameters
max_sizeThe maximum number of bytes to read.
Returns
Data as a UTF-8 string, may return less then the requested size.
Exceptions
io_errorOn IO error.

◆ rename()

void hi::v1::file::rename ( std::filesystem::path const & destination,
bool overwrite_existing = true )
inline

Rename an open file.

This function will rename an open file atomically.

Parameters
destinationThe destination file name.
overwrite_existingOverwrite an existing file.
Exceptions
io_errorWhen failing to rename.

◆ seek()

std::size_t hi::v1::file::seek ( std::ptrdiff_t offset,
seek_whence whence = seek_whence::begin )
inline

Set the seek location.

Parameters
offsetTo move the file pointer.
whenceWhere to seek from: begin, current or end
Returns
The new seek position relative to the beginning of the file.

◆ size()

std::size_t hi::v1::file::size ( ) const
inline

Return the size of the file.

◆ write() [1/5]

void hi::v1::file::write ( bstring const & text)
inline

Write data to a file.

Parameters
textThe byte string to write
Exceptions
io_error

◆ write() [2/5]

void hi::v1::file::write ( bstring_view text)
inline

Write data to a file.

Parameters
textThe byte string to write
Exceptions
io_error

◆ write() [3/5]

void hi::v1::file::write ( std::span< std::byte const > bytes)
inline

Write data to a file.

Parameters
bytesThe byte string to write
Exceptions
io_error

◆ write() [4/5]

void hi::v1::file::write ( std::string_view text)
inline

Write data to a file.

Parameters
textThe UTF-8 string to write
Exceptions
io_error

◆ write() [5/5]

void hi::v1::file::write ( void const * data,
std::size_t size )
inline

Write data to a file.

Parameters
dataPointer to data to be written.
sizeThe number of bytes to write.
Exceptions
io_error

The documentation for this class was generated from the following file: