aboutsummaryrefslogtreecommitdiff
path: root/cutl/fs/auto-remove.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-09-19 08:41:33 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-09-19 08:41:33 +0200
commit5409489c632fcaa3868a0767cecef65f079e5a94 (patch)
tree829cdf6020eb848526778741afe995ee242e7a4d /cutl/fs/auto-remove.cxx
parent6ca1c8ee64bf7268d194eb15e72d3024a335039d (diff)
Add RAII-based file auto-remover
Diffstat (limited to 'cutl/fs/auto-remove.cxx')
-rw-r--r--cutl/fs/auto-remove.cxx39
1 files changed, 39 insertions, 0 deletions
diff --git a/cutl/fs/auto-remove.cxx b/cutl/fs/auto-remove.cxx
new file mode 100644
index 0000000..08718e9
--- /dev/null
+++ b/cutl/fs/auto-remove.cxx
@@ -0,0 +1,39 @@
+// file : cutl/fs/auto-remove.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <cstdio> // std::remove
+#include <cerrno>
+
+#include <cutl/fs/exception.hxx>
+#include <cutl/fs/auto-remove.hxx>
+
+namespace cutl
+{
+ namespace fs
+ {
+ auto_remove::
+ ~auto_remove ()
+ {
+ if (!canceled_)
+ {
+ if (std::remove (path_.string ().c_str ()) == -1)
+ throw error (errno);
+ }
+ }
+
+ auto_removes::
+ ~auto_removes ()
+ {
+ if (!canceled_)
+ {
+ for (paths::iterator i (paths_.begin ()); i != paths_.end (); ++i)
+ {
+ if (std::remove (i->string ().c_str ()) == -1)
+ throw error (errno);
+ }
+ }
+ }
+ }
+}