]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/wfstream.h
Test using wxString::ToCDouble() in wxAny.
[wxWidgets.git] / include / wx / wfstream.h
... / ...
CommitLineData
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
31class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
32{
33public:
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
47protected:
48 wxFileInputStream();
49
50 size_t OnSysRead(void *buffer, size_t size);
51 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
52 wxFileOffset OnSysTell() const;
53
54protected:
55 wxFile *m_file;
56 bool m_file_destroy;
57
58 wxDECLARE_NO_COPY_CLASS(wxFileInputStream);
59};
60
61class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
62{
63public:
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
79protected:
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
86protected:
87 wxFile *m_file;
88 bool m_file_destroy;
89
90 wxDECLARE_NO_COPY_CLASS(wxFileOutputStream);
91};
92
93class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
94{
95public:
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
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
115 wxDECLARE_NO_COPY_CLASS(wxTempFileOutputStream);
116};
117
118class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
119 public wxFileOutputStream
120{
121public:
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
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
150private:
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
162class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
163{
164public:
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
178protected:
179 wxFFileInputStream();
180
181 size_t OnSysRead(void *buffer, size_t size);
182 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
183 wxFileOffset OnSysTell() const;
184
185protected:
186 wxFFile *m_file;
187 bool m_file_destroy;
188
189 wxDECLARE_NO_COPY_CLASS(wxFFileInputStream);
190};
191
192class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
193{
194public:
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
210protected:
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
217protected:
218 wxFFile *m_file;
219 bool m_file_destroy;
220
221 wxDECLARE_NO_COPY_CLASS(wxFFileOutputStream);
222};
223
224class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
225 public wxFFileOutputStream
226{
227public:
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
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
256private:
257 wxDECLARE_NO_COPY_CLASS(wxFFileStream);
258};
259
260#endif //wxUSE_FFILE
261
262#endif // wxUSE_STREAMS
263
264#endif // _WX_WXFSTREAM_H__