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