]>
git.saurik.com Git - wxWidgets.git/blob - src/common/fstream.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: "File stream" classes
4 // Author: Julian Smart
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "fstream.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #include <wx/stream.h>
20 #include <wx/fstream.h>
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 wxFileInputStream::wxFileInputStream(const wxString
& fileName
)
33 m_file
= new wxFile(fileName
, wxFile::read
);
34 m_file_destroy
= TRUE
;
35 m_i_streambuf
->SetBufferIO(1024);
38 wxFileInputStream::wxFileInputStream()
41 m_file_destroy
= FALSE
;
45 wxFileInputStream::~wxFileInputStream()
51 char wxFileInputStream::Peek()
56 size_t wxFileInputStream::StreamSize() const
58 return m_file
->Length();
61 size_t wxFileInputStream::OnSysRead(void *buffer
, size_t size
)
63 return m_file
->Read(buffer
, size
);
66 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
68 return m_file
->Seek(pos
, mode
);
71 off_t
wxFileInputStream::OnSysTell() const
73 return m_file
->Tell();
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
82 m_file
= new wxFile(fileName
, wxFile::write
);
83 m_file_destroy
= TRUE
;
84 m_o_streambuf
->SetBufferIO(1024);
87 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
90 m_file_destroy
= FALSE
;
91 m_o_streambuf
->SetBufferIO(1024);
94 wxFileOutputStream::wxFileOutputStream()
97 m_o_streambuf
->SetBufferIO(1024);
98 m_file_destroy
= FALSE
;
102 wxFileOutputStream::~wxFileOutputStream()
104 if (m_file_destroy
) {
110 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
112 size_t ret
= m_file
->Write(buffer
, size
);
113 m_lasterror
= wxStream_EOF
; // TODO
117 off_t
wxFileOutputStream::OnSysTell() const
119 return m_file
->Tell();
122 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
124 return m_file
->Seek(pos
, mode
);
127 void wxFileOutputStream::Sync()
129 wxOutputStream::Sync();
133 size_t wxFileOutputStream::StreamSize() const
135 return m_file
->Length();
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
141 wxFileStream::wxFileStream(const wxString
& fileName
)
142 : wxFileInputStream(fileName
), wxFileOutputStream(*wxFileInputStream::m_file
)