* wxStream: I've rewritten the inheritance

* added wxZlib*Stream
* updated makefiles and data.cpp
* modified a bit wxFile so I can use it in wxFile*Stream


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@263 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1998-07-14 12:06:50 +00:00
parent 33d0b396b2
commit 79c3e0e1ae
18 changed files with 588 additions and 224 deletions

View File

@@ -23,6 +23,7 @@
#include "wx/string.h"
#include "wx/filefn.h"
#include "wx/stream.h" // for wxSeekMode
// define off_t
#include <sys/types.h>
@@ -54,8 +55,6 @@ public:
enum OpenMode { read, write, read_write, write_append };
// standard values for file descriptor
enum { fd_invalid = -1, fd_stdin, fd_stdout, fd_stderr };
// seek type
enum SeekMode { FromStart, FromEnd, FromCurrent };
// static functions
// ----------------
@@ -84,7 +83,7 @@ public:
// returns number of bytes read or ofsInvalid on error
off_t Read(void *pBuf, off_t nCount);
// returns true on success
bool Write(const void *pBuf, uint nCount);
uint Write(const void *pBuf, uint nCount);
// returns true on success
bool Write(const wxString& str) { return Write(str.c_str(), str.Len()); }
// flush data not yet written
@@ -92,9 +91,9 @@ public:
// file pointer operations (return ofsInvalid on failure)
// move ptr ofs bytes related to start/current off_t/end of file
off_t Seek(off_t ofs, SeekMode mode = FromStart);
off_t Seek(off_t ofs, wxSeekMode mode = wxFromStart);
// move ptr to ofs bytes before the end
off_t SeekEnd(off_t ofs = 0) { return Seek(ofs, FromEnd); }
off_t SeekEnd(off_t ofs = 0) { return Seek(ofs, wxFromEnd); }
// get current off_t
off_t Tell() const;
// get current file length
@@ -105,6 +104,8 @@ public:
bool IsOpened() const { return m_fd != fd_invalid; }
// is end of file reached?
bool Eof() const;
// is an error occured?
bool Error() const { return m_error; }
// dtor closes the file if opened
~wxFile();
@@ -117,6 +118,7 @@ private:
wxFile& operator=(const wxFile&);
int m_fd; // file descriptor or INVALID_FD if not opened
bool m_error; // error memory
};
// ----------------------------------------------------------------------------

View File

@@ -11,58 +11,65 @@
#ifndef __WXFSTREAM_H__
#define __WXFSTREAM_H__
#include <stdio.h>
#include <wx/object.h>
#include <wx/string.h>
#include <wx/stream.h>
#include <wx/file.h>
class wxFileStreamBase: public wxStream {
DECLARE_CLASS(wxFileStreamBase)
class wxFileInputStream: virtual public wxFile, public wxInputStream {
DECLARE_CLASS(wxFileInputStream)
public:
wxFileStreamBase(const wxString& fileName, int iolimit);
virtual ~wxFileStreamBase();
wxFileInputStream(const wxString& fileName);
virtual ~wxFileInputStream();
wxInputStream& Read(void *buffer, size_t size);
size_t SeekI(int pos, wxWhenceType whence = wxBeginPosition);
size_t TellI() const;
off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
off_t TellI() const;
bool Eof() const { return m_eof; }
size_t LastRead() const { return m_lastread; }
bool Ok() const { return wxFile::IsOpened(); }
protected:
wxFileInputStream() {}
protected:
bool m_eof;
bool m_ok_i;
size_t m_lastread;
};
class wxFileOutputStream: virtual wxFile, public wxOutputStream {
DECLARE_CLASS(wxFileOutputStream)
public:
wxFileOutputStream(const wxString& fileName);
virtual ~wxFileOutputStream();
wxOutputStream& Write(const void *buffer, size_t size);
size_t SeekO(int pos, wxWhenceType whence = wxBeginPosition);
size_t TellO() const;
off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
off_t TellO() const;
bool Bad() const { return m_bad; }
size_t LastWrite() const { return m_lastwrite; }
void Sync();
bool IsOpened() const { return wxFile::IsOpened(); }
protected:
size_t m_lastread, m_lastwrite;
bool m_eof, m_bad;
FILE *m_file;
wxFileOutputStream() {}
protected:
bool m_bad;
size_t m_lastwrite;
};
class wxFileInputStream: public wxFileStreamBase {
DECLARE_CLASS(wxFileInputStream)
public:
wxFileInputStream(const wxString& fileName) : wxFileStreamBase(fileName, 1) {}
virtual ~wxFileInputStream() {}
};
class wxFileOutputStream: public wxFileStreamBase {
DECLARE_CLASS(wxFileOutputStream)
public:
wxFileOutputStream(const wxString& fileName) : wxFileStreamBase(fileName, 2) {}
virtual ~wxFileOutputStream() {}
};
class wxFileStream: public wxFileStreamBase {
class wxFileStream: public wxFileInputStream, public wxFileOutputStream {
DECLARE_CLASS(wxFileStream)
public:
wxFileStream(const wxString& fileName) : wxFileStreamBase(fileName, 0) {}
virtual ~wxFileStream() {}
wxFileStream(const wxString& fileName);
virtual ~wxFileStream();
};
#endif

View File

@@ -11,67 +11,68 @@
#ifndef __WXMMSTREAM_H__
#define __WXMMSTREAM_H__
#include "wx/object.h"
#include "wx/stream.h"
#include <wx/stream.h>
class wxMemoryStreamBase: public wxStream {
DECLARE_CLASS(wxMemoryStreamBase)
public:
wxMemoryStreamBase(char *data, size_t length, int iolimit);
class wxMemoryStreamBase {
protected:
wxMemoryStreamBase();
virtual ~wxMemoryStreamBase();
// Input part
wxInputStream& Read(void *buffer, size_t size);
size_t SeekI(int pos, wxWhenceType whence = wxBeginPosition);
size_t TellI() const { return m_position_i; }
bool Eof() const { return m_eof; }
size_t LastRead() const { return m_lastread; }
// Output part
wxOutputStream& Write(const void *buffer, size_t size);
size_t SeekO(int pos, wxWhenceType whence = wxBeginPosition);
size_t TellO() const { return m_position_o; }
bool Bad() const { return m_bad; }
size_t LastWrite() const { return m_lastwrite; }
void Sync() {}
protected:
bool ChangeBufferSize(size_t new_length);
protected:
bool m_bad, m_eof, m_persistent;
size_t m_lastread, m_lastwrite;
bool m_persistent;
size_t m_length;
size_t m_position_i, m_position_o;
char *m_buffer;
int m_iolimit;
};
class wxMemoryInputStream: public wxMemoryStreamBase {
class wxMemoryInputStream: virtual public wxMemoryStreamBase, public wxInputStream {
DECLARE_CLASS(wxMemoryInputStream)
public:
wxMemoryInputStream(char *data, size_t length)
: wxMemoryStreamBase(data, length, 1)
{}
wxMemoryInputStream(const char *data, size_t length);
virtual ~wxMemoryInputStream();
wxInputStream& Read(void *buffer, size_t size);
off_t SeekI(off_t pos, wxSeekMode mode);
off_t TellI() const { return m_position_i; }
bool Eof() const { return m_eof; }
size_t LastRead() const { return m_lastread; }
protected:
bool m_eof;
off_t m_position_i;
size_t m_lastread;
};
class wxMemoryOutputStream: public wxMemoryStreamBase {
DECLARE_DYNAMIC_CLASS(wxMemoryOutputStream)
class wxMemoryOutputStream: virtual public wxMemoryStreamBase, public wxOutputStream {
DECLARE_CLASS(wxMemoryOutputStream)
public:
wxMemoryOutputStream(char *data = NULL, size_t length = 0)
: wxMemoryStreamBase(data, length, 2)
{}
wxMemoryOutputStream(char *data = NULL, size_t length = 0);
virtual ~wxMemoryOutputStream();
wxOutputStream& Write(const void *buffer, size_t size);
off_t SeekO(off_t pos, wxSeekMode mode);
off_t TellO() const { return m_position_o; }
bool Bad() const { return m_bad; }
size_t LastWrite() const { return m_lastwrite; }
char *GetData() { return m_buffer; }
size_t GetLength() { return m_length; }
protected:
bool m_bad;
off_t m_position_o;
size_t m_lastwrite;
};
class wxMemoryStream: public wxMemoryStreamBase {
DECLARE_DYNAMIC_CLASS(wxMemoryStream)
class wxMemoryStream: public wxMemoryInputStream, public wxMemoryOutputStream {
DECLARE_CLASS(wxMemoryStream)
public:
wxMemoryStream(char *data = NULL, size_t length = 0)
: wxMemoryStreamBase(data, length, 0)
{}
wxMemoryStream(char *data = NULL, size_t length = 0);
virtual ~wxMemoryStream();
};
#endif

View File

@@ -13,7 +13,7 @@
#define __WXSTREAM_H__
#ifdef __GNUG__
#pragma interface "stream.h"
#pragma interface
#endif
#include <stdio.h>
@@ -25,11 +25,11 @@
*/
typedef enum {
wxBeginPosition = 0, wxCurrentPosition = 1, wxEndPosition = 2
} wxWhenceType;
wxFromStart, wxFromCurrent, wxFromEnd
} wxSeekMode;
class wxOutputStream;
class wxInputStream: public wxObject {
class wxInputStream: virtual public wxObject {
DECLARE_ABSTRACT_CLASS(wxInputStream)
public:
wxInputStream();
@@ -38,14 +38,14 @@ class wxInputStream: public wxObject {
virtual wxInputStream& Read(void *buffer, size_t size) = 0;
wxInputStream& Read(wxOutputStream& stream_out);
virtual size_t SeekI(int pos, wxWhenceType whence = wxBeginPosition) = 0;
virtual size_t TellI() const = 0;
virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart) = 0;
virtual off_t TellI() const = 0;
virtual bool Eof() const = 0;
virtual size_t LastRead() const = 0;
};
class wxOutputStream: public wxObject {
class wxOutputStream: virtual public wxObject {
DECLARE_ABSTRACT_CLASS(wxOutputStream)
public:
wxOutputStream();
@@ -54,8 +54,8 @@ class wxOutputStream: public wxObject {
virtual wxOutputStream& Write(const void *buffer, size_t size) = 0;
wxOutputStream& Write(wxInputStream& stream_in);
virtual size_t SeekO(int pos, wxWhenceType whence = wxBeginPosition) = 0;
virtual size_t TellO() const = 0;
virtual off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart) = 0;
virtual off_t TellO() const = 0;
virtual bool Bad() const = 0;
virtual size_t LastWrite() const = 0;
@@ -63,11 +63,10 @@ class wxOutputStream: public wxObject {
virtual void Sync() {}
};
class wxStream: public wxInputStream, public wxOutputStream {
DECLARE_ABSTRACT_CLASS(wxStream)
class wxStream: virtual public wxInputStream, virtual public wxOutputStream {
public:
wxStream() : wxInputStream(), wxOutputStream() {}
virtual ~wxStream() {}
wxStream() {}
virtual ~wxStream() { }
};
/*
@@ -82,11 +81,12 @@ class wxFilterInputStream: public wxInputStream {
virtual wxInputStream& Read(void *buffer, size_t size)
{ return m_parent_i_stream->Read(buffer, size); }
virtual size_t SeekI(int pos, wxWhenceType whence = wxBeginPosition)
{ return m_parent_i_stream->SeekI(pos, whence); }
virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart)
{ return m_parent_i_stream->SeekI(pos, mode); }
virtual bool Eof() const { return m_parent_i_stream->Eof(); }
virtual size_t LastRead() const { return m_parent_i_stream->LastRead(); }
protected:
wxInputStream *m_parent_i_stream;
};
@@ -99,8 +99,8 @@ class wxFilterOutputStream: public wxOutputStream {
virtual wxOutputStream& Write(const void *buffer, size_t size)
{ return m_parent_o_stream->Write(buffer, size); }
virtual size_t SeekO(int pos, wxWhenceType whence = wxBeginPosition)
{ return m_parent_o_stream->SeekO(pos, whence); }
virtual off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart)
{ return m_parent_o_stream->SeekO(pos, mode); }
virtual bool Bad() const { return m_parent_o_stream->Bad(); }
virtual size_t LastWrite() const { return m_parent_o_stream->LastWrite(); }

63
include/wx/zstream.h Normal file
View File

@@ -0,0 +1,63 @@
/////////////////////////////////////////////////////////////////////////////
// Name: zstream.h
// Purpose: Memory stream classes
// Author: Guilhem Lavaux
// Modified by:
// Created: 11/07/98
// RCS-ID: $Id$
// Copyright: (c) Guilhem Lavaux
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WXZSTREAM_H__
#define __WXZSTREAM_H__
#ifdef __GNUG__
#pragma interface
#endif
#include <wx/stream.h>
#include "zlib.h"
class wxZlibInputStream: public wxFilterInputStream {
DECLARE_CLASS(wxZlibInputStream)
public:
wxZlibInputStream(wxInputStream& stream);
virtual ~wxZlibInputStream();
wxInputStream& Read(void *buffer, size_t size);
off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
off_t TellI() const;
size_t LastRead() const { return m_lastread; }
bool Eof() const;
protected:
size_t m_lastread;
size_t m_z_size;
unsigned char *m_z_buffer;
bool m_eof;
struct z_stream_s m_inflate;
};
class wxZlibOutputStream: public wxFilterOutputStream {
DECLARE_CLASS(wxZlibOutputStream)
public:
wxZlibOutputStream(wxOutputStream& stream);
virtual ~wxZlibOutputStream();
wxOutputStream& Write(const void *buffer, size_t size);
off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
off_t TellO() const;
size_t LastWrite() const { return m_lastwrite; }
bool Bad() const;
protected:
size_t m_lastwrite;
size_t m_z_size;
unsigned char *m_z_buffer;
bool m_bad;
struct z_stream_s m_deflate;
};
#endif