1 | /* |
2 | * The contents of this file are subject to the Initial |
3 | * Developer's Public License Version 1.0 (the "License"); |
4 | * you may not use this file except in compliance with the |
5 | * License. You may obtain a copy of the License at |
6 | * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
7 | * |
8 | * Software distributed under the License is distributed AS IS, |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
10 | * See the License for the specific language governing rights |
11 | * and limitations under the License. |
12 | * |
13 | * The Original Code was created by Dmitry Yemanov |
14 | * for the Firebird Open Source RDBMS project. |
15 | * |
16 | * Copyright (c) 2006 Dmitry Yemanov <dimitr@users.sf.net> |
17 | * and all contributors signed below. |
18 | * |
19 | * All Rights Reserved. |
20 | * Contributor(s): ______________________________________. |
21 | */ |
22 | |
23 | #ifndef CLASSES_TEMP_FILE_H |
24 | #define CLASSES_TEMP_FILE_H |
25 | |
26 | #include "firebird.h" |
27 | #include "../common/classes/fb_string.h" |
28 | #include "../common/classes/File.h" |
29 | |
30 | namespace Firebird { |
31 | |
32 | class IStatus; |
33 | |
34 | class TempFile : public File |
35 | { |
36 | public: |
37 | TempFile(MemoryPool& pool, const PathName& prefix, const PathName& directory, |
38 | bool do_unlink = true) |
39 | : filename(pool), position(0), size(0), doUnlink(do_unlink) |
40 | { |
41 | init(directory, prefix); |
42 | } |
43 | |
44 | TempFile(const PathName& prefix, bool do_unlink = true) |
45 | : position(0), size(0), doUnlink(do_unlink) |
46 | { |
47 | init("" , prefix); |
48 | } |
49 | |
50 | virtual ~TempFile(); |
51 | |
52 | size_t read(offset_t, void*, size_t); |
53 | size_t write(offset_t, const void*, size_t); |
54 | |
55 | void unlink(); |
56 | |
57 | offset_t getSize() const |
58 | { |
59 | return size; |
60 | } |
61 | |
62 | void extend(size_t); |
63 | |
64 | const PathName& getName() const |
65 | { |
66 | return filename; |
67 | } |
68 | |
69 | static PathName getTempPath(); |
70 | static PathName create(const PathName& prefix, const PathName& directory = "" ); |
71 | static PathName create(IStatus* status, const PathName& prefix, const PathName& directory = "" ); |
72 | |
73 | private: |
74 | void init(const PathName&, const PathName&); |
75 | void seek(const offset_t); |
76 | |
77 | #if defined(WIN_NT) |
78 | HANDLE handle; |
79 | #else |
80 | int handle; |
81 | #endif |
82 | |
83 | PathName filename; |
84 | offset_t position; |
85 | offset_t size; |
86 | bool doUnlink; |
87 | }; |
88 | |
89 | } // namespace Firebird |
90 | |
91 | #endif // CLASSES_TEMP_FILE_H |
92 | |