root / trunk / Windows / libs / poco / include / Poco / TemporaryFile.h @ 3

View | Annotate | Download (3.2 KB)

1 3 jimbo
//
2 3 jimbo
// TemporaryFile.h
3 3 jimbo
//
4 3 jimbo
// $Id: //poco/1.3/Foundation/include/Poco/TemporaryFile.h#1 $
5 3 jimbo
//
6 3 jimbo
// Library: Foundation
7 3 jimbo
// Package: Filesystem
8 3 jimbo
// Module:  TemporaryFile
9 3 jimbo
//
10 3 jimbo
// Definition of the TemporaryFile class.
11 3 jimbo
//
12 3 jimbo
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13 3 jimbo
// and Contributors.
14 3 jimbo
//
15 3 jimbo
// Permission is hereby granted, free of charge, to any person or organization
16 3 jimbo
// obtaining a copy of the software and accompanying documentation covered by
17 3 jimbo
// this license (the "Software") to use, reproduce, display, distribute,
18 3 jimbo
// execute, and transmit the Software, and to prepare derivative works of the
19 3 jimbo
// Software, and to permit third-parties to whom the Software is furnished to
20 3 jimbo
// do so, all subject to the following:
21 3 jimbo
//
22 3 jimbo
// The copyright notices in the Software and this entire statement, including
23 3 jimbo
// the above license grant, this restriction and the following disclaimer,
24 3 jimbo
// must be included in all copies of the Software, in whole or in part, and
25 3 jimbo
// all derivative works of the Software, unless such copies or derivative
26 3 jimbo
// works are solely in the form of machine-executable object code generated by
27 3 jimbo
// a source language processor.
28 3 jimbo
//
29 3 jimbo
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 3 jimbo
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 3 jimbo
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32 3 jimbo
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33 3 jimbo
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34 3 jimbo
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 3 jimbo
// DEALINGS IN THE SOFTWARE.
36 3 jimbo
//
37 3 jimbo
38 3 jimbo
39 3 jimbo
#ifndef Foundation_TemporaryFile_INCLUDED
40 3 jimbo
#define Foundation_TemporaryFile_INCLUDED
41 3 jimbo
42 3 jimbo
43 3 jimbo
#include "Poco/Foundation.h"
44 3 jimbo
#include "Poco/File.h"
45 3 jimbo
46 3 jimbo
47 3 jimbo
namespace Poco {
48 3 jimbo
49 3 jimbo
50 3 jimbo
class Foundation_API TemporaryFile: public File
51 3 jimbo
        /// The TemporaryFile class helps with the handling
52 3 jimbo
        /// of temporary files.
53 3 jimbo
        /// A unique name for the temporary file is
54 3 jimbo
        /// automatically chosen and the file is placed
55 3 jimbo
        /// in the directory reserved for temporary
56 3 jimbo
        /// files (see Path::temp()).
57 3 jimbo
        /// Obtain the path by calling the path() method
58 3 jimbo
        /// (inherited from File).
59 3 jimbo
        ///
60 3 jimbo
        /// The TemporaryFile class does not actually
61 3 jimbo
        /// create the file - this is up to the application.
62 3 jimbo
        /// The class does, however, delete the temporary
63 3 jimbo
        /// file - either in the destructor, or immediately
64 3 jimbo
        /// before the application terminates.
65 3 jimbo
{
66 3 jimbo
public:
67 3 jimbo
        TemporaryFile();
68 3 jimbo
                /// Creates the TemporaryFile.
69 3 jimbo
70 3 jimbo
        ~TemporaryFile();
71 3 jimbo
                /// Destroys the TemporaryFile and
72 3 jimbo
                /// deletes the corresponding file on
73 3 jimbo
                /// disk unless keep() or keepUntilExit()
74 3 jimbo
                /// has been called.
75 3 jimbo
76 3 jimbo
        void keep();
77 3 jimbo
                /// Disables automatic deletion of the file in
78 3 jimbo
                /// the destructor.
79 3 jimbo
80 3 jimbo
        void keepUntilExit();
81 3 jimbo
                /// Disables automatic deletion of the file in
82 3 jimbo
                /// the destructor, but registers the file
83 3 jimbo
                /// for deletion at process termination.
84 3 jimbo
85 3 jimbo
        static void registerForDeletion(const std::string& path);
86 3 jimbo
                /// Registers the given file for deletion
87 3 jimbo
                /// at process termination.
88 3 jimbo
89 3 jimbo
        static std::string tempName();
90 3 jimbo
                /// Returns a unique path name for a temporary
91 3 jimbo
                /// file in the system's scratch directory
92 3 jimbo
                /// (see Path::temp()).
93 3 jimbo
94 3 jimbo
private:
95 3 jimbo
        bool _keep;
96 3 jimbo
};
97 3 jimbo
98 3 jimbo
99 3 jimbo
} // namespace Poco
100 3 jimbo
101 3 jimbo
102 3 jimbo
#endif // Foundation_TemporaryFile_INCLUDED