1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: File stream classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_WXFSTREAM_H__
13 #define _WX_WXFSTREAM_H__
19 #include "wx/object.h"
20 #include "wx/string.h"
21 #include "wx/stream.h"
27 // ----------------------------------------------------------------------------
28 // wxFileStream using wxFile
29 // ----------------------------------------------------------------------------
31 class WXDLLIMPEXP_BASE wxFileInputStream
: public wxInputStream
34 wxFileInputStream(const wxString
& ifileName
);
35 wxFileInputStream(wxFile
& file
);
36 wxFileInputStream(int fd
);
37 virtual ~wxFileInputStream();
39 wxFileOffset
GetLength() const;
41 bool Ok() const { return IsOk(); }
42 virtual bool IsOk() const;
43 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
45 wxFile
* GetFile() const { return m_file
; }
50 size_t OnSysRead(void *buffer
, size_t size
);
51 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
52 wxFileOffset
OnSysTell() const;
58 wxDECLARE_NO_COPY_CLASS(wxFileInputStream
);
61 class WXDLLIMPEXP_BASE wxFileOutputStream
: public wxOutputStream
64 wxFileOutputStream(const wxString
& fileName
);
65 wxFileOutputStream(wxFile
& file
);
66 wxFileOutputStream(int fd
);
67 virtual ~wxFileOutputStream();
70 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
71 wxFileOffset
GetLength() const;
73 bool Ok() const { return IsOk(); }
74 virtual bool IsOk() const;
75 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
77 wxFile
* GetFile() const { return m_file
; }
82 size_t OnSysWrite(const void *buffer
, size_t size
);
83 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
84 wxFileOffset
OnSysTell() const;
90 wxDECLARE_NO_COPY_CLASS(wxFileOutputStream
);
93 class WXDLLIMPEXP_BASE wxTempFileOutputStream
: public wxOutputStream
96 wxTempFileOutputStream(const wxString
& fileName
);
97 virtual ~wxTempFileOutputStream();
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(); }
103 wxFileOffset
GetLength() const { return m_file
->Length(); }
104 bool IsSeekable() const { return true; }
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(); }
115 wxDECLARE_NO_COPY_CLASS(wxTempFileOutputStream
);
118 class WXDLLIMPEXP_BASE wxFileStream
: public wxFileInputStream
,
119 public wxFileOutputStream
122 wxFileStream(const wxString
& fileName
);
123 virtual bool IsOk() const;
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)
129 virtual bool IsSeekable() const
131 return wxFileInputStream::IsSeekable();
134 virtual wxFileOffset
GetLength() const
136 return wxFileInputStream::GetLength();
140 virtual wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
)
142 return wxFileInputStream::OnSysSeek(pos
, mode
);
145 virtual wxFileOffset
OnSysTell() const
147 return wxFileInputStream::OnSysTell();
151 wxDECLARE_NO_COPY_CLASS(wxFileStream
);
158 // ----------------------------------------------------------------------------
159 // wxFFileStream using wxFFile
160 // ----------------------------------------------------------------------------
162 class WXDLLIMPEXP_BASE wxFFileInputStream
: public wxInputStream
165 wxFFileInputStream(const wxString
& fileName
, const wxString
& mode
= "rb");
166 wxFFileInputStream(wxFFile
& file
);
167 wxFFileInputStream(FILE *file
);
168 virtual ~wxFFileInputStream();
170 wxFileOffset
GetLength() const;
172 bool Ok() const { return IsOk(); }
173 virtual bool IsOk() const;
174 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
176 wxFFile
* GetFile() const { return m_file
; }
179 wxFFileInputStream();
181 size_t OnSysRead(void *buffer
, size_t size
);
182 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
183 wxFileOffset
OnSysTell() const;
189 wxDECLARE_NO_COPY_CLASS(wxFFileInputStream
);
192 class WXDLLIMPEXP_BASE wxFFileOutputStream
: public wxOutputStream
195 wxFFileOutputStream(const wxString
& fileName
, const wxString
& mode
= "wb");
196 wxFFileOutputStream(wxFFile
& file
);
197 wxFFileOutputStream(FILE *file
);
198 virtual ~wxFFileOutputStream();
201 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
202 wxFileOffset
GetLength() const;
204 bool Ok() const { return IsOk(); }
205 virtual bool IsOk() const;
206 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
208 wxFFile
* GetFile() const { return m_file
; }
211 wxFFileOutputStream();
213 size_t OnSysWrite(const void *buffer
, size_t size
);
214 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
215 wxFileOffset
OnSysTell() const;
221 wxDECLARE_NO_COPY_CLASS(wxFFileOutputStream
);
224 class WXDLLIMPEXP_BASE wxFFileStream
: public wxFFileInputStream
,
225 public wxFFileOutputStream
228 wxFFileStream(const wxString
& fileName
, const wxString
& mode
= "w+b");
230 // override some virtual functions to resolve ambiguities, just as in
233 virtual bool IsOk() const;
235 virtual bool IsSeekable() const
237 return wxFFileInputStream::IsSeekable();
240 virtual wxFileOffset
GetLength() const
242 return wxFFileInputStream::GetLength();
246 virtual wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
)
248 return wxFFileInputStream::OnSysSeek(pos
, mode
);
251 virtual wxFileOffset
OnSysTell() const
253 return wxFFileInputStream::OnSysTell();
257 wxDECLARE_NO_COPY_CLASS(wxFFileStream
);
262 #endif // wxUSE_STREAMS
264 #endif // _WX_WXFSTREAM_H__