]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fstream.cpp
fix for private access for wxTimerProc
[wxWidgets.git] / src / common / fstream.cpp
index 6ebb2b1395c1ee0f907d79d8cdcbb10755d30fa4..14613367e6cedcec8dfa522a411acbe8bd1f82b0 100644 (file)
 #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()
-{
-  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);
+// ----------------------------------------------------------------------------
+// wxFileInputStream
+// ----------------------------------------------------------------------------
 
-  m_eof = FALSE;
-  m_bad = FALSE;
+wxFileInputStream::wxFileInputStream(const wxString& fileName)
+  : wxInputStream()
+{
+  m_file = new wxFile(fileName, wxFile::read);
+  m_file_destroy = TRUE;
+  m_i_streambuf->SetBufferIO(1024);
 }
 
-wxFileStreamBase::~wxFileStreamBase()
+wxFileInputStream::wxFileInputStream()
+  : wxInputStream()
 {
-  fclose(m_file);
+  m_file_destroy = FALSE;
+  m_file = NULL;
 }
 
-wxInputStream& wxFileStreamBase::Read(void *buffer, size_t size)
+wxFileInputStream::~wxFileInputStream()
 {
-  m_lastread = fread(buffer, 1, size, m_file);
-  m_eof = feof(m_file);
-  return *this;
+  if (m_file_destroy)
+    delete m_file;
 }
 
-wxOutputStream& wxFileStreamBase::Write(const void *buffer, size_t size)
+char wxFileInputStream::Peek()
 {
-  m_lastwrite = fwrite(buffer, 1, size, m_file);
-  m_bad = ferror(m_file) != 0;
-  return *this;
+  return 0;
 }
 
-size_t wxFileStreamBase::SeekI(int pos, wxWhenceType whence)
+size_t wxFileInputStream::DoRead(void *buffer, size_t size)
 {
-  int real_whence;
+  return m_file->Read(buffer, size);
+}
 
-  if (whence == wxBeginPosition)
-    real_whence = SEEK_SET;
-  else if (whence == wxCurrentPosition)
-    real_whence = SEEK_CUR;
-  else if (whence == wxEndPosition)
-    real_whence = SEEK_END;
+off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
+{
+  return m_file->Seek(pos, mode);
+}
 
-  fseek(m_file, pos, real_whence);
-  return ftell(m_file);
+off_t wxFileInputStream::DoTellInput() const
+{
+  return m_file->Tell();
 }
 
-size_t wxFileStreamBase::TellI() const
+// ----------------------------------------------------------------------------
+// wxFileOutputStream
+// ----------------------------------------------------------------------------
+
+wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
+{
+  m_file = new wxFile(fileName, wxFile::write);
+  m_file_destroy = TRUE;
+  m_o_streambuf->SetBufferIO(1024);
+}
+
+wxFileOutputStream::wxFileOutputStream()
+  : wxOutputStream()
 {
-  return ftell(m_file);
+  m_o_streambuf->SetBufferIO(1024);
+  m_file_destroy = FALSE;
+  m_file = NULL;
 }
 
-size_t wxFileStreamBase::TellO() const
+wxFileOutputStream::~wxFileOutputStream()
 {
-  return ftell(m_file);
+  if (m_file_destroy) {
+    Sync();
+    delete m_file;
+  }
 }
 
-size_t wxFileStreamBase::SeekO(int pos, wxWhenceType whence)
+size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size)
+{
+  size_t ret = m_file->Write(buffer, size);
+  m_bad = m_file->Error();
+  return ret;
+}
+
+off_t wxFileOutputStream::DoTellOutput() const
+{
+  return m_file->Tell();
+}
+
+off_t wxFileOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode)
+{
+  return m_file->Seek(pos, mode);
+}
+
+void wxFileOutputStream::Sync()
+{
+  wxOutputStream::Sync();
+  m_file->Flush();
+}
+
+// ----------------------------------------------------------------------------
+// wxFileStream
+// ----------------------------------------------------------------------------
+
+wxFileStream::wxFileStream(const wxString& fileName)
+  : wxFileInputStream(), wxFileOutputStream()
 {
-  return SeekI(pos, whence);
+  m_file = new wxFile(fileName, wxFile::read_write);
+  // Reread the initial buffer.
+  m_i_streambuf->SetBufferIO(1024);
 }
 
-void wxFileStreamBase::Sync()
+wxFileStream::~wxFileStream()
 {
-  fflush(m_file);
+  Sync();
+  delete m_file;
 }