aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Support/FileUtilities.h20
-rw-r--r--include/llvm/Support/FileUtilities.h20
2 files changed, 40 insertions, 0 deletions
diff --git a/include/Support/FileUtilities.h b/include/Support/FileUtilities.h
index 3bc3aa8504..7ccb694349 100644
--- a/include/Support/FileUtilities.h
+++ b/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
diff --git a/include/llvm/Support/FileUtilities.h b/include/llvm/Support/FileUtilities.h
index 3bc3aa8504..7ccb694349 100644
--- a/include/llvm/Support/FileUtilities.h
+++ b/include/llvm/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