X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3d4c6a214ac5b00dbf5e314e369471135db81c0d..6f34921d9369a31de14e4b07e4824e2d701710f0:/src/common/fstream.cpp diff --git a/src/common/fstream.cpp b/src/common/fstream.cpp index 6ebb2b1395..3d0468bbb9 100644 --- a/src/common/fstream.cpp +++ b/src/common/fstream.cpp @@ -13,93 +13,100 @@ #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) + : wxFile(fileName, read) +{ + m_i_streambuf->SetBufferIO(1024); +} + +wxFileInputStream::~wxFileInputStream() +{ +} + +char wxFileInputStream::Peek() +{ + return 0; +} + +size_t wxFileInputStream::DoRead(void *buffer, size_t size) { - 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_eof = FALSE; - m_bad = FALSE; + size_t ret = wxFile::Read(buffer, size); + m_eof = wxFile::Eof(); + + return ret; } -wxFileStreamBase::~wxFileStreamBase() +off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode) { - fclose(m_file); + return wxFile::Seek(pos, mode); } -wxInputStream& wxFileStreamBase::Read(void *buffer, size_t size) +off_t wxFileInputStream::DoTellInput() const { - m_lastread = fread(buffer, 1, size, m_file); - m_eof = feof(m_file); - return *this; + return wxFile::Tell(); } -wxOutputStream& wxFileStreamBase::Write(const void *buffer, size_t size) +// ---------------------------------------------------------------------------- +// wxFileOutputStream +// ---------------------------------------------------------------------------- + +wxFileOutputStream::wxFileOutputStream(const wxString& fileName) + : wxFile(fileName, write) { - m_lastwrite = fwrite(buffer, 1, size, m_file); - m_bad = ferror(m_file) != 0; - return *this; + m_o_streambuf->SetBufferIO(1024); } -size_t wxFileStreamBase::SeekI(int pos, wxWhenceType whence) +wxFileOutputStream::~wxFileOutputStream() { - int real_whence; + Sync(); +} - if (whence == wxBeginPosition) - real_whence = SEEK_SET; - else if (whence == wxCurrentPosition) - real_whence = SEEK_CUR; - else if (whence == wxEndPosition) - real_whence = SEEK_END; +size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size) +{ + size_t ret = wxFile::Write(buffer, size); + m_bad = wxFile::Error(); + return ret; +} - fseek(m_file, pos, real_whence); - return ftell(m_file); +off_t wxFileOutputStream::DoTellOutput() const +{ + return wxFile::Tell(); } -size_t wxFileStreamBase::TellI() const +off_t wxFileOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode) { - return ftell(m_file); + return wxFile::Seek(pos, mode); } -size_t wxFileStreamBase::TellO() const +void wxFileOutputStream::Sync() { - return ftell(m_file); + wxOutputStream::Sync(); + wxFile::Flush(); } -size_t wxFileStreamBase::SeekO(int pos, wxWhenceType whence) +// ---------------------------------------------------------------------------- +// wxFileStream +// ---------------------------------------------------------------------------- + +wxFileStream::wxFileStream(const wxString& fileName) + : wxFile(fileName, read_write) { - return SeekI(pos, whence); } -void wxFileStreamBase::Sync() +wxFileStream::~wxFileStream() { - fflush(m_file); }