#include <file.h>
A RAII type to replace std::FILE *
.
While open, the file name ends with ".unfinished".
Automatically closes and renames the file to the original when it goes out of scope. If the object is destroyed because of stack unwinding, no renaming is done.
Public Member Functions | |
RenamingFilePtr (const std::filesystem::path &filename, const std::string &mode) | |
Construct a RenamingFilePtr . More... | |
FILE * | get () |
Get the underlying FILE* pointer. More... | |
~RenamingFilePtr () | |
Close the file and rename it. More... | |
Private Attributes | |
FILE * | file_ |
Internal file pointer. More... | |
std::filesystem::path | filename_ |
Path of the finished file. More... | |
std::filesystem::path | filename_unfinished_ |
Path of the unfinished file. More... | |
int | uncaught_exceptions_ {std::uncaught_exceptions()} |
Number of uncaught exceptions at the time when the object is created. More... | |
smash::RenamingFilePtr::RenamingFilePtr | ( | const std::filesystem::path & | filename, |
const std::string & | mode | ||
) |
Construct a RenamingFilePtr
.
[in] | filename | Path to the file. |
[in] | mode | The mode in which the file should be opened (see std::fopen ). |
Definition at line 19 of file file.cc.
smash::RenamingFilePtr::~RenamingFilePtr | ( | ) |
Close the file and rename it.
Definition at line 29 of file file.cc.
FILE * smash::RenamingFilePtr::get | ( | ) |
|
private |
|
private |
|
private |
|
private |
Number of uncaught exceptions at the time when the object is created.
If it has not changed when the object is destroyed, we suppose that the contents of the file are reliable and in the destructor we can safely rename the file and remove the _.unfinished_ suffix.