TemporaryFile.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // TemporaryFile.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/TemporaryFile.h#2 $
  5. //
  6. // Library: Foundation
  7. // Package: Filesystem
  8. // Module: TemporaryFile
  9. //
  10. // Definition of the TemporaryFile class.
  11. //
  12. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_TemporaryFile_INCLUDED
  18. #define Foundation_TemporaryFile_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/File.h"
  21. namespace Poco {
  22. class Foundation_API TemporaryFile: public File
  23. /// The TemporaryFile class helps with the handling
  24. /// of temporary files.
  25. /// A unique name for the temporary file is
  26. /// automatically chosen and the file is placed
  27. /// in the directory reserved for temporary
  28. /// files (see Path::temp()).
  29. /// Obtain the path by calling the path() method
  30. /// (inherited from File).
  31. ///
  32. /// The TemporaryFile class does not actually
  33. /// create the file - this is up to the application.
  34. /// The class does, however, delete the temporary
  35. /// file - either in the destructor, or immediately
  36. /// before the application terminates.
  37. {
  38. public:
  39. TemporaryFile();
  40. /// Creates the TemporaryFile.
  41. TemporaryFile(const std::string& tempDir);
  42. /// Creates the TemporaryFile using the given directory.
  43. ~TemporaryFile();
  44. /// Destroys the TemporaryFile and
  45. /// deletes the corresponding file on
  46. /// disk unless keep() or keepUntilExit()
  47. /// has been called.
  48. void keep();
  49. /// Disables automatic deletion of the file in
  50. /// the destructor.
  51. void keepUntilExit();
  52. /// Disables automatic deletion of the file in
  53. /// the destructor, but registers the file
  54. /// for deletion at process termination.
  55. static void registerForDeletion(const std::string& path);
  56. /// Registers the given file for deletion
  57. /// at process termination.
  58. static std::string tempName(const std::string& tempDir = "");
  59. /// Returns a unique path name for a temporary
  60. /// file in the system's scratch directory (see Path::temp())
  61. /// if tempDir is empty or in the directory specified in tempDir
  62. /// otherwise.
  63. private:
  64. bool _keep;
  65. };
  66. } // namespace Poco
  67. #endif // Foundation_TemporaryFile_INCLUDED