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