OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::FileWriter Class Reference

Streaming writer that finalises by atomic-renaming a .tmp file to its final path. More...

#include <io_utilities.h>

Public Member Functions

 FileWriter ()=default
 
 ~FileWriter ()
 
 FileWriter (const FileWriter &)=delete
 
FileWriteroperator= (const FileWriter &)=delete
 
 FileWriter (FileWriter &&)=delete
 
FileWriteroperator= (FileWriter &&)=delete
 
void open (const filesystem::path &tmp_path)
 Opens a temporary file to which subsequent write() calls are appended.
 
bool is_open () const
 Returns true while the underlying stream is open.
 
void write (const void *buffer, size_t bytes)
 Appends the given byte range to the open file.
 
void finish_with_rename (const filesystem::path &final_path)
 Closes the stream and atomically renames the tmp file to final_path.
 
void abort ()
 Closes and deletes the tmp file, discarding any written data.
 

Detailed Description

Streaming writer that finalises by atomic-renaming a .tmp file to its final path.

Constructor & Destructor Documentation

◆ FileWriter() [1/3]

opennn::FileWriter::FileWriter ( )
default

◆ ~FileWriter()

opennn::FileWriter::~FileWriter ( )

◆ FileWriter() [2/3]

opennn::FileWriter::FileWriter ( const FileWriter & )
delete

◆ FileWriter() [3/3]

opennn::FileWriter::FileWriter ( FileWriter && )
delete

Member Function Documentation

◆ abort()

void opennn::FileWriter::abort ( )

Closes and deletes the tmp file, discarding any written data.

◆ finish_with_rename()

void opennn::FileWriter::finish_with_rename ( const filesystem::path & final_path)

Closes the stream and atomically renames the tmp file to final_path.

◆ is_open()

bool opennn::FileWriter::is_open ( ) const
nodiscard

Returns true while the underlying stream is open.

◆ open()

void opennn::FileWriter::open ( const filesystem::path & tmp_path)

Opens a temporary file to which subsequent write() calls are appended.

◆ operator=() [1/2]

FileWriter & opennn::FileWriter::operator= ( const FileWriter & )
delete

◆ operator=() [2/2]

FileWriter & opennn::FileWriter::operator= ( FileWriter && )
delete

◆ write()

void opennn::FileWriter::write ( const void * buffer,
size_t bytes )

Appends the given byte range to the open file.