From 2bcf9410de5f2d0a0f8ce3bf0c00a40f4788fa80 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 18 Feb 2004 17:16:17 +0000 Subject: [PATCH] Move a helper class out of bugpoint to here. llvm-svn: 11582 --- llvm/include/Support/FileUtilities.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/llvm/include/Support/FileUtilities.h b/llvm/include/Support/FileUtilities.h index 3bc3aa850460..7ccb69434917 100644 --- a/llvm/include/Support/FileUtilities.h +++ b/llvm/include/Support/FileUtilities.h @@ -131,6 +131,26 @@ public: return Ret; } }; + + /// FileRemover - This class is a simple object meant to be stack allocated. + /// If an exception is thrown from a region, the object removes the filename + /// specified (if deleteIt is true). + /// + class FileRemover { + bool DeleteIt; + std::string Filename; + public: + FileRemover(bool deleteIt, const std::string &filename) + : DeleteIt(deleteIt), Filename(filename) {} + + ~FileRemover() { + if (DeleteIt) removeFile(Filename); + } + + /// releaseFile - Take ownership of the file away from the FileRemover so it + /// will not be removed when the object is destroyed. + void releaseFile() { DeleteIt = false; } + }; } // End llvm namespace #endif