| 1 |
// file : cutl/fs/auto-remove.hxx |
| 2 |
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC |
| 3 |
// license : MIT; see accompanying LICENSE file |
| 4 |
|
| 5 |
#ifndef CUTL_FS_AUTO_REMOVE_HXX |
| 6 |
#define CUTL_FS_AUTO_REMOVE_HXX |
| 7 |
|
| 8 |
#include <vector> |
| 9 |
|
| 10 |
#include <cutl/fs/path.hxx> |
| 11 |
#include <cutl/fs/exception.hxx> |
| 12 |
|
| 13 |
#include <cutl/details/export.hxx> |
| 14 |
|
| 15 |
namespace cutl |
| 16 |
{ |
| 17 |
namespace fs |
| 18 |
{ |
| 19 |
// Remove a file or an empty directory on destruction unless canceled. |
| 20 |
// |
| 21 |
struct LIBCUTL_EXPORT auto_remove |
| 22 |
{ |
| 23 |
explicit |
| 24 |
auto_remove (path const& p) |
| 25 |
: path_ (p), canceled_ (false) |
| 26 |
{ |
| 27 |
} |
| 28 |
|
| 29 |
~auto_remove (); |
| 30 |
|
| 31 |
void |
| 32 |
cancel () |
| 33 |
{ |
| 34 |
canceled_ = true; |
| 35 |
} |
| 36 |
|
| 37 |
private: |
| 38 |
auto_remove (auto_remove const&); |
| 39 |
|
| 40 |
auto_remove& |
| 41 |
operator= (auto_remove const&); |
| 42 |
|
| 43 |
private: |
| 44 |
path path_; |
| 45 |
bool canceled_; |
| 46 |
}; |
| 47 |
|
| 48 |
// Remove a list of file or aempty directories on destruction unless |
| 49 |
// canceled. |
| 50 |
// |
| 51 |
struct LIBCUTL_EXPORT auto_removes |
| 52 |
{ |
| 53 |
auto_removes (): canceled_ (false) {} |
| 54 |
~auto_removes (); |
| 55 |
|
| 56 |
void |
| 57 |
add (path const& p) |
| 58 |
{ |
| 59 |
paths_.push_back (p); |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
cancel () |
| 64 |
{ |
| 65 |
canceled_ = true; |
| 66 |
} |
| 67 |
|
| 68 |
private: |
| 69 |
auto_removes (auto_removes const&); |
| 70 |
|
| 71 |
auto_removes& |
| 72 |
operator= (auto_removes const&); |
| 73 |
|
| 74 |
private: |
| 75 |
typedef std::vector<path> paths; |
| 76 |
|
| 77 |
paths paths_; |
| 78 |
bool canceled_; |
| 79 |
}; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
#endif // CUTL_FS_AUTO_REMOVE_HXX |