Allow TempDir::remove()

This commit is contained in:
Sebastian Messmer 2015-10-29 15:51:16 +01:00
parent 62fcd1a3fd
commit cc99cb0ea5
3 changed files with 15 additions and 6 deletions

View File

@ -5,12 +5,19 @@ namespace bf = boost::filesystem;
namespace cpputils {
TempDir::TempDir()
: _path(bf::unique_path(bf::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%")) {
: _path(bf::unique_path(bf::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%")), _existing(true) {
bf::create_directory(_path);
}
TempDir::~TempDir() {
remove();
}
void TempDir::remove() {
if (_existing) {
bf::remove_all(_path);
_existing = false;
}
}
const bf::path &TempDir::path() const {

View File

@ -7,14 +7,16 @@
namespace cpputils {
class TempDir {
class TempDir final {
public:
TempDir();
virtual ~TempDir();
~TempDir();
const boost::filesystem::path &path() const;
void remove();
private:
const boost::filesystem::path _path;
bool _existing;
DISALLOW_COPY_AND_ASSIGN(TempDir);
};

View File

@ -7,11 +7,11 @@
namespace cpputils {
class TempFile {
class TempFile final {
public:
explicit TempFile(const boost::filesystem::path &path, bool create = true);
explicit TempFile(bool create = true);
virtual ~TempFile();
~TempFile();
const boost::filesystem::path &path() const;
//TODO Test exists()
bool exists() const;