* wxFileInputStream and wxFileOutputStream doesn't inherit anymore from wxFile.
* The destructor of wxFile isn't anymore virtual. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@669 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -120,7 +120,7 @@ public:
|
|||||||
bool Error() const { return m_error; }
|
bool Error() const { return m_error; }
|
||||||
|
|
||||||
// dtor closes the file if opened
|
// dtor closes the file if opened
|
||||||
virtual ~wxFile(); // Temporally virtual because of wxFileStream: I'll change back in a near future.
|
~wxFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// copy ctor and assignment operator are private because
|
// copy ctor and assignment operator are private because
|
||||||
|
@@ -16,26 +16,30 @@
|
|||||||
#include <wx/stream.h>
|
#include <wx/stream.h>
|
||||||
#include <wx/file.h>
|
#include <wx/file.h>
|
||||||
|
|
||||||
class wxFileInputStream: public wxInputStream, virtual public wxFile {
|
class wxFileStreamBase {
|
||||||
|
protected:
|
||||||
|
wxFile *m_file;
|
||||||
|
bool m_file_destroy;
|
||||||
|
};
|
||||||
|
|
||||||
|
class wxFileInputStream: public wxInputStream, virtual public wxFileStreamBase {
|
||||||
public:
|
public:
|
||||||
wxFileInputStream(const wxString& fileName);
|
wxFileInputStream(const wxString& fileName);
|
||||||
virtual ~wxFileInputStream();
|
virtual ~wxFileInputStream();
|
||||||
|
|
||||||
virtual char Peek();
|
virtual char Peek();
|
||||||
|
|
||||||
virtual bool Eof() const { return wxFile::Eof(); }
|
bool Ok() const { return m_file->IsOpened(); }
|
||||||
|
|
||||||
bool Ok() const { return wxFile::IsOpened(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxFileInputStream() {}
|
wxFileInputStream();
|
||||||
|
|
||||||
size_t DoRead(void *buffer, size_t size);
|
size_t DoRead(void *buffer, size_t size);
|
||||||
off_t DoSeekInput(off_t pos, wxSeekMode mode);
|
off_t DoSeekInput(off_t pos, wxSeekMode mode);
|
||||||
off_t DoTellInput() const;
|
off_t DoTellInput() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class wxFileOutputStream: public wxOutputStream, virtual public wxFile {
|
class wxFileOutputStream: public wxOutputStream, virtual public wxFileStreamBase {
|
||||||
public:
|
public:
|
||||||
wxFileOutputStream(const wxString& fileName);
|
wxFileOutputStream(const wxString& fileName);
|
||||||
virtual ~wxFileOutputStream();
|
virtual ~wxFileOutputStream();
|
||||||
@@ -46,10 +50,10 @@ class wxFileOutputStream: public wxOutputStream, virtual public wxFile {
|
|||||||
|
|
||||||
void Sync();
|
void Sync();
|
||||||
|
|
||||||
bool Ok() const { return wxFile::IsOpened(); }
|
bool Ok() const { return m_file->IsOpened(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxFileOutputStream() {}
|
wxFileOutputStream();
|
||||||
|
|
||||||
size_t DoWrite(const void *buffer, size_t size);
|
size_t DoWrite(const void *buffer, size_t size);
|
||||||
off_t DoSeekOutput(off_t pos, wxSeekMode mode);
|
off_t DoSeekOutput(off_t pos, wxSeekMode mode);
|
||||||
|
@@ -28,13 +28,24 @@
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxFileInputStream::wxFileInputStream(const wxString& fileName)
|
wxFileInputStream::wxFileInputStream(const wxString& fileName)
|
||||||
: wxFile(fileName, read)
|
: wxInputStream()
|
||||||
{
|
{
|
||||||
|
m_file = new wxFile(fileName, wxFile::read);
|
||||||
|
m_file_destroy = TRUE;
|
||||||
m_i_streambuf->SetBufferIO(1024);
|
m_i_streambuf->SetBufferIO(1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxFileInputStream::wxFileInputStream()
|
||||||
|
: wxInputStream()
|
||||||
|
{
|
||||||
|
m_file_destroy = FALSE;
|
||||||
|
m_file = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
wxFileInputStream::~wxFileInputStream()
|
wxFileInputStream::~wxFileInputStream()
|
||||||
{
|
{
|
||||||
|
if (m_file_destroy)
|
||||||
|
delete m_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
char wxFileInputStream::Peek()
|
char wxFileInputStream::Peek()
|
||||||
@@ -44,17 +55,17 @@ char wxFileInputStream::Peek()
|
|||||||
|
|
||||||
size_t wxFileInputStream::DoRead(void *buffer, size_t size)
|
size_t wxFileInputStream::DoRead(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
return wxFile::Read(buffer, size);
|
return m_file->Read(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFileInputStream::DoSeekInput(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::DoTellInput() const
|
off_t wxFileInputStream::DoTellInput() const
|
||||||
{
|
{
|
||||||
return wxFile::Tell();
|
return m_file->Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -62,37 +73,49 @@ off_t wxFileInputStream::DoTellInput() const
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
|
wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
|
||||||
: wxFile(fileName, write)
|
{
|
||||||
|
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_o_streambuf->SetBufferIO(1024);
|
||||||
|
m_file_destroy = FALSE;
|
||||||
|
m_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileOutputStream::~wxFileOutputStream()
|
wxFileOutputStream::~wxFileOutputStream()
|
||||||
{
|
{
|
||||||
|
if (m_file_destroy) {
|
||||||
Sync();
|
Sync();
|
||||||
|
delete m_file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size)
|
size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t ret = wxFile::Write(buffer, size);
|
size_t ret = m_file->Write(buffer, size);
|
||||||
m_bad = wxFile::Error();
|
m_bad = m_file->Error();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFileOutputStream::DoTellOutput() const
|
off_t wxFileOutputStream::DoTellOutput() const
|
||||||
{
|
{
|
||||||
return wxFile::Tell();
|
return m_file->Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t wxFileOutputStream::DoSeekOutput(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()
|
void wxFileOutputStream::Sync()
|
||||||
{
|
{
|
||||||
wxOutputStream::Sync();
|
wxOutputStream::Sync();
|
||||||
wxFile::Flush();
|
m_file->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -100,10 +123,15 @@ void wxFileOutputStream::Sync()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxFileStream::wxFileStream(const wxString& fileName)
|
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()
|
wxFileStream::~wxFileStream()
|
||||||
{
|
{
|
||||||
|
Sync();
|
||||||
|
delete m_file;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user