Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.1 KiB

  1. //===- ToolOutputFile.h - Output files for compiler-like tools -----------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the tool_output_file class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_TOOLOUTPUTFILE_H
  14. #define LLVM_SUPPORT_TOOLOUTPUTFILE_H
  15. #include "llvm/Support/raw_ostream.h"
  16. namespace llvm {
  17. /// tool_output_file - This class contains a raw_fd_ostream and adds a
  18. /// few extra features commonly needed for compiler-like tool output files:
  19. /// - The file is automatically deleted if the process is killed.
  20. /// - The file is automatically deleted when the tool_output_file
  21. /// object is destroyed unless the client calls keep().
  22. class tool_output_file {
  23. /// Installer - This class is declared before the raw_fd_ostream so that
  24. /// it is constructed before the raw_fd_ostream is constructed and
  25. /// destructed after the raw_fd_ostream is destructed. It installs
  26. /// cleanups in its constructor and uninstalls them in its destructor.
  27. class CleanupInstaller {
  28. /// Filename - The name of the file.
  29. std::string Filename;
  30. public:
  31. /// Keep - The flag which indicates whether we should not delete the file.
  32. bool Keep;
  33. explicit CleanupInstaller(const char *filename);
  34. ~CleanupInstaller();
  35. } Installer;
  36. /// OS - The contained stream. This is intentionally declared after
  37. /// Installer.
  38. raw_fd_ostream OS;
  39. public:
  40. /// tool_output_file - This constructor's arguments are passed to
  41. /// to raw_fd_ostream's constructor.
  42. tool_output_file(const char *filename, std::string &ErrorInfo,
  43. unsigned Flags = 0);
  44. /// os - Return the contained raw_fd_ostream.
  45. raw_fd_ostream &os() { return OS; }
  46. /// keep - Indicate that the tool's job wrt this output file has been
  47. /// successful and the file should not be deleted.
  48. void keep() { Installer.Keep = true; }
  49. };
  50. } // end llvm namespace
  51. #endif