1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: File stream classes
4 // Author: Guilhem Lavaux
7 // Copyright: (c) Guilhem Lavaux
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_WXFSTREAM_H__
12 #define _WX_WXFSTREAM_H__
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/stream.h"
26 // ----------------------------------------------------------------------------
27 // wxFileStream using wxFile
28 // ----------------------------------------------------------------------------
30 class WXDLLIMPEXP_BASE wxFileInputStream
: public wxInputStream
33 wxFileInputStream(const wxString
& ifileName
);
34 wxFileInputStream(wxFile
& file
);
35 wxFileInputStream(int fd
);
36 virtual ~wxFileInputStream();
38 wxFileOffset
GetLength() const;
40 bool Ok() const { return IsOk(); }
41 virtual bool IsOk() const;
42 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
44 wxFile
* GetFile() const { return m_file
; }
49 size_t OnSysRead(void *buffer
, size_t size
);
50 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
51 wxFileOffset
OnSysTell() const;
57 wxDECLARE_NO_COPY_CLASS(wxFileInputStream
);
60 class WXDLLIMPEXP_BASE wxFileOutputStream
: public wxOutputStream
63 wxFileOutputStream(const wxString
& fileName
);
64 wxFileOutputStream(wxFile
& file
);
65 wxFileOutputStream(int fd
);
66 virtual ~wxFileOutputStream();
69 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
70 wxFileOffset
GetLength() const;
72 bool Ok() const { return IsOk(); }
73 virtual bool IsOk() const;
74 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
76 wxFile
* GetFile() const { return m_file
; }
81 size_t OnSysWrite(const void *buffer
, size_t size
);
82 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
83 wxFileOffset
OnSysTell() const;
89 wxDECLARE_NO_COPY_CLASS(wxFileOutputStream
);
92 class WXDLLIMPEXP_BASE wxTempFileOutputStream
: public wxOutputStream
95 wxTempFileOutputStream(const wxString
& fileName
);
96 virtual ~wxTempFileOutputStream();
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(); }
102 wxFileOffset
GetLength() const { return m_file
->Length(); }
103 bool IsSeekable() const { return true; }
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(); }
114 wxDECLARE_NO_COPY_CLASS(wxTempFileOutputStream
);
117 class WXDLLIMPEXP_BASE wxFileStream
: public wxFileInputStream
,
118 public wxFileOutputStream
121 wxFileStream(const wxString
& fileName
);
122 virtual bool IsOk() const;
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)
128 virtual bool IsSeekable() const
130 return wxFileInputStream::IsSeekable();
133 virtual wxFileOffset
GetLength() const
135 return wxFileInputStream::GetLength();
139 virtual wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
)
141 return wxFileInputStream::OnSysSeek(pos
, mode
);
144 virtual wxFileOffset
OnSysTell() const
146 return wxFileInputStream::OnSysTell();
150 wxDECLARE_NO_COPY_CLASS(wxFileStream
);
157 // ----------------------------------------------------------------------------
158 // wxFFileStream using wxFFile
159 // ----------------------------------------------------------------------------
161 class WXDLLIMPEXP_BASE wxFFileInputStream
: public wxInputStream
164 wxFFileInputStream(const wxString
& fileName
, const wxString
& mode
= "rb");
165 wxFFileInputStream(wxFFile
& file
);
166 wxFFileInputStream(FILE *file
);
167 virtual ~wxFFileInputStream();
169 wxFileOffset
GetLength() const;
171 bool Ok() const { return IsOk(); }
172 virtual bool IsOk() const;
173 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
175 wxFFile
* GetFile() const { return m_file
; }
178 wxFFileInputStream();
180 size_t OnSysRead(void *buffer
, size_t size
);
181 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
182 wxFileOffset
OnSysTell() const;
188 wxDECLARE_NO_COPY_CLASS(wxFFileInputStream
);
191 class WXDLLIMPEXP_BASE wxFFileOutputStream
: public wxOutputStream
194 wxFFileOutputStream(const wxString
& fileName
, const wxString
& mode
= "wb");
195 wxFFileOutputStream(wxFFile
& file
);
196 wxFFileOutputStream(FILE *file
);
197 virtual ~wxFFileOutputStream();
200 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
201 wxFileOffset
GetLength() const;
203 bool Ok() const { return IsOk(); }
204 virtual bool IsOk() const;
205 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
207 wxFFile
* GetFile() const { return m_file
; }
210 wxFFileOutputStream();
212 size_t OnSysWrite(const void *buffer
, size_t size
);
213 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
214 wxFileOffset
OnSysTell() const;
220 wxDECLARE_NO_COPY_CLASS(wxFFileOutputStream
);
223 class WXDLLIMPEXP_BASE wxFFileStream
: public wxFFileInputStream
,
224 public wxFFileOutputStream
227 wxFFileStream(const wxString
& fileName
, const wxString
& mode
= "w+b");
229 // override some virtual functions to resolve ambiguities, just as in
232 virtual bool IsOk() const;
234 virtual bool IsSeekable() const
236 return wxFFileInputStream::IsSeekable();
239 virtual wxFileOffset
GetLength() const
241 return wxFFileInputStream::GetLength();
245 virtual wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
)
247 return wxFFileInputStream::OnSysSeek(pos
, mode
);
250 virtual wxFileOffset
OnSysTell() const
252 return wxFFileInputStream::OnSysTell();
256 wxDECLARE_NO_COPY_CLASS(wxFFileStream
);
261 #endif // wxUSE_STREAMS
263 #endif // _WX_WXFSTREAM_H__