X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3d4c6a214ac5b00dbf5e314e369471135db81c0d..520e470fdd0daef09c77938db642e4583933c90d:/src/common/fstream.cpp?ds=inline diff --git a/src/common/fstream.cpp b/src/common/fstream.cpp index 6ebb2b1395..7012e2b20a 100644 --- a/src/common/fstream.cpp +++ b/src/common/fstream.cpp @@ -13,93 +13,107 @@ #pragma implementation "fstream.h" #endif -#include +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" #include #include #include -#define BUF_TEMP_SIZE 10000 - -#if !USE_SHARED_LIBRARY -IMPLEMENT_CLASS(wxFileStreamBase, wxStream) -IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase) -IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase) -IMPLEMENT_CLASS(wxFileStream, wxFileStreamBase) +#ifdef __BORLANDC__ +#pragma hdrstop #endif -wxFileStreamBase::wxFileStreamBase(const wxString& fileName, int iolimit) - : wxStream() +// ---------------------------------------------------------------------------- +// wxFileInputStream +// ---------------------------------------------------------------------------- + +wxFileInputStream::wxFileInputStream(const wxString& fileName) + : wxInputStream() { - char *open_mode; - - switch (iolimit) { - case 0: - open_mode = "a+"; - break; - case 1: - open_mode = "rb"; - break; - case 2: - open_mode = "wb"; - break; - } - m_file = fopen(fileName, open_mode); - fseek(m_file, 0, SEEK_SET); + m_file = new wxFile(fileName, wxFile::read); + m_file_destroy = TRUE; + m_i_streambuf->SetBufferIO(1024); +} - m_eof = FALSE; - m_bad = FALSE; +wxFileInputStream::wxFileInputStream() + : wxInputStream() +{ + m_file_destroy = FALSE; + m_file = NULL; } -wxFileStreamBase::~wxFileStreamBase() +wxFileInputStream::~wxFileInputStream() { - fclose(m_file); + if (m_file_destroy) + delete m_file; } -wxInputStream& wxFileStreamBase::Read(void *buffer, size_t size) +char wxFileInputStream::Peek() { - m_lastread = fread(buffer, 1, size, m_file); - m_eof = feof(m_file); - return *this; + return 0; } -wxOutputStream& wxFileStreamBase::Write(const void *buffer, size_t size) +size_t wxFileInputStream::OnSysRead(void *buffer, size_t size) { - m_lastwrite = fwrite(buffer, 1, size, m_file); - m_bad = ferror(m_file) != 0; - return *this; + return m_file->Read(buffer, size); } -size_t wxFileStreamBase::SeekI(int pos, wxWhenceType whence) +off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode) { - int real_whence; + return m_file->Seek(pos, mode); +} + +off_t wxFileInputStream::OnSysTell() const +{ + return m_file->Tell(); +} - if (whence == wxBeginPosition) - real_whence = SEEK_SET; - else if (whence == wxCurrentPosition) - real_whence = SEEK_CUR; - else if (whence == wxEndPosition) - real_whence = SEEK_END; +// ---------------------------------------------------------------------------- +// wxFileOutputStream +// ---------------------------------------------------------------------------- - fseek(m_file, pos, real_whence); - return ftell(m_file); +wxFileOutputStream::wxFileOutputStream(const wxString& fileName) +{ + 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; + } } -size_t wxFileStreamBase::TellI() const +size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size) { - return ftell(m_file); + size_t ret = m_file->Write(buffer, size); + m_lasterror = wxStream_EOF; // TODO + return ret; } -size_t wxFileStreamBase::TellO() const +off_t wxFileOutputStream::OnSysTell() const { - return ftell(m_file); + return m_file->Tell(); } -size_t wxFileStreamBase::SeekO(int pos, wxWhenceType whence) +off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode) { - return SeekI(pos, whence); + return m_file->Seek(pos, mode); } -void wxFileStreamBase::Sync() +void wxFileOutputStream::Sync() { - fflush(m_file); + wxOutputStream::Sync(); + m_file->Flush(); }