]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wfstream.h
Add XRC handler for wxCommandLinkButton.
[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
5fec5bb6
VZ
45protected:
46 wxFileInputStream();
79c3e0e1 47
5fec5bb6
VZ
48 size_t OnSysRead(void *buffer, size_t size);
49 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
50 wxFileOffset OnSysTell() const;
75ed1d15 51
5fec5bb6
VZ
52protected:
53 wxFile *m_file;
54 bool m_file_destroy;
22f3361e 55
c0c133e1 56 wxDECLARE_NO_COPY_CLASS(wxFileInputStream);
79c3e0e1
GL
57};
58
5fec5bb6
VZ
59class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
60{
61public:
62 wxFileOutputStream(const wxString& fileName);
63 wxFileOutputStream(wxFile& file);
64 wxFileOutputStream(int fd);
65 virtual ~wxFileOutputStream();
32fc4afb 66
5fec5bb6
VZ
67 void Sync();
68 bool Close() { return m_file_destroy ? m_file->Close() : true; }
69 wxFileOffset GetLength() const;
32fc4afb 70
b7cacb43 71 bool Ok() const { return IsOk(); }
f02f4d43 72 virtual bool IsOk() const;
0912690b 73 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
32fc4afb 74
5fec5bb6
VZ
75protected:
76 wxFileOutputStream();
32fc4afb 77
5fec5bb6
VZ
78 size_t OnSysWrite(const void *buffer, size_t size);
79 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
80 wxFileOffset OnSysTell() const;
32fc4afb 81
5fec5bb6
VZ
82protected:
83 wxFile *m_file;
84 bool m_file_destroy;
22f3361e 85
c0c133e1 86 wxDECLARE_NO_COPY_CLASS(wxFileOutputStream);
32fc4afb
GL
87};
88
e1265174
MW
89class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
90{
91public:
92 wxTempFileOutputStream(const wxString& fileName);
93 virtual ~wxTempFileOutputStream();
94
95 bool Close() { return Commit(); }
5f9c3802
SC
96 WXDLLIMPEXP_INLINE_BASE virtual bool Commit() { return m_file->Commit(); }
97 WXDLLIMPEXP_INLINE_BASE virtual void Discard() { m_file->Discard(); }
e1265174
MW
98
99 wxFileOffset GetLength() const { return m_file->Length(); }
100 bool IsSeekable() const { return true; }
101
102protected:
103 size_t OnSysWrite(const void *buffer, size_t size);
104 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
105 { return m_file->Seek(pos, mode); }
106 wxFileOffset OnSysTell() const { return m_file->Tell(); }
107
108private:
109 wxTempFile *m_file;
110
c0c133e1 111 wxDECLARE_NO_COPY_CLASS(wxTempFileOutputStream);
e1265174
MW
112};
113
fc7a2a60
VZ
114class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
115 public wxFileOutputStream
116{
117public:
118 wxFileStream(const wxString& fileName);
a6ac8d75 119 virtual bool IsOk() const;
fc7a2a60 120
3e97b550
VZ
121 // override (some) virtual functions inherited from both classes to resolve
122 // ambiguities (this wouldn't be necessary if wxStreamBase were a virtual
123 // base class but it isn't)
124
125 virtual bool IsSeekable() const
126 {
127 return wxFileInputStream::IsSeekable();
128 }
129
130 virtual wxFileOffset GetLength() const
131 {
132 return wxFileInputStream::GetLength();
133 }
134
135protected:
136 virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
137 {
138 return wxFileInputStream::OnSysSeek(pos, mode);
139 }
140
141 virtual wxFileOffset OnSysTell() const
142 {
143 return wxFileInputStream::OnSysTell();
144 }
145
fc7a2a60 146private:
c0c133e1 147 wxDECLARE_NO_COPY_CLASS(wxFileStream);
84b46c35
GL
148};
149
85990624
RN
150#endif //wxUSE_FILE
151
152#if wxUSE_FFILE
153
65045edd
RR
154// ----------------------------------------------------------------------------
155// wxFFileStream using wxFFile
156// ----------------------------------------------------------------------------
157
5fec5bb6
VZ
158class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
159{
160public:
dc65c743 161 wxFFileInputStream(const wxString& fileName, const wxString& mode = "rb");
5fec5bb6
VZ
162 wxFFileInputStream(wxFFile& file);
163 wxFFileInputStream(FILE *file);
d3c7fc99 164 virtual ~wxFFileInputStream();
65045edd 165
5fec5bb6 166 wxFileOffset GetLength() const;
65045edd 167
b7cacb43 168 bool Ok() const { return IsOk(); }
f02f4d43 169 virtual bool IsOk() const;
0912690b 170 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
65045edd 171
5fec5bb6
VZ
172protected:
173 wxFFileInputStream();
65045edd 174
5fec5bb6
VZ
175 size_t OnSysRead(void *buffer, size_t size);
176 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
177 wxFileOffset OnSysTell() const;
65045edd 178
5fec5bb6
VZ
179protected:
180 wxFFile *m_file;
181 bool m_file_destroy;
22f3361e 182
c0c133e1 183 wxDECLARE_NO_COPY_CLASS(wxFFileInputStream);
65045edd
RR
184};
185
5fec5bb6
VZ
186class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
187{
188public:
02e22828 189 wxFFileOutputStream(const wxString& fileName, const wxString& mode = "wb");
5fec5bb6
VZ
190 wxFFileOutputStream(wxFFile& file);
191 wxFFileOutputStream(FILE *file);
192 virtual ~wxFFileOutputStream();
65045edd 193
5fec5bb6
VZ
194 void Sync();
195 bool Close() { return m_file_destroy ? m_file->Close() : true; }
196 wxFileOffset GetLength() const;
65045edd 197
b7cacb43 198 bool Ok() const { return IsOk(); }
92bf6cc1 199 virtual bool IsOk() const;
0912690b 200 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
65045edd 201
5fec5bb6
VZ
202protected:
203 wxFFileOutputStream();
65045edd 204
5fec5bb6
VZ
205 size_t OnSysWrite(const void *buffer, size_t size);
206 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
207 wxFileOffset OnSysTell() const;
65045edd 208
5fec5bb6
VZ
209protected:
210 wxFFile *m_file;
211 bool m_file_destroy;
22f3361e 212
c0c133e1 213 wxDECLARE_NO_COPY_CLASS(wxFFileOutputStream);
65045edd
RR
214};
215
fc7a2a60
VZ
216class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
217 public wxFFileOutputStream
218{
219public:
02e22828 220 wxFFileStream(const wxString& fileName, const wxString& mode = "w+b");
3e97b550
VZ
221
222 // override some virtual functions to resolve ambiguities, just as in
223 // wxFileStream
224
92bf6cc1 225 virtual bool IsOk() const;
fc7a2a60 226
3e97b550
VZ
227 virtual bool IsSeekable() const
228 {
229 return wxFFileInputStream::IsSeekable();
230 }
231
232 virtual wxFileOffset GetLength() const
233 {
234 return wxFFileInputStream::GetLength();
235 }
236
237protected:
238 virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
239 {
240 return wxFFileInputStream::OnSysSeek(pos, mode);
241 }
242
243 virtual wxFileOffset OnSysTell() const
244 {
245 return wxFFileInputStream::OnSysTell();
246 }
247
fc7a2a60 248private:
c0c133e1 249 wxDECLARE_NO_COPY_CLASS(wxFFileStream);
65045edd 250};
fc7a2a60 251
85990624
RN
252#endif //wxUSE_FFILE
253
254#endif // wxUSE_STREAMS
a0250ba3 255
5fec5bb6 256#endif // _WX_WXFSTREAM_H__