Version: SMASH-1.8
file.cc
Go to the documentation of this file.
1
/*
2
*
3
* Copyright (c) 2018
4
* SMASH Team
5
*
6
* GNU General Public License (GPLv3 or later)
7
*
8
*/
9
10
#include "
smash/file.h
"
11
12
namespace
smash
{
13
14
FilePtr
fopen
(
const
bf::path& filename,
const
std::string& mode) {
15
FilePtr
f{
std::fopen
(filename.c_str(), mode.c_str())};
16
return
f;
17
}
18
19
RenamingFilePtr::RenamingFilePtr
(
const
bf::path& filename,
20
const
std::string& mode) {
21
filename_
= filename;
22
filename_unfinished_
= filename;
23
filename_unfinished_
+=
".unfinished"
;
24
file_
=
std::fopen
(
filename_unfinished_
.c_str(), mode.c_str());
25
}
26
27
FILE*
RenamingFilePtr::get
() {
return
file_
; }
28
29
RenamingFilePtr::~RenamingFilePtr
() {
30
std::fclose(
file_
);
31
bf::rename(
filename_unfinished_
,
filename_
);
32
}
33
34
}
// namespace smash
smash
Definition:
action.h:24
smash::FilePtr
std::unique_ptr< std::FILE, FileDeleter > FilePtr
A RAII type to replace std::FILE *.
Definition:
file.h:63
smash::fopen
FilePtr fopen(const bf::path &filename, const std::string &mode)
Open a file with given mode.
Definition:
file.cc:14
smash::RenamingFilePtr::~RenamingFilePtr
~RenamingFilePtr()
Close the file and rename it.
Definition:
file.cc:29
smash::RenamingFilePtr::get
FILE * get()
Get the underlying FILE* pointer.
Definition:
file.cc:27
smash::RenamingFilePtr::filename_unfinished_
bf::path filename_unfinished_
Path of the unfinished file.
Definition:
file.h:95
smash::RenamingFilePtr::filename_
bf::path filename_
Path of the finished file.
Definition:
file.h:93
smash::RenamingFilePtr::file_
FILE * file_
Internal file pointer.
Definition:
file.h:91
file.h
smash::RenamingFilePtr::RenamingFilePtr
RenamingFilePtr(const bf::path &filename, const std::string &mode)
Construct a RenamingFilePtr.
Definition:
file.cc:19
src
file.cc
Impressum
Data privacy protection
Generated on Tue Apr 7 2020 13:50:08 for SMASH by
Doxygen
1.8.16