2015-04-25 02:40:02 +02:00
|
|
|
#include "TempFile.h"
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
using std::ofstream;
|
|
|
|
|
|
|
|
namespace cpputils {
|
|
|
|
|
|
|
|
TempFile::TempFile(const bf::path &path, bool create)
|
|
|
|
: _path(path) {
|
|
|
|
if (create) {
|
|
|
|
ofstream file(_path.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TempFile::TempFile(bool create)
|
|
|
|
: TempFile(bf::unique_path(bf::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%"), create) {
|
|
|
|
}
|
|
|
|
|
|
|
|
TempFile::~TempFile() {
|
2015-10-23 12:15:51 +02:00
|
|
|
if (exists()) {
|
2015-04-25 02:40:02 +02:00
|
|
|
bf::remove(_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 12:15:51 +02:00
|
|
|
bool TempFile::exists() const {
|
|
|
|
return bf::exists(_path);
|
|
|
|
}
|
|
|
|
|
2015-04-25 02:40:02 +02:00
|
|
|
const bf::path &TempFile::path() const {
|
|
|
|
return _path;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|