1998-07-12 15:24:52 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2005-01-15 23:06:09 +00:00
|
|
|
// Name: wx/wfstream.h
|
1998-07-12 15:24:52 +00:00
|
|
|
// Purpose: File stream classes
|
|
|
|
// Author: Guilhem Lavaux
|
|
|
|
// Modified by:
|
|
|
|
// Created: 11/07/98
|
|
|
|
// Copyright: (c) Guilhem Lavaux
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-07-12 15:24:52 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
1998-09-10 11:41:14 +00:00
|
|
|
|
1998-08-15 00:23:28 +00:00
|
|
|
#ifndef _WX_WXFSTREAM_H__
|
|
|
|
#define _WX_WXFSTREAM_H__
|
1998-07-12 15:24:52 +00:00
|
|
|
|
1999-06-16 06:03:04 +00:00
|
|
|
#include "wx/defs.h"
|
1999-06-15 20:21:59 +00:00
|
|
|
|
2005-02-17 10:42:22 +00:00
|
|
|
#if wxUSE_STREAMS
|
1999-06-15 20:21:59 +00:00
|
|
|
|
1999-08-20 22:52:21 +00:00
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/string.h"
|
|
|
|
#include "wx/stream.h"
|
|
|
|
#include "wx/file.h"
|
1999-08-22 16:12:48 +00:00
|
|
|
#include "wx/ffile.h"
|
|
|
|
|
2005-02-17 10:42:22 +00:00
|
|
|
#if wxUSE_FILE
|
|
|
|
|
1999-08-22 16:12:48 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFileStream using wxFile
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-07-12 15:24:52 +00:00
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxFileInputStream(const wxString& ifileName);
|
|
|
|
wxFileInputStream(wxFile& file);
|
|
|
|
wxFileInputStream(int fd);
|
2006-09-05 20:47:48 +00:00
|
|
|
virtual ~wxFileInputStream();
|
1998-07-12 15:24:52 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset GetLength() const wxOVERRIDE;
|
1998-07-12 15:24:52 +00:00
|
|
|
|
2006-10-08 21:56:55 +00:00
|
|
|
bool Ok() const { return IsOk(); }
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsOk() const wxOVERRIDE;
|
|
|
|
virtual bool IsSeekable() const wxOVERRIDE { return m_file->GetKind() == wxFILE_KIND_DISK; }
|
1998-07-14 12:06:50 +00:00
|
|
|
|
2013-03-09 15:08:44 +00:00
|
|
|
wxFile* GetFile() const { return m_file; }
|
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
protected:
|
|
|
|
wxFileInputStream();
|
1998-07-14 12:06:50 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual size_t OnSysRead(void *buffer, size_t size) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysTell() const wxOVERRIDE;
|
1998-10-14 17:36:50 +00:00
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
protected:
|
|
|
|
wxFile *m_file;
|
|
|
|
bool m_file_destroy;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxFileInputStream);
|
1998-07-14 12:06:50 +00:00
|
|
|
};
|
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxFileOutputStream(const wxString& fileName);
|
|
|
|
wxFileOutputStream(wxFile& file);
|
|
|
|
wxFileOutputStream(int fd);
|
|
|
|
virtual ~wxFileOutputStream();
|
1998-07-12 15:24:52 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
void Sync() wxOVERRIDE;
|
|
|
|
bool Close() wxOVERRIDE { return m_file_destroy ? m_file->Close() : true; }
|
|
|
|
virtual wxFileOffset GetLength() const wxOVERRIDE;
|
1998-07-12 15:24:52 +00:00
|
|
|
|
2006-10-08 21:56:55 +00:00
|
|
|
bool Ok() const { return IsOk(); }
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsOk() const wxOVERRIDE;
|
|
|
|
virtual bool IsSeekable() const wxOVERRIDE { return m_file->GetKind() == wxFILE_KIND_DISK; }
|
1998-07-12 15:24:52 +00:00
|
|
|
|
2013-03-09 15:08:44 +00:00
|
|
|
wxFile* GetFile() const { return m_file; }
|
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
protected:
|
|
|
|
wxFileOutputStream();
|
1998-07-12 15:24:52 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual size_t OnSysWrite(const void *buffer, size_t size) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysTell() const wxOVERRIDE;
|
1998-07-12 15:24:52 +00:00
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
protected:
|
|
|
|
wxFile *m_file;
|
|
|
|
bool m_file_destroy;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxFileOutputStream);
|
1998-07-12 15:24:52 +00:00
|
|
|
};
|
|
|
|
|
2005-03-13 16:20:51 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxTempFileOutputStream(const wxString& fileName);
|
|
|
|
virtual ~wxTempFileOutputStream();
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
bool Close() wxOVERRIDE { return Commit(); }
|
2008-09-21 19:04:42 +00:00
|
|
|
WXDLLIMPEXP_INLINE_BASE virtual bool Commit() { return m_file->Commit(); }
|
|
|
|
WXDLLIMPEXP_INLINE_BASE virtual void Discard() { m_file->Discard(); }
|
2005-03-13 16:20:51 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset GetLength() const wxOVERRIDE { return m_file->Length(); }
|
|
|
|
virtual bool IsSeekable() const wxOVERRIDE { return true; }
|
2005-03-13 16:20:51 +00:00
|
|
|
|
|
|
|
protected:
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual size_t OnSysWrite(const void *buffer, size_t size) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) wxOVERRIDE
|
2005-03-13 16:20:51 +00:00
|
|
|
{ return m_file->Seek(pos, mode); }
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset OnSysTell() const wxOVERRIDE { return m_file->Tell(); }
|
2005-03-13 16:20:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxTempFile *m_file;
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxTempFileOutputStream);
|
2005-03-13 16:20:51 +00:00
|
|
|
};
|
|
|
|
|
2003-07-22 00:24:07 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
|
|
|
|
public wxFileOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxFileStream(const wxString& fileName);
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsOk() const wxOVERRIDE;
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2009-12-27 19:39:55 +00:00
|
|
|
// override (some) virtual functions inherited from both classes to resolve
|
|
|
|
// ambiguities (this wouldn't be necessary if wxStreamBase were a virtual
|
|
|
|
// base class but it isn't)
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsSeekable() const wxOVERRIDE
|
2009-12-27 19:39:55 +00:00
|
|
|
{
|
|
|
|
return wxFileInputStream::IsSeekable();
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset GetLength() const wxOVERRIDE
|
2009-12-27 19:39:55 +00:00
|
|
|
{
|
|
|
|
return wxFileInputStream::GetLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) wxOVERRIDE
|
2009-12-27 19:39:55 +00:00
|
|
|
{
|
|
|
|
return wxFileInputStream::OnSysSeek(pos, mode);
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset OnSysTell() const wxOVERRIDE
|
2009-12-27 19:39:55 +00:00
|
|
|
{
|
|
|
|
return wxFileInputStream::OnSysTell();
|
|
|
|
}
|
|
|
|
|
2003-07-22 00:24:07 +00:00
|
|
|
private:
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxFileStream);
|
1998-10-28 18:29:51 +00:00
|
|
|
};
|
|
|
|
|
2005-02-17 10:42:22 +00:00
|
|
|
#endif //wxUSE_FILE
|
|
|
|
|
|
|
|
#if wxUSE_FFILE
|
|
|
|
|
1999-08-22 16:12:48 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFFileStream using wxFFile
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
|
|
|
|
{
|
|
|
|
public:
|
2007-06-19 11:57:48 +00:00
|
|
|
wxFFileInputStream(const wxString& fileName, const wxString& mode = "rb");
|
2005-01-15 23:06:09 +00:00
|
|
|
wxFFileInputStream(wxFFile& file);
|
|
|
|
wxFFileInputStream(FILE *file);
|
2006-09-05 20:47:48 +00:00
|
|
|
virtual ~wxFFileInputStream();
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset GetLength() const wxOVERRIDE;
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2006-10-08 21:56:55 +00:00
|
|
|
bool Ok() const { return IsOk(); }
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsOk() const wxOVERRIDE;
|
|
|
|
virtual bool IsSeekable() const wxOVERRIDE { return m_file->GetKind() == wxFILE_KIND_DISK; }
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2013-03-09 15:08:44 +00:00
|
|
|
wxFFile* GetFile() const { return m_file; }
|
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
protected:
|
|
|
|
wxFFileInputStream();
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual size_t OnSysRead(void *buffer, size_t size) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysTell() const wxOVERRIDE;
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
protected:
|
|
|
|
wxFFile *m_file;
|
|
|
|
bool m_file_destroy;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxFFileInputStream);
|
1999-08-22 16:12:48 +00:00
|
|
|
};
|
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
2008-06-15 17:34:50 +00:00
|
|
|
wxFFileOutputStream(const wxString& fileName, const wxString& mode = "wb");
|
2005-01-15 23:06:09 +00:00
|
|
|
wxFFileOutputStream(wxFFile& file);
|
|
|
|
wxFFileOutputStream(FILE *file);
|
|
|
|
virtual ~wxFFileOutputStream();
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
void Sync() wxOVERRIDE;
|
|
|
|
bool Close() wxOVERRIDE { return m_file_destroy ? m_file->Close() : true; }
|
|
|
|
virtual wxFileOffset GetLength() const wxOVERRIDE;
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2006-10-08 21:56:55 +00:00
|
|
|
bool Ok() const { return IsOk(); }
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsOk() const wxOVERRIDE;
|
|
|
|
virtual bool IsSeekable() const wxOVERRIDE { return m_file->GetKind() == wxFILE_KIND_DISK; }
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2013-03-09 15:08:44 +00:00
|
|
|
wxFFile* GetFile() const { return m_file; }
|
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
protected:
|
|
|
|
wxFFileOutputStream();
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual size_t OnSysWrite(const void *buffer, size_t size) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) wxOVERRIDE;
|
|
|
|
virtual wxFileOffset OnSysTell() const wxOVERRIDE;
|
1999-08-22 16:12:48 +00:00
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
protected:
|
|
|
|
wxFFile *m_file;
|
|
|
|
bool m_file_destroy;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxFFileOutputStream);
|
1999-08-22 16:12:48 +00:00
|
|
|
};
|
|
|
|
|
2003-07-22 00:24:07 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
|
|
|
|
public wxFFileOutputStream
|
|
|
|
{
|
|
|
|
public:
|
2008-06-15 17:34:50 +00:00
|
|
|
wxFFileStream(const wxString& fileName, const wxString& mode = "w+b");
|
2009-12-27 19:39:55 +00:00
|
|
|
|
|
|
|
// override some virtual functions to resolve ambiguities, just as in
|
|
|
|
// wxFileStream
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsOk() const wxOVERRIDE;
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsSeekable() const wxOVERRIDE
|
2009-12-27 19:39:55 +00:00
|
|
|
{
|
|
|
|
return wxFFileInputStream::IsSeekable();
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset GetLength() const wxOVERRIDE
|
2009-12-27 19:39:55 +00:00
|
|
|
{
|
|
|
|
return wxFFileInputStream::GetLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) wxOVERRIDE
|
2009-12-27 19:39:55 +00:00
|
|
|
{
|
|
|
|
return wxFFileInputStream::OnSysSeek(pos, mode);
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxFileOffset OnSysTell() const wxOVERRIDE
|
2009-12-27 19:39:55 +00:00
|
|
|
{
|
|
|
|
return wxFFileInputStream::OnSysTell();
|
|
|
|
}
|
|
|
|
|
2003-07-22 00:24:07 +00:00
|
|
|
private:
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxFFileStream);
|
1999-08-22 16:12:48 +00:00
|
|
|
};
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2005-02-17 10:42:22 +00:00
|
|
|
#endif //wxUSE_FFILE
|
|
|
|
|
|
|
|
#endif // wxUSE_STREAMS
|
1999-09-13 03:49:33 +00:00
|
|
|
|
2005-01-15 23:06:09 +00:00
|
|
|
#endif // _WX_WXFSTREAM_H__
|