]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wfstream.h
Fix FILETIME <-> wxDateTime conversions while DST is in effect in wxMSW.
[wxWidgets.git] / include / wx / wfstream.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wfstream.h
3 // Purpose: File stream classes
4 // Author: Guilhem Lavaux
5 // Modified by:
6 // Created: 11/07/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXFSTREAM_H__
13 #define _WX_WXFSTREAM_H__
14
15 #include "wx/defs.h"
16
17 #if wxUSE_STREAMS
18
19 #include "wx/object.h"
20 #include "wx/string.h"
21 #include "wx/stream.h"
22 #include "wx/file.h"
23 #include "wx/ffile.h"
24
25 #if wxUSE_FILE
26
27 // ----------------------------------------------------------------------------
28 // wxFileStream using wxFile
29 // ----------------------------------------------------------------------------
30
31 class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
32 {
33 public:
34 wxFileInputStream(const wxString& ifileName);
35 wxFileInputStream(wxFile& file);
36 wxFileInputStream(int fd);
37 virtual ~wxFileInputStream();
38
39 wxFileOffset GetLength() const;
40
41 bool Ok() const { return IsOk(); }
42 virtual bool IsOk() const;
43 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
44
45 wxFile* GetFile() const { return m_file; }
46
47 protected:
48 wxFileInputStream();
49
50 size_t OnSysRead(void *buffer, size_t size);
51 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
52 wxFileOffset OnSysTell() const;
53
54 protected:
55 wxFile *m_file;
56 bool m_file_destroy;
57
58 wxDECLARE_NO_COPY_CLASS(wxFileInputStream);
59 };
60
61 class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
62 {
63 public:
64 wxFileOutputStream(const wxString& fileName);
65 wxFileOutputStream(wxFile& file);
66 wxFileOutputStream(int fd);
67 virtual ~wxFileOutputStream();
68
69 void Sync();
70 bool Close() { return m_file_destroy ? m_file->Close() : true; }
71 wxFileOffset GetLength() const;
72
73 bool Ok() const { return IsOk(); }
74 virtual bool IsOk() const;
75 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
76
77 wxFile* GetFile() const { return m_file; }
78
79 protected:
80 wxFileOutputStream();
81
82 size_t OnSysWrite(const void *buffer, size_t size);
83 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
84 wxFileOffset OnSysTell() const;
85
86 protected:
87 wxFile *m_file;
88 bool m_file_destroy;
89
90 wxDECLARE_NO_COPY_CLASS(wxFileOutputStream);
91 };
92
93 class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
94 {
95 public:
96 wxTempFileOutputStream(const wxString& fileName);
97 virtual ~wxTempFileOutputStream();
98
99 bool Close() { return Commit(); }
100 WXDLLIMPEXP_INLINE_BASE virtual bool Commit() { return m_file->Commit(); }
101 WXDLLIMPEXP_INLINE_BASE virtual void Discard() { m_file->Discard(); }
102
103 wxFileOffset GetLength() const { return m_file->Length(); }
104 bool IsSeekable() const { return true; }
105
106 protected:
107 size_t OnSysWrite(const void *buffer, size_t size);
108 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
109 { return m_file->Seek(pos, mode); }
110 wxFileOffset OnSysTell() const { return m_file->Tell(); }
111
112 private:
113 wxTempFile *m_file;
114
115 wxDECLARE_NO_COPY_CLASS(wxTempFileOutputStream);
116 };
117
118 class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
119 public wxFileOutputStream
120 {
121 public:
122 wxFileStream(const wxString& fileName);
123 virtual bool IsOk() const;
124
125 // override (some) virtual functions inherited from both classes to resolve
126 // ambiguities (this wouldn't be necessary if wxStreamBase were a virtual
127 // base class but it isn't)
128
129 virtual bool IsSeekable() const
130 {
131 return wxFileInputStream::IsSeekable();
132 }
133
134 virtual wxFileOffset GetLength() const
135 {
136 return wxFileInputStream::GetLength();
137 }
138
139 protected:
140 virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
141 {
142 return wxFileInputStream::OnSysSeek(pos, mode);
143 }
144
145 virtual wxFileOffset OnSysTell() const
146 {
147 return wxFileInputStream::OnSysTell();
148 }
149
150 private:
151 wxDECLARE_NO_COPY_CLASS(wxFileStream);
152 };
153
154 #endif //wxUSE_FILE
155
156 #if wxUSE_FFILE
157
158 // ----------------------------------------------------------------------------
159 // wxFFileStream using wxFFile
160 // ----------------------------------------------------------------------------
161
162 class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
163 {
164 public:
165 wxFFileInputStream(const wxString& fileName, const wxString& mode = "rb");
166 wxFFileInputStream(wxFFile& file);
167 wxFFileInputStream(FILE *file);
168 virtual ~wxFFileInputStream();
169
170 wxFileOffset GetLength() const;
171
172 bool Ok() const { return IsOk(); }
173 virtual bool IsOk() const;
174 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
175
176 wxFFile* GetFile() const { return m_file; }
177
178 protected:
179 wxFFileInputStream();
180
181 size_t OnSysRead(void *buffer, size_t size);
182 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
183 wxFileOffset OnSysTell() const;
184
185 protected:
186 wxFFile *m_file;
187 bool m_file_destroy;
188
189 wxDECLARE_NO_COPY_CLASS(wxFFileInputStream);
190 };
191
192 class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
193 {
194 public:
195 wxFFileOutputStream(const wxString& fileName, const wxString& mode = "wb");
196 wxFFileOutputStream(wxFFile& file);
197 wxFFileOutputStream(FILE *file);
198 virtual ~wxFFileOutputStream();
199
200 void Sync();
201 bool Close() { return m_file_destroy ? m_file->Close() : true; }
202 wxFileOffset GetLength() const;
203
204 bool Ok() const { return IsOk(); }
205 virtual bool IsOk() const;
206 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
207
208 wxFFile* GetFile() const { return m_file; }
209
210 protected:
211 wxFFileOutputStream();
212
213 size_t OnSysWrite(const void *buffer, size_t size);
214 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
215 wxFileOffset OnSysTell() const;
216
217 protected:
218 wxFFile *m_file;
219 bool m_file_destroy;
220
221 wxDECLARE_NO_COPY_CLASS(wxFFileOutputStream);
222 };
223
224 class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
225 public wxFFileOutputStream
226 {
227 public:
228 wxFFileStream(const wxString& fileName, const wxString& mode = "w+b");
229
230 // override some virtual functions to resolve ambiguities, just as in
231 // wxFileStream
232
233 virtual bool IsOk() const;
234
235 virtual bool IsSeekable() const
236 {
237 return wxFFileInputStream::IsSeekable();
238 }
239
240 virtual wxFileOffset GetLength() const
241 {
242 return wxFFileInputStream::GetLength();
243 }
244
245 protected:
246 virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
247 {
248 return wxFFileInputStream::OnSysSeek(pos, mode);
249 }
250
251 virtual wxFileOffset OnSysTell() const
252 {
253 return wxFFileInputStream::OnSysTell();
254 }
255
256 private:
257 wxDECLARE_NO_COPY_CLASS(wxFFileStream);
258 };
259
260 #endif //wxUSE_FFILE
261
262 #endif // wxUSE_STREAMS
263
264 #endif // _WX_WXFSTREAM_H__