X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e49f47aa77457548df1a86f74c285ea3226b3cce..3f659fd6b10a8a5c899eaa99adc76a55322b33fd:/src/common/fstream.cpp diff --git a/src/common/fstream.cpp b/src/common/fstream.cpp index d1bfb0637b..14613367e6 100644 --- a/src/common/fstream.cpp +++ b/src/common/fstream.cpp @@ -23,36 +23,49 @@ #pragma hdrstop #endif -#define BUF_TEMP_SIZE 10000 - // ---------------------------------------------------------------------------- // wxFileInputStream // ---------------------------------------------------------------------------- wxFileInputStream::wxFileInputStream(const wxString& fileName) - : wxFile(fileName, read) + : wxInputStream() { - m_lastread = 0; + m_file = new wxFile(fileName, wxFile::read); + m_file_destroy = TRUE; + m_i_streambuf->SetBufferIO(1024); +} + +wxFileInputStream::wxFileInputStream() + : wxInputStream() +{ + m_file_destroy = FALSE; + m_file = NULL; } wxFileInputStream::~wxFileInputStream() { + if (m_file_destroy) + delete m_file; +} + +char wxFileInputStream::Peek() +{ + return 0; } -wxInputStream& wxFileInputStream::Read(void *buffer, size_t size) +size_t wxFileInputStream::DoRead(void *buffer, size_t size) { - m_lastread = wxFile::Read(buffer, size); - return *this; + return m_file->Read(buffer, size); } -off_t wxFileInputStream::SeekI(off_t pos, wxSeekMode mode) +off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode) { - return wxFile::Seek(pos, mode); + return m_file->Seek(pos, mode); } -off_t wxFileInputStream::TellI() const +off_t wxFileInputStream::DoTellInput() const { - return wxFile::Tell(); + return m_file->Tell(); } // ---------------------------------------------------------------------------- @@ -60,35 +73,49 @@ off_t wxFileInputStream::TellI() const // ---------------------------------------------------------------------------- wxFileOutputStream::wxFileOutputStream(const wxString& fileName) - : wxFile(fileName, write) { - m_lastwrite = 0; + m_file = new wxFile(fileName, wxFile::write); + m_file_destroy = TRUE; + m_o_streambuf->SetBufferIO(1024); +} + +wxFileOutputStream::wxFileOutputStream() + : wxOutputStream() +{ + m_o_streambuf->SetBufferIO(1024); + m_file_destroy = FALSE; + m_file = NULL; } wxFileOutputStream::~wxFileOutputStream() { + if (m_file_destroy) { + Sync(); + delete m_file; + } } -wxOutputStream& wxFileOutputStream::Write(const void *buffer, size_t size) +size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size) { - m_lastwrite = wxFile::Write(buffer, size); - m_bad = wxFile::Error(); - return *this; + size_t ret = m_file->Write(buffer, size); + m_bad = m_file->Error(); + return ret; } -off_t wxFileOutputStream::TellO() const +off_t wxFileOutputStream::DoTellOutput() const { - return wxFile::Tell(); + return m_file->Tell(); } -off_t wxFileOutputStream::SeekO(off_t pos, wxSeekMode mode) +off_t wxFileOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode) { - return wxFile::Seek(pos, mode); + return m_file->Seek(pos, mode); } void wxFileOutputStream::Sync() { - wxFile::Flush(); + wxOutputStream::Sync(); + m_file->Flush(); } // ---------------------------------------------------------------------------- @@ -96,10 +123,15 @@ void wxFileOutputStream::Sync() // ---------------------------------------------------------------------------- wxFileStream::wxFileStream(const wxString& fileName) - : wxFile(fileName, read_write) + : wxFileInputStream(), wxFileOutputStream() { + m_file = new wxFile(fileName, wxFile::read_write); + // Reread the initial buffer. + m_i_streambuf->SetBufferIO(1024); } wxFileStream::~wxFileStream() { + Sync(); + delete m_file; }