]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wfstream.h
Add wxDataViewRendererBase::GetEffectiveAlignment() and use it.
[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 // Copyright: (c) Guilhem Lavaux
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_WXFSTREAM_H__
12 #define _WX_WXFSTREAM_H__
13
14 #include "wx/defs.h"
15
16 #if wxUSE_STREAMS
17
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/stream.h"
21 #include "wx/file.h"
22 #include "wx/ffile.h"
23
24 #if wxUSE_FILE
25
26 // ----------------------------------------------------------------------------
27 // wxFileStream using wxFile
28 // ----------------------------------------------------------------------------
29
30 class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
31 {
32 public:
33 wxFileInputStream(const wxString& ifileName);
34 wxFileInputStream(wxFile& file);
35 wxFileInputStream(int fd);
36 virtual ~wxFileInputStream();
37
38 wxFileOffset GetLength() const;
39
40 bool Ok() const { return IsOk(); }
41 virtual bool IsOk() const;
42 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
43
44 wxFile* GetFile() const { return m_file; }
45
46 protected:
47 wxFileInputStream();
48
49 size_t OnSysRead(void *buffer, size_t size);
50 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
51 wxFileOffset OnSysTell() const;
52
53 protected:
54 wxFile *m_file;
55 bool m_file_destroy;
56
57 wxDECLARE_NO_COPY_CLASS(wxFileInputStream);
58 };
59
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();
67
68 void Sync();
69 bool Close() { return m_file_destroy ? m_file->Close() : true; }
70 wxFileOffset GetLength() const;
71
72 bool Ok() const { return IsOk(); }
73 virtual bool IsOk() const;
74 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
75
76 wxFile* GetFile() const { return m_file; }
77
78 protected:
79 wxFileOutputStream();
80
81 size_t OnSysWrite(const void *buffer, size_t size);
82 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
83 wxFileOffset OnSysTell() const;
84
85 protected:
86 wxFile *m_file;
87 bool m_file_destroy;
88
89 wxDECLARE_NO_COPY_CLASS(wxFileOutputStream);
90 };
91
92 class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
93 {
94 public:
95 wxTempFileOutputStream(const wxString& fileName);
96 virtual ~wxTempFileOutputStream();
97
98 bool Close() { return Commit(); }
99 WXDLLIMPEXP_INLINE_BASE virtual bool Commit() { return m_file->Commit(); }
100 WXDLLIMPEXP_INLINE_BASE virtual void Discard() { m_file->Discard(); }
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
114 wxDECLARE_NO_COPY_CLASS(wxTempFileOutputStream);
115 };
116
117 class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
118 public wxFileOutputStream
119 {
120 public:
121 wxFileStream(const wxString& fileName);
122 virtual bool IsOk() const;
123
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
149 private:
150 wxDECLARE_NO_COPY_CLASS(wxFileStream);
151 };
152
153 #endif //wxUSE_FILE
154
155 #if wxUSE_FFILE
156
157 // ----------------------------------------------------------------------------
158 // wxFFileStream using wxFFile
159 // ----------------------------------------------------------------------------
160
161 class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
162 {
163 public:
164 wxFFileInputStream(const wxString& fileName, const wxString& mode = "rb");
165 wxFFileInputStream(wxFFile& file);
166 wxFFileInputStream(FILE *file);
167 virtual ~wxFFileInputStream();
168
169 wxFileOffset GetLength() const;
170
171 bool Ok() const { return IsOk(); }
172 virtual bool IsOk() const;
173 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
174
175 wxFFile* GetFile() const { return m_file; }
176
177 protected:
178 wxFFileInputStream();
179
180 size_t OnSysRead(void *buffer, size_t size);
181 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
182 wxFileOffset OnSysTell() const;
183
184 protected:
185 wxFFile *m_file;
186 bool m_file_destroy;
187
188 wxDECLARE_NO_COPY_CLASS(wxFFileInputStream);
189 };
190
191 class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
192 {
193 public:
194 wxFFileOutputStream(const wxString& fileName, const wxString& mode = "wb");
195 wxFFileOutputStream(wxFFile& file);
196 wxFFileOutputStream(FILE *file);
197 virtual ~wxFFileOutputStream();
198
199 void Sync();
200 bool Close() { return m_file_destroy ? m_file->Close() : true; }
201 wxFileOffset GetLength() const;
202
203 bool Ok() const { return IsOk(); }
204 virtual bool IsOk() const;
205 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
206
207 wxFFile* GetFile() const { return m_file; }
208
209 protected:
210 wxFFileOutputStream();
211
212 size_t OnSysWrite(const void *buffer, size_t size);
213 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
214 wxFileOffset OnSysTell() const;
215
216 protected:
217 wxFFile *m_file;
218 bool m_file_destroy;
219
220 wxDECLARE_NO_COPY_CLASS(wxFFileOutputStream);
221 };
222
223 class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
224 public wxFFileOutputStream
225 {
226 public:
227 wxFFileStream(const wxString& fileName, const wxString& mode = "w+b");
228
229 // override some virtual functions to resolve ambiguities, just as in
230 // wxFileStream
231
232 virtual bool IsOk() const;
233
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
255 private:
256 wxDECLARE_NO_COPY_CLASS(wxFFileStream);
257 };
258
259 #endif //wxUSE_FFILE
260
261 #endif // wxUSE_STREAMS
262
263 #endif // _WX_WXFSTREAM_H__