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 m_file
->IsOpened(); }
42 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
47 size_t OnSysRead(void *buffer
, size_t size
);
48 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
49 wxFileOffset
OnSysTell() const;
55 DECLARE_NO_COPY_CLASS(wxFileInputStream
)
58 class WXDLLIMPEXP_BASE wxFileOutputStream
: public wxOutputStream
61 wxFileOutputStream(const wxString
& fileName
);
62 wxFileOutputStream(wxFile
& file
);
63 wxFileOutputStream(int fd
);
64 virtual ~wxFileOutputStream();
67 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
68 wxFileOffset
GetLength() const;
70 bool Ok() const { return m_file
->IsOpened(); }
71 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
76 size_t OnSysWrite(const void *buffer
, size_t size
);
77 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
78 wxFileOffset
OnSysTell() const;
84 DECLARE_NO_COPY_CLASS(wxFileOutputStream
)
87 class WXDLLIMPEXP_BASE wxTempFileOutputStream
: public wxOutputStream
90 wxTempFileOutputStream(const wxString
& fileName
);
91 virtual ~wxTempFileOutputStream();
93 bool Close() { return Commit(); }
94 virtual bool Commit() { return m_file
->Commit(); }
95 virtual void Discard() { m_file
->Discard(); }
97 wxFileOffset
GetLength() const { return m_file
->Length(); }
98 bool IsSeekable() const { return true; }
101 size_t OnSysWrite(const void *buffer
, size_t size
);
102 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
)
103 { return m_file
->Seek(pos
, mode
); }
104 wxFileOffset
OnSysTell() const { return m_file
->Tell(); }
109 DECLARE_NO_COPY_CLASS(wxTempFileOutputStream
)
112 class WXDLLIMPEXP_BASE wxFileStream
: public wxFileInputStream
,
113 public wxFileOutputStream
116 wxFileStream(const wxString
& fileName
);
119 DECLARE_NO_COPY_CLASS(wxFileStream
)
126 // ----------------------------------------------------------------------------
127 // wxFFileStream using wxFFile
128 // ----------------------------------------------------------------------------
130 class WXDLLIMPEXP_BASE wxFFileInputStream
: public wxInputStream
133 wxFFileInputStream(const wxString
& fileName
, const wxChar
*mode
= _T("rb"));
134 wxFFileInputStream(wxFFile
& file
);
135 wxFFileInputStream(FILE *file
);
136 virtual ~wxFFileInputStream();
138 wxFileOffset
GetLength() const;
140 bool Ok() const { return m_file
->IsOpened(); }
141 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
144 wxFFileInputStream();
146 size_t OnSysRead(void *buffer
, size_t size
);
147 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
148 wxFileOffset
OnSysTell() const;
154 DECLARE_NO_COPY_CLASS(wxFFileInputStream
)
157 class WXDLLIMPEXP_BASE wxFFileOutputStream
: public wxOutputStream
160 wxFFileOutputStream(const wxString
& fileName
, const wxChar
*mode
= _T("w+b"));
161 wxFFileOutputStream(wxFFile
& file
);
162 wxFFileOutputStream(FILE *file
);
163 virtual ~wxFFileOutputStream();
166 bool Close() { return m_file_destroy
? m_file
->Close() : true; }
167 wxFileOffset
GetLength() const;
169 bool Ok() const { return m_file
->IsOpened(); }
170 bool IsSeekable() const { return m_file
->GetKind() == wxFILE_KIND_DISK
; }
173 wxFFileOutputStream();
175 size_t OnSysWrite(const void *buffer
, size_t size
);
176 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
177 wxFileOffset
OnSysTell() const;
183 DECLARE_NO_COPY_CLASS(wxFFileOutputStream
)
186 class WXDLLIMPEXP_BASE wxFFileStream
: public wxFFileInputStream
,
187 public wxFFileOutputStream
190 wxFFileStream(const wxString
& fileName
);
193 DECLARE_NO_COPY_CLASS(wxFFileStream
)
198 #endif // wxUSE_STREAMS
200 #endif // _WX_WXFSTREAM_H__