Remove two dead methods and improve the comments for DiffFilesWithTolerance.
[oota-llvm.git] / include / llvm / Support / FileUtilities.h
1 //===- llvm/Support/FileUtilities.h - File System Utilities -----*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a family of utility functions which are useful for doing
11 // various things with files.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_FILEUTILITIES_H
16 #define LLVM_SUPPORT_FILEUTILITIES_H
17
18 #include "llvm/System/Path.h"
19
20 namespace llvm {
21
22   /// DiffFilesWithTolerance - Compare the two files specified, returning 0 if
23   /// the files match, 1 if they are different, and 2 if there is a file error.
24   /// This function allows you to specify an absolete and relative FP error that
25   /// is allowed to exist.  If you specify a string to fill in for the error
26   /// option, it will set the string to an error message if an error occurs, or
27   /// if the files are different.
28   ///
29   int DiffFilesWithTolerance(const sys::Path &FileA, const sys::Path &FileB,
30                              double AbsTol, double RelTol,
31                              std::string *Error = 0);
32
33
34   /// FileRemover - This class is a simple object meant to be stack allocated.
35   /// If an exception is thrown from a region, the object removes the filename
36   /// specified (if deleteIt is true).
37   ///
38   class FileRemover {
39     sys::Path Filename;
40     bool DeleteIt;
41   public:
42     FileRemover(const sys::Path &filename, bool deleteIt = true)
43       : Filename(filename), DeleteIt(deleteIt) {}
44     
45     ~FileRemover() {
46       if (DeleteIt)
47         try {
48           Filename.destroyFile();
49         } catch (...) {}             // Ignore problems deleting the file.
50     }
51
52     /// releaseFile - Take ownership of the file away from the FileRemover so it
53     /// will not be removed when the object is destroyed.
54     void releaseFile() { DeleteIt = false; }
55   };
56 } // End llvm namespace
57
58 #endif