Move a helper class out of bugpoint to here.
authorChris Lattner <sabre@nondot.org>
Wed, 18 Feb 2004 17:16:17 +0000 (17:16 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 18 Feb 2004 17:16:17 +0000 (17:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11582 91177308-0d34-0410-b5e6-96231b3b80d8

include/Support/FileUtilities.h
include/llvm/Support/FileUtilities.h

index 3bc3aa850460d387870ce864255835d19c116b26..7ccb69434917f869742035db0adea3186066ecbe 100644 (file)
@@ -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
index 3bc3aa850460d387870ce864255835d19c116b26..7ccb69434917f869742035db0adea3186066ecbe 100644 (file)
@@ -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