diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-12-16 20:29:05 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-02-24 16:40:04 +0300 |
commit | 8e761289a2446367267c6c0d9a26e734f0f78306 (patch) | |
tree | fb495d8c18801f271d124ee48731f10df396ca89 /libcutl/fs/auto-remove.hxx | |
parent | 4c8104756b92b9fa16b3a725e8a6aa620dfd606e (diff) |
Get rid of legacy build systems and rename cutl/ to libcutl/
Diffstat (limited to 'libcutl/fs/auto-remove.hxx')
-rw-r--r-- | libcutl/fs/auto-remove.hxx | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/libcutl/fs/auto-remove.hxx b/libcutl/fs/auto-remove.hxx new file mode 100644 index 0000000..c55f6f9 --- /dev/null +++ b/libcutl/fs/auto-remove.hxx @@ -0,0 +1,82 @@ +// file : libcutl/fs/auto-remove.hxx +// license : MIT; see accompanying LICENSE file + +#ifndef LIBCUTL_FS_AUTO_REMOVE_HXX +#define LIBCUTL_FS_AUTO_REMOVE_HXX + +#include <vector> + +#include <libcutl/fs/path.hxx> +#include <libcutl/fs/exception.hxx> + +#include <libcutl/export.hxx> + +namespace cutl +{ + namespace fs + { + // Remove a file or an empty directory on destruction unless canceled. + // + struct LIBCUTL_EXPORT auto_remove + { + explicit + auto_remove (path const& p) + : path_ (p), canceled_ (false) + { + } + + ~auto_remove (); + + void + cancel () + { + canceled_ = true; + } + + private: + auto_remove (auto_remove const&); + + auto_remove& + operator= (auto_remove const&); + + private: + path path_; + bool canceled_; + }; + + // Remove a list of file or aempty directories on destruction unless + // canceled. + // + struct LIBCUTL_EXPORT auto_removes + { + auto_removes (): canceled_ (false) {} + ~auto_removes (); + + void + add (path const& p) + { + paths_.push_back (p); + } + + void + cancel () + { + canceled_ = true; + } + + private: + auto_removes (auto_removes const&); + + auto_removes& + operator= (auto_removes const&); + + private: + typedef std::vector<path> paths; + + paths paths_; + bool canceled_; + }; + } +} + +#endif // LIBCUTL_FS_AUTO_REMOVE_HXX |