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