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
; }
48 size_t OnSysRead(void *buffer
, size_t size
);
49 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
50 wxFileOffset
OnSysTell() const;
56 wxDECLARE_NO_COPY_CLASS(wxFileInputStream
);
59 class WXDLLIMPEXP_BASE wxFileOutputStream
: public wxOutputStream
62 wxFileOutputStream(const wxString
& fileName
);
63 wxFileOutputStream(wxFile
& file
);
64 wxFileOutputStream(int fd
);
65 virtual ~wxFileOutputStream();
68 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
69 wxFileOffset
GetLength() const;
71 bool Ok() const { return IsOk(); }
72 virtual bool IsOk() const;
73 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
78 size_t OnSysWrite(const void *buffer
, size_t size
);
79 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
80 wxFileOffset
OnSysTell() const;
86 wxDECLARE_NO_COPY_CLASS(wxFileOutputStream
);
89 class WXDLLIMPEXP_BASE wxTempFileOutputStream
: public wxOutputStream
92 wxTempFileOutputStream(const wxString
& fileName
);
93 virtual ~wxTempFileOutputStream();
95 bool Close() { return Commit(); }
96 WXDLLIMPEXP_INLINE_BASE
virtual bool Commit() { return m_file
->Commit(); }
97 WXDLLIMPEXP_INLINE_BASE
virtual void Discard() { m_file
->Discard(); }
99 wxFileOffset
GetLength() const { return m_file
->Length(); }
100 bool IsSeekable() const { return true; }
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(); }
111 wxDECLARE_NO_COPY_CLASS(wxTempFileOutputStream
);
114 class WXDLLIMPEXP_BASE wxFileStream
: public wxFileInputStream
,
115 public wxFileOutputStream
118 wxFileStream(const wxString
& fileName
);
119 virtual bool IsOk() const;
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)
125 virtual bool IsSeekable() const
127 return wxFileInputStream::IsSeekable();
130 virtual wxFileOffset
GetLength() const
132 return wxFileInputStream::GetLength();
136 virtual wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
)
138 return wxFileInputStream::OnSysSeek(pos
, mode
);
141 virtual wxFileOffset
OnSysTell() const
143 return wxFileInputStream::OnSysTell();
147 wxDECLARE_NO_COPY_CLASS(wxFileStream
);
154 // ----------------------------------------------------------------------------
155 // wxFFileStream using wxFFile
156 // ----------------------------------------------------------------------------
158 class WXDLLIMPEXP_BASE wxFFileInputStream
: public wxInputStream
161 wxFFileInputStream(const wxString
& fileName
, const wxString
& mode
= "rb");
162 wxFFileInputStream(wxFFile
& file
);
163 wxFFileInputStream(FILE *file
);
164 virtual ~wxFFileInputStream();
166 wxFileOffset
GetLength() const;
168 bool Ok() const { return IsOk(); }
169 virtual bool IsOk() const;
170 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
173 wxFFileInputStream();
175 size_t OnSysRead(void *buffer
, size_t size
);
176 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
177 wxFileOffset
OnSysTell() const;
183 wxDECLARE_NO_COPY_CLASS(wxFFileInputStream
);
186 class WXDLLIMPEXP_BASE wxFFileOutputStream
: public wxOutputStream
189 wxFFileOutputStream(const wxString
& fileName
, const wxString
& mode
= "wb");
190 wxFFileOutputStream(wxFFile
& file
);
191 wxFFileOutputStream(FILE *file
);
192 virtual ~wxFFileOutputStream();
195 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
196 wxFileOffset
GetLength() const;
198 bool Ok() const { return IsOk(); }
199 virtual bool IsOk() const;
200 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
203 wxFFileOutputStream();
205 size_t OnSysWrite(const void *buffer
, size_t size
);
206 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
207 wxFileOffset
OnSysTell() const;
213 wxDECLARE_NO_COPY_CLASS(wxFFileOutputStream
);
216 class WXDLLIMPEXP_BASE wxFFileStream
: public wxFFileInputStream
,
217 public wxFFileOutputStream
220 wxFFileStream(const wxString
& fileName
, const wxString
& mode
= "w+b");
222 // override some virtual functions to resolve ambiguities, just as in
225 virtual bool IsOk() const;
227 virtual bool IsSeekable() const
229 return wxFFileInputStream::IsSeekable();
232 virtual wxFileOffset
GetLength() const
234 return wxFFileInputStream::GetLength();
238 virtual wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
)
240 return wxFFileInputStream::OnSysSeek(pos
, mode
);
243 virtual wxFileOffset
OnSysTell() const
245 return wxFFileInputStream::OnSysTell();
249 wxDECLARE_NO_COPY_CLASS(wxFFileStream
);
254 #endif // wxUSE_STREAMS
256 #endif // _WX_WXFSTREAM_H__