#pragma implementation "fstream.h"
#endif
-#include <wx/object.h>
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
#include <stdio.h>
#include <wx/stream.h>
#include <wx/fstream.h>
-#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);
}