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 DECLARE_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 DECLARE_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 virtual bool Commit() { return m_file
->Commit(); }
97 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 DECLARE_NO_COPY_CLASS(wxTempFileOutputStream
)
114 class WXDLLIMPEXP_BASE wxFileStream
: public wxFileInputStream
,
115 public wxFileOutputStream
118 wxFileStream(const wxString
& fileName
);
119 virtual bool IsOk() const;
122 DECLARE_NO_COPY_CLASS(wxFileStream
)
129 // ----------------------------------------------------------------------------
130 // wxFFileStream using wxFFile
131 // ----------------------------------------------------------------------------
133 class WXDLLIMPEXP_BASE wxFFileInputStream
: public wxInputStream
136 wxFFileInputStream(const wxString
& fileName
, const wxString
& mode
= "rb");
137 wxFFileInputStream(wxFFile
& file
);
138 wxFFileInputStream(FILE *file
);
139 virtual ~wxFFileInputStream();
141 wxFileOffset
GetLength() const;
143 bool Ok() const { return IsOk(); }
144 virtual bool IsOk() const;
145 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
148 wxFFileInputStream();
150 size_t OnSysRead(void *buffer
, size_t size
);
151 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
152 wxFileOffset
OnSysTell() const;
158 DECLARE_NO_COPY_CLASS(wxFFileInputStream
)
161 class WXDLLIMPEXP_BASE wxFFileOutputStream
: public wxOutputStream
164 wxFFileOutputStream(const wxString
& fileName
, const wxString
& mode
= "wb");
165 wxFFileOutputStream(wxFFile
& file
);
166 wxFFileOutputStream(FILE *file
);
167 virtual ~wxFFileOutputStream();
170 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
171 wxFileOffset
GetLength() const;
173 bool Ok() const { return IsOk(); }
174 virtual bool IsOk() const;
175 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
178 wxFFileOutputStream();
180 size_t OnSysWrite(const void *buffer
, size_t size
);
181 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
182 wxFileOffset
OnSysTell() const;
188 DECLARE_NO_COPY_CLASS(wxFFileOutputStream
)
191 class WXDLLIMPEXP_BASE wxFFileStream
: public wxFFileInputStream
,
192 public wxFFileOutputStream
195 wxFFileStream(const wxString
& fileName
, const wxString
& mode
= "w+b");
196 virtual bool IsOk() const;
199 DECLARE_NO_COPY_CLASS(wxFFileStream
)
204 #endif // wxUSE_STREAMS
206 #endif // _WX_WXFSTREAM_H__