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