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__
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "wfstream.h"
23 #include "wx/object.h"
24 #include "wx/string.h"
25 #include "wx/stream.h"
31 // ----------------------------------------------------------------------------
32 // wxFileStream using wxFile
33 // ----------------------------------------------------------------------------
35 class WXDLLIMPEXP_BASE wxFileInputStream
: public wxInputStream
38 wxFileInputStream(const wxString
& ifileName
);
39 wxFileInputStream(wxFile
& file
);
40 wxFileInputStream(int fd
);
43 wxFileOffset
GetLength() const;
45 bool Ok() const { return m_file
->IsOpened(); }
46 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
51 size_t OnSysRead(void *buffer
, size_t size
);
52 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
53 wxFileOffset
OnSysTell() const;
59 DECLARE_NO_COPY_CLASS(wxFileInputStream
)
62 class WXDLLIMPEXP_BASE wxFileOutputStream
: public wxOutputStream
65 wxFileOutputStream(const wxString
& fileName
);
66 wxFileOutputStream(wxFile
& file
);
67 wxFileOutputStream(int fd
);
68 virtual ~wxFileOutputStream();
71 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
72 wxFileOffset
GetLength() const;
74 bool Ok() const { return m_file
->IsOpened(); }
75 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
80 size_t OnSysWrite(const void *buffer
, size_t size
);
81 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
82 wxFileOffset
OnSysTell() const;
88 DECLARE_NO_COPY_CLASS(wxFileOutputStream
)
91 class WXDLLIMPEXP_BASE wxTempFileOutputStream
: public wxOutputStream
94 wxTempFileOutputStream(const wxString
& fileName
);
95 virtual ~wxTempFileOutputStream();
97 bool Close() { return Commit(); }
98 virtual bool Commit() { return m_file
->Commit(); }
99 virtual void Discard() { m_file
->Discard(); }
101 wxFileOffset
GetLength() const { return m_file
->Length(); }
102 bool IsSeekable() const { return true; }
105 size_t OnSysWrite(const void *buffer
, size_t size
);
106 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
)
107 { return m_file
->Seek(pos
, mode
); }
108 wxFileOffset
OnSysTell() const { return m_file
->Tell(); }
113 DECLARE_NO_COPY_CLASS(wxTempFileOutputStream
)
116 class WXDLLIMPEXP_BASE wxFileStream
: public wxFileInputStream
,
117 public wxFileOutputStream
120 wxFileStream(const wxString
& fileName
);
123 DECLARE_NO_COPY_CLASS(wxFileStream
)
130 // ----------------------------------------------------------------------------
131 // wxFFileStream using wxFFile
132 // ----------------------------------------------------------------------------
134 class WXDLLIMPEXP_BASE wxFFileInputStream
: public wxInputStream
137 wxFFileInputStream(const wxString
& fileName
, const wxChar
*mode
= _T("rb"));
138 wxFFileInputStream(wxFFile
& file
);
139 wxFFileInputStream(FILE *file
);
140 ~wxFFileInputStream();
142 wxFileOffset
GetLength() const;
144 bool Ok() const { return m_file
->IsOpened(); }
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 wxChar
*mode
= _T("w+b"));
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 m_file
->IsOpened(); }
174 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
177 wxFFileOutputStream();
179 size_t OnSysWrite(const void *buffer
, size_t size
);
180 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
181 wxFileOffset
OnSysTell() const;
187 DECLARE_NO_COPY_CLASS(wxFFileOutputStream
)
190 class WXDLLIMPEXP_BASE wxFFileStream
: public wxFFileInputStream
,
191 public wxFFileOutputStream
194 wxFFileStream(const wxString
& fileName
);
197 DECLARE_NO_COPY_CLASS(wxFFileStream
)
202 #endif // wxUSE_STREAMS
204 #endif // _WX_WXFSTREAM_H__