]>
git.saurik.com Git - wxWidgets.git/blob - src/common/wfstream.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: "File stream" classes
4 // Author: Julian Smart
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wfstream.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_STREAMS && wxUSE_FILE
26 #include "wx/stream.h"
27 #include "wx/wfstream.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 wxFileInputStream::wxFileInputStream(const wxString
& fileName
)
36 m_file
= new wxFile(fileName
, wxFile::read
);
37 m_file_destroy
= TRUE
;
40 wxFileInputStream::wxFileInputStream()
43 m_file_destroy
= FALSE
;
47 wxFileInputStream::wxFileInputStream(wxFile
& file
)
50 m_file_destroy
= FALSE
;
53 wxFileInputStream::wxFileInputStream(int fd
)
55 m_file
= new wxFile(fd
);
56 m_file_destroy
= TRUE
;
59 wxFileInputStream::~wxFileInputStream()
65 size_t wxFileInputStream::GetSize() const
67 return m_file
->Length();
70 size_t wxFileInputStream::OnSysRead(void *buffer
, size_t size
)
74 ret
= m_file
->Read(buffer
, size
);
76 m_lasterror
= wxStream_NOERROR
;
78 m_lasterror
= wxStream_EOF
;
79 if (ret
== wxInvalidOffset
) {
80 m_lasterror
= wxStream_READ_ERR
;
87 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
89 return m_file
->Seek(pos
, mode
);
92 off_t
wxFileInputStream::OnSysTell() const
94 return m_file
->Tell();
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
103 m_file
= new wxFile(fileName
, wxFile::write
);
104 m_file_destroy
= TRUE
;
107 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
110 m_file_destroy
= FALSE
;
113 wxFileOutputStream::wxFileOutputStream()
116 m_file_destroy
= FALSE
;
120 wxFileOutputStream::wxFileOutputStream(int fd
)
122 m_file
= new wxFile(fd
);
123 m_file_destroy
= TRUE
;
126 wxFileOutputStream::~wxFileOutputStream()
128 if (m_file_destroy
) {
134 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
136 size_t ret
= m_file
->Write(buffer
, size
);
138 m_lasterror
= wxStream_WRITE_ERR
;
140 m_lasterror
= wxStream_NOERROR
;
144 off_t
wxFileOutputStream::OnSysTell() const
146 return m_file
->Tell();
149 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
151 return m_file
->Seek(pos
, mode
);
154 void wxFileOutputStream::Sync()
156 wxOutputStream::Sync();
160 size_t wxFileOutputStream::GetSize() const
162 return m_file
->Length();
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
168 wxFileStream::wxFileStream(const wxString
& fileName
)
169 : wxFileInputStream(fileName
), wxFileOutputStream(*wxFileInputStream::m_file
)
173 // ----------------------------------------------------------------------------
174 // wxFFileInputStream
175 // ----------------------------------------------------------------------------
177 wxFFileInputStream::wxFFileInputStream(const wxString
& fileName
)
180 m_file
= new wxFFile(fileName
, "r");
181 m_file_destroy
= TRUE
;
184 wxFFileInputStream::wxFFileInputStream()
187 m_file_destroy
= FALSE
;
191 wxFFileInputStream::wxFFileInputStream(wxFFile
& file
)
194 m_file_destroy
= FALSE
;
197 wxFFileInputStream::wxFFileInputStream(FILE *file
)
199 m_file
= new wxFFile(file
);
200 m_file_destroy
= TRUE
;
203 wxFFileInputStream::~wxFFileInputStream()
209 size_t wxFFileInputStream::GetSize() const
211 return m_file
->Length();
214 size_t wxFFileInputStream::OnSysRead(void *buffer
, size_t size
)
218 ret
= m_file
->Read(buffer
, size
);
221 m_lasterror
= wxStream_EOF
;
222 if (ret
== wxInvalidOffset
) {
223 m_lasterror
= wxStream_READ_ERR
;
230 off_t
wxFFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
232 return m_file
->Seek(pos
, mode
);
235 off_t
wxFFileInputStream::OnSysTell() const
237 return m_file
->Tell();
240 // ----------------------------------------------------------------------------
241 // wxFFileOutputStream
242 // ----------------------------------------------------------------------------
244 wxFFileOutputStream::wxFFileOutputStream(const wxString
& fileName
)
246 m_file
= new wxFFile(fileName
, "w+");
247 m_file_destroy
= TRUE
;
250 wxFFileOutputStream::wxFFileOutputStream(wxFFile
& file
)
253 m_file_destroy
= FALSE
;
256 wxFFileOutputStream::wxFFileOutputStream()
259 m_file_destroy
= FALSE
;
263 wxFFileOutputStream::wxFFileOutputStream(FILE *file
)
265 m_file
= new wxFFile(file
);
266 m_file_destroy
= TRUE
;
269 wxFFileOutputStream::~wxFFileOutputStream()
271 if (m_file_destroy
) {
277 size_t wxFFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
279 size_t ret
= m_file
->Write(buffer
, size
);
281 m_lasterror
= wxStream_WRITE_ERR
;
283 m_lasterror
= wxStream_NOERROR
;
287 off_t
wxFFileOutputStream::OnSysTell() const
289 return m_file
->Tell();
292 off_t
wxFFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
294 return m_file
->Seek(pos
, mode
);
297 void wxFFileOutputStream::Sync()
299 wxOutputStream::Sync();
303 size_t wxFFileOutputStream::GetSize() const
305 return m_file
->Length();
308 // ----------------------------------------------------------------------------
310 // ----------------------------------------------------------------------------
311 wxFFileStream::wxFFileStream(const wxString
& fileName
)
312 : wxFFileInputStream(fileName
), wxFFileOutputStream(*wxFFileInputStream::m_file
)
316 // wxUSE_STREAMS && wxUSE_FILE