From 5409489c632fcaa3868a0767cecef65f079e5a94 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 19 Sep 2009 08:41:33 +0200 Subject: Add RAII-based file auto-remover --- cutl/fs/auto-remove.cxx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 cutl/fs/auto-remove.cxx (limited to 'cutl/fs/auto-remove.cxx') 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 +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include // std::remove +#include + +#include +#include + +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); + } + } + } + } +} -- cgit v1.1