* 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:
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "wx/string.h"
|
#include "wx/string.h"
|
||||||
#include "wx/filefn.h"
|
#include "wx/filefn.h"
|
||||||
|
#include "wx/stream.h" // for wxSeekMode
|
||||||
|
|
||||||
// define off_t
|
// define off_t
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -54,8 +55,6 @@ public:
|
|||||||
enum OpenMode { read, write, read_write, write_append };
|
enum OpenMode { read, write, read_write, write_append };
|
||||||
// standard values for file descriptor
|
// standard values for file descriptor
|
||||||
enum { fd_invalid = -1, fd_stdin, fd_stdout, fd_stderr };
|
enum { fd_invalid = -1, fd_stdin, fd_stdout, fd_stderr };
|
||||||
// seek type
|
|
||||||
enum SeekMode { FromStart, FromEnd, FromCurrent };
|
|
||||||
|
|
||||||
// static functions
|
// static functions
|
||||||
// ----------------
|
// ----------------
|
||||||
@@ -84,7 +83,7 @@ public:
|
|||||||
// returns number of bytes read or ofsInvalid on error
|
// returns number of bytes read or ofsInvalid on error
|
||||||
off_t Read(void *pBuf, off_t nCount);
|
off_t Read(void *pBuf, off_t nCount);
|
||||||
// returns true on success
|
// returns true on success
|
||||||
bool Write(const void *pBuf, uint nCount);
|
uint Write(const void *pBuf, uint nCount);
|
||||||
// returns true on success
|
// returns true on success
|
||||||
bool Write(const wxString& str) { return Write(str.c_str(), str.Len()); }
|
bool Write(const wxString& str) { return Write(str.c_str(), str.Len()); }
|
||||||
// flush data not yet written
|
// flush data not yet written
|
||||||
@@ -92,9 +91,9 @@ public:
|
|||||||
|
|
||||||
// file pointer operations (return ofsInvalid on failure)
|
// file pointer operations (return ofsInvalid on failure)
|
||||||
// move ptr ofs bytes related to start/current off_t/end of file
|
// 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
|
// 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
|
// get current off_t
|
||||||
off_t Tell() const;
|
off_t Tell() const;
|
||||||
// get current file length
|
// get current file length
|
||||||
@@ -105,6 +104,8 @@ public:
|
|||||||
bool IsOpened() const { return m_fd != fd_invalid; }
|
bool IsOpened() const { return m_fd != fd_invalid; }
|
||||||
// is end of file reached?
|
// is end of file reached?
|
||||||
bool Eof() const;
|
bool Eof() const;
|
||||||
|
// is an error occured?
|
||||||
|
bool Error() const { return m_error; }
|
||||||
|
|
||||||
// dtor closes the file if opened
|
// dtor closes the file if opened
|
||||||
~wxFile();
|
~wxFile();
|
||||||
@@ -117,6 +118,7 @@ private:
|
|||||||
wxFile& operator=(const wxFile&);
|
wxFile& operator=(const wxFile&);
|
||||||
|
|
||||||
int m_fd; // file descriptor or INVALID_FD if not opened
|
int m_fd; // file descriptor or INVALID_FD if not opened
|
||||||
|
bool m_error; // error memory
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -11,58 +11,65 @@
|
|||||||
#ifndef __WXFSTREAM_H__
|
#ifndef __WXFSTREAM_H__
|
||||||
#define __WXFSTREAM_H__
|
#define __WXFSTREAM_H__
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <wx/object.h>
|
#include <wx/object.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
#include <wx/stream.h>
|
#include <wx/stream.h>
|
||||||
|
#include <wx/file.h>
|
||||||
|
|
||||||
class wxFileStreamBase: public wxStream {
|
class wxFileInputStream: virtual public wxFile, public wxInputStream {
|
||||||
DECLARE_CLASS(wxFileStreamBase)
|
DECLARE_CLASS(wxFileInputStream)
|
||||||
public:
|
public:
|
||||||
wxFileStreamBase(const wxString& fileName, int iolimit);
|
wxFileInputStream(const wxString& fileName);
|
||||||
virtual ~wxFileStreamBase();
|
virtual ~wxFileInputStream();
|
||||||
|
|
||||||
wxInputStream& Read(void *buffer, size_t size);
|
wxInputStream& Read(void *buffer, size_t size);
|
||||||
size_t SeekI(int pos, wxWhenceType whence = wxBeginPosition);
|
off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
|
||||||
size_t TellI() const;
|
off_t TellI() const;
|
||||||
|
|
||||||
bool Eof() const { return m_eof; }
|
bool Eof() const { return m_eof; }
|
||||||
size_t LastRead() const { return m_lastread; }
|
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);
|
wxOutputStream& Write(const void *buffer, size_t size);
|
||||||
size_t SeekO(int pos, wxWhenceType whence = wxBeginPosition);
|
off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
|
||||||
size_t TellO() const;
|
off_t TellO() const;
|
||||||
|
|
||||||
bool Bad() const { return m_bad; }
|
bool Bad() const { return m_bad; }
|
||||||
size_t LastWrite() const { return m_lastwrite; }
|
size_t LastWrite() const { return m_lastwrite; }
|
||||||
|
|
||||||
void Sync();
|
void Sync();
|
||||||
|
|
||||||
|
bool IsOpened() const { return wxFile::IsOpened(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
size_t m_lastread, m_lastwrite;
|
wxFileOutputStream() {}
|
||||||
bool m_eof, m_bad;
|
|
||||||
FILE *m_file;
|
protected:
|
||||||
|
bool m_bad;
|
||||||
|
size_t m_lastwrite;
|
||||||
};
|
};
|
||||||
|
|
||||||
class wxFileInputStream: public wxFileStreamBase {
|
class wxFileStream: public wxFileInputStream, public wxFileOutputStream {
|
||||||
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 {
|
|
||||||
DECLARE_CLASS(wxFileStream)
|
DECLARE_CLASS(wxFileStream)
|
||||||
public:
|
public:
|
||||||
wxFileStream(const wxString& fileName) : wxFileStreamBase(fileName, 0) {}
|
wxFileStream(const wxString& fileName);
|
||||||
virtual ~wxFileStream() {}
|
virtual ~wxFileStream();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -11,67 +11,68 @@
|
|||||||
#ifndef __WXMMSTREAM_H__
|
#ifndef __WXMMSTREAM_H__
|
||||||
#define __WXMMSTREAM_H__
|
#define __WXMMSTREAM_H__
|
||||||
|
|
||||||
#include "wx/object.h"
|
#include <wx/stream.h>
|
||||||
#include "wx/stream.h"
|
|
||||||
|
|
||||||
class wxMemoryStreamBase: public wxStream {
|
class wxMemoryStreamBase {
|
||||||
DECLARE_CLASS(wxMemoryStreamBase)
|
protected:
|
||||||
public:
|
wxMemoryStreamBase();
|
||||||
wxMemoryStreamBase(char *data, size_t length, int iolimit);
|
|
||||||
virtual ~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);
|
bool ChangeBufferSize(size_t new_length);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_bad, m_eof, m_persistent;
|
bool m_persistent;
|
||||||
size_t m_lastread, m_lastwrite;
|
|
||||||
size_t m_length;
|
size_t m_length;
|
||||||
size_t m_position_i, m_position_o;
|
|
||||||
char *m_buffer;
|
char *m_buffer;
|
||||||
int m_iolimit;
|
int m_iolimit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class wxMemoryInputStream: virtual public wxMemoryStreamBase, public wxInputStream {
|
||||||
class wxMemoryInputStream: public wxMemoryStreamBase {
|
|
||||||
DECLARE_CLASS(wxMemoryInputStream)
|
DECLARE_CLASS(wxMemoryInputStream)
|
||||||
public:
|
public:
|
||||||
wxMemoryInputStream(char *data, size_t length)
|
wxMemoryInputStream(const char *data, size_t length);
|
||||||
: wxMemoryStreamBase(data, length, 1)
|
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 {
|
class wxMemoryOutputStream: virtual public wxMemoryStreamBase, public wxOutputStream {
|
||||||
DECLARE_DYNAMIC_CLASS(wxMemoryOutputStream)
|
DECLARE_CLASS(wxMemoryOutputStream)
|
||||||
public:
|
public:
|
||||||
wxMemoryOutputStream(char *data = NULL, size_t length = 0)
|
wxMemoryOutputStream(char *data = NULL, size_t length = 0);
|
||||||
: wxMemoryStreamBase(data, length, 2)
|
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 {
|
class wxMemoryStream: public wxMemoryInputStream, public wxMemoryOutputStream {
|
||||||
DECLARE_DYNAMIC_CLASS(wxMemoryStream)
|
DECLARE_CLASS(wxMemoryStream)
|
||||||
public:
|
public:
|
||||||
wxMemoryStream(char *data = NULL, size_t length = 0)
|
wxMemoryStream(char *data = NULL, size_t length = 0);
|
||||||
: wxMemoryStreamBase(data, length, 0)
|
virtual ~wxMemoryStream();
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
#define __WXSTREAM_H__
|
#define __WXSTREAM_H__
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma interface "stream.h"
|
#pragma interface
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -25,11 +25,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
wxBeginPosition = 0, wxCurrentPosition = 1, wxEndPosition = 2
|
wxFromStart, wxFromCurrent, wxFromEnd
|
||||||
} wxWhenceType;
|
} wxSeekMode;
|
||||||
|
|
||||||
class wxOutputStream;
|
class wxOutputStream;
|
||||||
class wxInputStream: public wxObject {
|
class wxInputStream: virtual public wxObject {
|
||||||
DECLARE_ABSTRACT_CLASS(wxInputStream)
|
DECLARE_ABSTRACT_CLASS(wxInputStream)
|
||||||
public:
|
public:
|
||||||
wxInputStream();
|
wxInputStream();
|
||||||
@@ -38,14 +38,14 @@ class wxInputStream: public wxObject {
|
|||||||
virtual wxInputStream& Read(void *buffer, size_t size) = 0;
|
virtual wxInputStream& Read(void *buffer, size_t size) = 0;
|
||||||
wxInputStream& Read(wxOutputStream& stream_out);
|
wxInputStream& Read(wxOutputStream& stream_out);
|
||||||
|
|
||||||
virtual size_t SeekI(int pos, wxWhenceType whence = wxBeginPosition) = 0;
|
virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart) = 0;
|
||||||
virtual size_t TellI() const = 0;
|
virtual off_t TellI() const = 0;
|
||||||
|
|
||||||
virtual bool Eof() const = 0;
|
virtual bool Eof() const = 0;
|
||||||
virtual size_t LastRead() const = 0;
|
virtual size_t LastRead() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class wxOutputStream: public wxObject {
|
class wxOutputStream: virtual public wxObject {
|
||||||
DECLARE_ABSTRACT_CLASS(wxOutputStream)
|
DECLARE_ABSTRACT_CLASS(wxOutputStream)
|
||||||
public:
|
public:
|
||||||
wxOutputStream();
|
wxOutputStream();
|
||||||
@@ -54,8 +54,8 @@ class wxOutputStream: public wxObject {
|
|||||||
virtual wxOutputStream& Write(const void *buffer, size_t size) = 0;
|
virtual wxOutputStream& Write(const void *buffer, size_t size) = 0;
|
||||||
wxOutputStream& Write(wxInputStream& stream_in);
|
wxOutputStream& Write(wxInputStream& stream_in);
|
||||||
|
|
||||||
virtual size_t SeekO(int pos, wxWhenceType whence = wxBeginPosition) = 0;
|
virtual off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart) = 0;
|
||||||
virtual size_t TellO() const = 0;
|
virtual off_t TellO() const = 0;
|
||||||
|
|
||||||
virtual bool Bad() const = 0;
|
virtual bool Bad() const = 0;
|
||||||
virtual size_t LastWrite() const = 0;
|
virtual size_t LastWrite() const = 0;
|
||||||
@@ -63,11 +63,10 @@ class wxOutputStream: public wxObject {
|
|||||||
virtual void Sync() {}
|
virtual void Sync() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class wxStream: public wxInputStream, public wxOutputStream {
|
class wxStream: virtual public wxInputStream, virtual public wxOutputStream {
|
||||||
DECLARE_ABSTRACT_CLASS(wxStream)
|
|
||||||
public:
|
public:
|
||||||
wxStream() : wxInputStream(), wxOutputStream() {}
|
wxStream() {}
|
||||||
virtual ~wxStream() {}
|
virtual ~wxStream() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -82,11 +81,12 @@ class wxFilterInputStream: public wxInputStream {
|
|||||||
|
|
||||||
virtual wxInputStream& Read(void *buffer, size_t size)
|
virtual wxInputStream& Read(void *buffer, size_t size)
|
||||||
{ return m_parent_i_stream->Read(buffer, size); }
|
{ return m_parent_i_stream->Read(buffer, size); }
|
||||||
virtual size_t SeekI(int pos, wxWhenceType whence = wxBeginPosition)
|
virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart)
|
||||||
{ return m_parent_i_stream->SeekI(pos, whence); }
|
{ return m_parent_i_stream->SeekI(pos, mode); }
|
||||||
|
|
||||||
virtual bool Eof() const { return m_parent_i_stream->Eof(); }
|
virtual bool Eof() const { return m_parent_i_stream->Eof(); }
|
||||||
virtual size_t LastRead() const { return m_parent_i_stream->LastRead(); }
|
virtual size_t LastRead() const { return m_parent_i_stream->LastRead(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxInputStream *m_parent_i_stream;
|
wxInputStream *m_parent_i_stream;
|
||||||
};
|
};
|
||||||
@@ -99,8 +99,8 @@ class wxFilterOutputStream: public wxOutputStream {
|
|||||||
|
|
||||||
virtual wxOutputStream& Write(const void *buffer, size_t size)
|
virtual wxOutputStream& Write(const void *buffer, size_t size)
|
||||||
{ return m_parent_o_stream->Write(buffer, size); }
|
{ return m_parent_o_stream->Write(buffer, size); }
|
||||||
virtual size_t SeekO(int pos, wxWhenceType whence = wxBeginPosition)
|
virtual off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart)
|
||||||
{ return m_parent_o_stream->SeekO(pos, whence); }
|
{ return m_parent_o_stream->SeekO(pos, mode); }
|
||||||
|
|
||||||
virtual bool Bad() const { return m_parent_o_stream->Bad(); }
|
virtual bool Bad() const { return m_parent_o_stream->Bad(); }
|
||||||
virtual size_t LastWrite() const { return m_parent_o_stream->LastWrite(); }
|
virtual size_t LastWrite() const { return m_parent_o_stream->LastWrite(); }
|
||||||
|
63
include/wx/zstream.h
Normal file
63
include/wx/zstream.h
Normal 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
|
@@ -58,6 +58,7 @@ LIB_CPP_SRC=\
|
|||||||
common/stream.cpp \
|
common/stream.cpp \
|
||||||
common/fstream.cpp \
|
common/fstream.cpp \
|
||||||
common/mstream.cpp \
|
common/mstream.cpp \
|
||||||
|
common/zstream.cpp \
|
||||||
common/datstrm.cpp \
|
common/datstrm.cpp \
|
||||||
\
|
\
|
||||||
gtk/app.cpp \
|
gtk/app.cpp \
|
||||||
|
@@ -105,6 +105,7 @@ bool wxFile::Exists(const char *sz)
|
|||||||
wxFile::wxFile(const char *szFileName, OpenMode mode)
|
wxFile::wxFile(const char *szFileName, OpenMode mode)
|
||||||
{
|
{
|
||||||
m_fd = fd_invalid;
|
m_fd = fd_invalid;
|
||||||
|
m_error = FALSE;
|
||||||
|
|
||||||
Open(szFileName, mode);
|
Open(szFileName, mode);
|
||||||
}
|
}
|
||||||
@@ -202,17 +203,18 @@ off_t wxFile::Read(void *pBuf, off_t nCount)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write
|
// write
|
||||||
bool wxFile::Write(const void *pBuf, uint nCount)
|
uint wxFile::Write(const void *pBuf, uint nCount)
|
||||||
{
|
{
|
||||||
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
|
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
|
||||||
|
|
||||||
int iRc = ::write(m_fd, pBuf, nCount);
|
int iRc = ::write(m_fd, pBuf, nCount);
|
||||||
if ( iRc == -1 ) {
|
if ( iRc == -1 ) {
|
||||||
wxLogSysError("can't write to file descriptor %d", m_fd);
|
wxLogSysError("can't write to file descriptor %d", m_fd);
|
||||||
return FALSE;
|
m_error = TRUE;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return TRUE;
|
return iRc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// flush
|
// flush
|
||||||
@@ -235,21 +237,21 @@ bool wxFile::Flush()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// seek
|
// seek
|
||||||
off_t wxFile::Seek(off_t ofs, SeekMode mode)
|
off_t wxFile::Seek(off_t ofs, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
wxASSERT( IsOpened() );
|
wxASSERT( IsOpened() );
|
||||||
|
|
||||||
int flag = -1;
|
int flag = -1;
|
||||||
switch ( mode ) {
|
switch ( mode ) {
|
||||||
case FromStart:
|
case wxFromStart:
|
||||||
flag = SEEK_SET;
|
flag = SEEK_SET;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FromCurrent:
|
case wxFromCurrent:
|
||||||
flag = SEEK_CUR;
|
flag = SEEK_CUR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FromEnd:
|
case wxFromEnd:
|
||||||
flag = SEEK_END;
|
flag = SEEK_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -13,93 +13,100 @@
|
|||||||
#pragma implementation "fstream.h"
|
#pragma implementation "fstream.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <wx/object.h>
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wx/stream.h>
|
#include <wx/stream.h>
|
||||||
#include <wx/fstream.h>
|
#include <wx/fstream.h>
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define BUF_TEMP_SIZE 10000
|
#define BUF_TEMP_SIZE 10000
|
||||||
|
|
||||||
#if !USE_SHARED_LIBRARY
|
#if !USE_SHARED_LIBRARY
|
||||||
IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
|
IMPLEMENT_CLASS(wxFileInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
|
IMPLEMENT_CLASS(wxFileOutputStream, wxOutputStream)
|
||||||
IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
|
IMPLEMENT_CLASS2(wxFileStream, wxInputStream, wxOutputStream)
|
||||||
IMPLEMENT_CLASS(wxFileStream, wxFileStreamBase)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxFileStreamBase::wxFileStreamBase(const wxString& fileName, int iolimit)
|
// ----------------------------------------------------------------------------
|
||||||
: wxStream()
|
// wxFileInputStream
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxFileInputStream::wxFileInputStream(const wxString& fileName)
|
||||||
|
: wxFile(fileName, read)
|
||||||
{
|
{
|
||||||
char *open_mode;
|
m_lastread = 0;
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
m_eof = FALSE;
|
|
||||||
m_bad = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileStreamBase::~wxFileStreamBase()
|
wxFileInputStream::~wxFileInputStream()
|
||||||
{
|
{
|
||||||
fclose(m_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxInputStream& wxFileStreamBase::Read(void *buffer, size_t size)
|
wxInputStream& wxFileInputStream::Read(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
m_lastread = fread(buffer, 1, size, m_file);
|
m_lastread = wxFile::Read(buffer, size);
|
||||||
m_eof = feof(m_file);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxOutputStream& wxFileStreamBase::Write(const void *buffer, size_t size)
|
off_t wxFileInputStream::SeekI(off_t pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
m_lastwrite = fwrite(buffer, 1, size, m_file);
|
return wxFile::Seek(pos, mode);
|
||||||
m_bad = ferror(m_file) != 0;
|
}
|
||||||
|
|
||||||
|
off_t wxFileInputStream::TellI() const
|
||||||
|
{
|
||||||
|
return wxFile::Tell();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxFileOutputStream
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
|
||||||
|
: wxFile(fileName, write)
|
||||||
|
{
|
||||||
|
m_lastwrite = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxFileOutputStream::~wxFileOutputStream()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxOutputStream& wxFileOutputStream::Write(const void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
m_lastwrite = wxFile::Write(buffer, size);
|
||||||
|
m_bad = wxFile::Error();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileStreamBase::SeekI(int pos, wxWhenceType whence)
|
off_t wxFileOutputStream::TellO() const
|
||||||
{
|
{
|
||||||
int real_whence;
|
return wxFile::Tell();
|
||||||
|
|
||||||
if (whence == wxBeginPosition)
|
|
||||||
real_whence = SEEK_SET;
|
|
||||||
else if (whence == wxCurrentPosition)
|
|
||||||
real_whence = SEEK_CUR;
|
|
||||||
else if (whence == wxEndPosition)
|
|
||||||
real_whence = SEEK_END;
|
|
||||||
|
|
||||||
fseek(m_file, pos, real_whence);
|
|
||||||
return ftell(m_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileStreamBase::TellI() const
|
off_t wxFileOutputStream::SeekO(off_t pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
return ftell(m_file);
|
return wxFile::Seek(pos, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileStreamBase::TellO() const
|
void wxFileOutputStream::Sync()
|
||||||
{
|
{
|
||||||
return ftell(m_file);
|
wxFile::Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxFileStreamBase::SeekO(int pos, wxWhenceType whence)
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxFileStream
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxFileStream::wxFileStream(const wxString& fileName)
|
||||||
|
: wxFile(fileName, read_write)
|
||||||
{
|
{
|
||||||
return SeekI(pos, whence);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileStreamBase::Sync()
|
wxFileStream::~wxFileStream()
|
||||||
{
|
{
|
||||||
fflush(m_file);
|
|
||||||
}
|
}
|
||||||
|
@@ -13,32 +13,69 @@
|
|||||||
#pragma implementation "mstream.h"
|
#pragma implementation "mstream.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "wx/stream.h"
|
#include <wx/stream.h>
|
||||||
#include "wx/mstream.h"
|
#include <wx/mstream.h>
|
||||||
|
|
||||||
#if !USE_SHARED_LIBRARY
|
#ifdef __BORLANDC__
|
||||||
IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream)
|
#pragma hdrstop
|
||||||
IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase)
|
|
||||||
//IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase)
|
|
||||||
//IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxMemoryStreamBase::wxMemoryStreamBase(char *data, size_t length, int iolimit)
|
#if !USE_SHARED_LIBRARY
|
||||||
|
IMPLEMENT_CLASS(wxMemoryInputStream, wxInputStream)
|
||||||
|
IMPLEMENT_CLASS(wxMemoryOutputStream, wxOutputStream)
|
||||||
|
IMPLEMENT_CLASS2(wxMemoryStream, wxInputStream, wxOutputStream)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxMemoryStreamBase
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
wxMemoryStreamBase::wxMemoryStreamBase()
|
||||||
{
|
{
|
||||||
m_buffer = data;
|
m_buffer = NULL;
|
||||||
m_iolimit = iolimit;
|
m_iolimit = 0;
|
||||||
m_persistent = FALSE;
|
m_persistent = FALSE;
|
||||||
m_length = length;
|
m_length = 0;
|
||||||
m_position_i = m_position_o = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMemoryStreamBase::~wxMemoryStreamBase()
|
wxMemoryStreamBase::~wxMemoryStreamBase()
|
||||||
{
|
{
|
||||||
free(m_buffer);
|
if (!m_persistent && m_buffer)
|
||||||
|
free(m_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxInputStream& wxMemoryStreamBase::Read(void *buffer, size_t size)
|
bool wxMemoryStreamBase::ChangeBufferSize(size_t new_size)
|
||||||
|
{
|
||||||
|
if (m_iolimit == 1)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
m_length = new_size;
|
||||||
|
if (!m_buffer)
|
||||||
|
m_buffer = (char *)malloc(m_length);
|
||||||
|
else
|
||||||
|
m_buffer = (char *)realloc(m_buffer, m_length);
|
||||||
|
|
||||||
|
return (m_buffer != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxMemoryInputStream
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxMemoryInputStream::wxMemoryInputStream(const char *data, size_t len)
|
||||||
|
{
|
||||||
|
m_persistent = TRUE;
|
||||||
|
m_length = len;
|
||||||
|
m_buffer = (char *)data; // It's bad.
|
||||||
|
m_position_i = 0;
|
||||||
|
m_lastread = 0;
|
||||||
|
m_eof = FALSE;
|
||||||
|
m_iolimit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxInputStream& wxMemoryInputStream::Read(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (m_iolimit == 2) {
|
if (m_iolimit == 2) {
|
||||||
m_eof = TRUE;
|
m_eof = TRUE;
|
||||||
@@ -54,24 +91,24 @@ wxInputStream& wxMemoryStreamBase::Read(void *buffer, size_t size)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxMemoryStreamBase::SeekI(int pos, wxWhenceType whence)
|
off_t wxMemoryInputStream::SeekI(off_t pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
if (m_iolimit == 2)
|
if (m_iolimit == 2)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (whence) {
|
switch (mode) {
|
||||||
case wxBeginPosition:
|
case wxFromStart:
|
||||||
if ((size_t)pos > m_length)
|
if ((size_t)pos > m_length)
|
||||||
return m_position_i;
|
return m_position_i;
|
||||||
return (m_position_i = pos);
|
return (m_position_i = pos);
|
||||||
|
|
||||||
case wxCurrentPosition:
|
case wxFromCurrent:
|
||||||
if ((size_t)(m_position_i+pos) > m_length)
|
if ((size_t)(m_position_i+pos) > m_length)
|
||||||
return m_position_i;
|
return m_position_i;
|
||||||
|
|
||||||
return (m_position_i += pos);
|
return (m_position_i += pos);
|
||||||
|
|
||||||
case wxEndPosition:
|
case wxFromEnd:
|
||||||
if ((size_t)(m_length-pos) > m_length)
|
if ((size_t)(m_length-pos) > m_length)
|
||||||
return m_position_i;
|
return m_position_i;
|
||||||
|
|
||||||
@@ -81,7 +118,22 @@ size_t wxMemoryStreamBase::SeekI(int pos, wxWhenceType whence)
|
|||||||
return m_position_i;
|
return m_position_i;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxOutputStream& wxMemoryStreamBase::Write(const void *buffer, size_t size)
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxMemoryOutputStream
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxMemoryOutputStream::wxMemoryOutputStream(char *data, size_t len)
|
||||||
|
{
|
||||||
|
m_persistent = FALSE;
|
||||||
|
m_buffer = data;
|
||||||
|
m_length = len;
|
||||||
|
m_position_o = 0;
|
||||||
|
m_lastwrite = 0;
|
||||||
|
m_bad = FALSE;
|
||||||
|
m_iolimit = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxOutputStream& wxMemoryOutputStream::Write(const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (m_iolimit == 1) {
|
if (m_iolimit == 1) {
|
||||||
m_bad = TRUE;
|
m_bad = TRUE;
|
||||||
@@ -101,24 +153,24 @@ wxOutputStream& wxMemoryStreamBase::Write(const void *buffer, size_t size)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxMemoryStreamBase::SeekO(int pos, wxWhenceType whence)
|
off_t wxMemoryOutputStream::SeekO(off_t pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
if (m_iolimit == 2)
|
if (m_iolimit == 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (whence) {
|
switch (mode) {
|
||||||
case wxBeginPosition:
|
case wxFromStart:
|
||||||
if ((size_t)pos > m_length)
|
if ((size_t)pos > m_length)
|
||||||
return m_position_o;
|
return m_position_o;
|
||||||
return (m_position_o = pos);
|
return (m_position_o = pos);
|
||||||
|
|
||||||
case wxCurrentPosition:
|
case wxFromCurrent:
|
||||||
if ((size_t)(m_position_o+pos) > m_length)
|
if ((size_t)(m_position_o+pos) > m_length)
|
||||||
return m_position_o;
|
return m_position_o;
|
||||||
|
|
||||||
return (m_position_o += pos);
|
return (m_position_o += pos);
|
||||||
|
|
||||||
case wxEndPosition:
|
case wxFromEnd:
|
||||||
if ((size_t)(m_length-pos) > m_length)
|
if ((size_t)(m_length-pos) > m_length)
|
||||||
return m_position_o;
|
return m_position_o;
|
||||||
|
|
||||||
@@ -128,13 +180,19 @@ size_t wxMemoryStreamBase::SeekO(int pos, wxWhenceType whence)
|
|||||||
return m_position_o;
|
return m_position_o;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxMemoryStreamBase::ChangeBufferSize(size_t new_size)
|
// ----------------------------------------------------------------------------
|
||||||
{
|
// wxMemoryStream
|
||||||
m_length = new_size;
|
// ----------------------------------------------------------------------------
|
||||||
if (!m_buffer)
|
|
||||||
m_buffer = (char *)malloc(m_length);
|
|
||||||
else
|
|
||||||
m_buffer = (char *)realloc(m_buffer, m_length);
|
|
||||||
|
|
||||||
return (m_buffer != NULL);
|
wxMemoryStream::wxMemoryStream(char *data, size_t len)
|
||||||
|
: wxMemoryInputStream(NULL, 0), wxMemoryOutputStream(NULL, 0)
|
||||||
|
{
|
||||||
|
m_persistent = FALSE;
|
||||||
|
m_buffer = data;
|
||||||
|
m_length = len;
|
||||||
|
m_iolimit = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxMemoryStream::~wxMemoryStream()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@@ -15,22 +15,15 @@
|
|||||||
|
|
||||||
// For compilers that support precompilation, includes "wx.h".
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
#include "wx/wxprec.h"
|
#include "wx/wxprec.h"
|
||||||
|
#include <wx/stream.h>
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
|
||||||
#include "wx/setup.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wx/object.h"
|
|
||||||
#include "wx/stream.h"
|
|
||||||
|
|
||||||
#if !USE_SHARED_LIBRARY
|
#if !USE_SHARED_LIBRARY
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS2(wxStream, wxInputStream, wxOutputStream)
|
|
||||||
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
|
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
|
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
|
||||||
#endif
|
#endif
|
||||||
|
200
src/common/zstream.cpp
Normal file
200
src/common/zstream.cpp
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: zstream.cpp
|
||||||
|
// Purpose: Compressed stream classes
|
||||||
|
// Author: Guilhem Lavaux
|
||||||
|
// Modified by:
|
||||||
|
// Created: 11/07/98
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) Guilhem Lavaux
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "zstream.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
#include <wx/stream.h>
|
||||||
|
#include <wx/zstream.h>
|
||||||
|
#include <wx/utils.h>
|
||||||
|
#include "zlib.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !USE_SHARED_LIBRARY
|
||||||
|
IMPLEMENT_CLASS(wxZlibInputStream, wxFilterInputStream)
|
||||||
|
IMPLEMENT_CLASS(wxZlibOutputStream, wxFilterOutputStream)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//////////////////////
|
||||||
|
// wxZlibInputStream
|
||||||
|
//////////////////////
|
||||||
|
|
||||||
|
wxZlibInputStream::wxZlibInputStream(wxInputStream& stream)
|
||||||
|
: wxFilterInputStream(stream)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
m_inflate.zalloc = (alloc_func)0;
|
||||||
|
m_inflate.zfree = (free_func)0;
|
||||||
|
m_inflate.opaque = (voidpf)0;
|
||||||
|
|
||||||
|
err = inflateInit(&m_inflate);
|
||||||
|
if (err != Z_OK) {
|
||||||
|
inflateEnd(&m_inflate);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_inflate.avail_in = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxZlibInputStream::~wxZlibInputStream()
|
||||||
|
{
|
||||||
|
inflateEnd(&m_inflate);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxInputStream& wxZlibInputStream::Read(void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
m_inflate.next_out = (unsigned char *)buffer;
|
||||||
|
m_inflate.avail_out = size;
|
||||||
|
m_eof = FALSE;
|
||||||
|
|
||||||
|
while (m_inflate.avail_out > 0) {
|
||||||
|
if (m_inflate.avail_in == 0) {
|
||||||
|
wxFilterInputStream::Read(m_z_buffer, m_z_size);
|
||||||
|
m_inflate.next_in = m_z_buffer;
|
||||||
|
m_inflate.avail_in = wxFilterInputStream::LastRead();
|
||||||
|
if (wxFilterInputStream::Eof()) {
|
||||||
|
m_lastread = size - m_inflate.avail_out;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = inflate(&m_inflate, Z_FINISH);
|
||||||
|
if (err == Z_STREAM_END) {
|
||||||
|
m_lastread = size - m_inflate.avail_out;
|
||||||
|
m_eof = TRUE;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastread = size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t wxZlibInputStream::SeekI(off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t wxZlibInputStream::TellI() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxZlibInputStream::Eof() const
|
||||||
|
{
|
||||||
|
if (!m_eof)
|
||||||
|
return wxFilterInputStream::Eof();
|
||||||
|
return m_eof;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////
|
||||||
|
// wxZlibOutputStream
|
||||||
|
//////////////////////
|
||||||
|
|
||||||
|
wxZlibOutputStream::wxZlibOutputStream(wxOutputStream& stream)
|
||||||
|
: wxFilterOutputStream(stream)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
m_deflate.zalloc = (alloc_func)0;
|
||||||
|
m_deflate.zfree = (free_func)0;
|
||||||
|
m_deflate.opaque = (voidpf)0;
|
||||||
|
|
||||||
|
err = deflateInit(&m_deflate, Z_DEFAULT_COMPRESSION);
|
||||||
|
if (err != Z_OK) {
|
||||||
|
deflateEnd(&m_deflate);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_deflate.avail_in = 0;
|
||||||
|
m_deflate.next_out = m_z_buffer;
|
||||||
|
m_deflate.avail_out = m_z_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxZlibOutputStream::~wxZlibOutputStream()
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
err = deflate(&m_deflate, Z_FINISH);
|
||||||
|
if (err == Z_STREAM_END)
|
||||||
|
break;
|
||||||
|
if (err < 0) {
|
||||||
|
wxDebugMsg("wxZlibOutputStream: error during final deflate");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (m_deflate.avail_out == 0) {
|
||||||
|
wxFilterOutputStream::Write(m_z_buffer, m_z_size);
|
||||||
|
if (wxFilterOutputStream::Bad()) {
|
||||||
|
wxDebugMsg("wxZlibOutputStream: error during final write");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
m_deflate.next_out = m_z_buffer;
|
||||||
|
m_deflate.avail_out = m_z_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wxFilterOutputStream::Write(m_z_buffer, m_z_size-m_deflate.avail_out);
|
||||||
|
|
||||||
|
deflateEnd(&m_deflate);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxOutputStream& wxZlibOutputStream::Write(const void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
m_deflate.next_in = (unsigned char *)buffer;
|
||||||
|
m_deflate.avail_in = size;
|
||||||
|
|
||||||
|
m_bad = FALSE;
|
||||||
|
while (m_deflate.avail_in > 0) {
|
||||||
|
if (m_deflate.avail_out == 0) {
|
||||||
|
wxFilterOutputStream::Write(m_z_buffer, m_z_size);
|
||||||
|
if (wxFilterOutputStream::Bad()) {
|
||||||
|
m_lastwrite = size - m_deflate.avail_in;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deflate.next_out = m_z_buffer;
|
||||||
|
m_deflate.avail_out = m_z_size;
|
||||||
|
}
|
||||||
|
err = deflate(&m_deflate, Z_NO_FLUSH);
|
||||||
|
if (err < 0) {
|
||||||
|
m_bad = TRUE;
|
||||||
|
m_lastwrite = size - m_deflate.avail_in;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_lastwrite = size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t wxZlibOutputStream::SeekO(off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t wxZlibOutputStream::TellO() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxZlibOutputStream::Bad() const
|
||||||
|
{
|
||||||
|
if (!m_bad)
|
||||||
|
return wxFilterOutputStream::Bad();
|
||||||
|
return m_bad;
|
||||||
|
}
|
@@ -348,21 +348,23 @@ IMPLEMENT_DYNAMIC_CLASS(wxProcess, wxEvtHandler)
|
|||||||
#include "wx/stream.h"
|
#include "wx/stream.h"
|
||||||
#include "wx/fstream.h"
|
#include "wx/fstream.h"
|
||||||
#include "wx/mstream.h"
|
#include "wx/mstream.h"
|
||||||
|
#include "wx/zstream.h"
|
||||||
#include "wx/datstrm.h"
|
#include "wx/datstrm.h"
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS2(wxStream, wxInputStream, wxOutputStream)
|
|
||||||
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
|
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
|
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
|
IMPLEMENT_CLASS(wxFileInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
|
IMPLEMENT_CLASS(wxFileOutputStream, wxOutputStream)
|
||||||
IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
|
IMPLEMENT_CLASS2(wxFileStream, wxFileInputStream, wxFileOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream)
|
IMPLEMENT_CLASS(wxMemoryInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase)
|
IMPLEMENT_CLASS(wxMemoryOutputStream, wxOutputStream)
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase)
|
IMPLEMENT_CLASS2(wxMemoryStream, wxMemoryInputStream, wxMemoryOutputStream)
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase)
|
|
||||||
|
IMPLEMENT_CLASS(wxZlibInputStream, wxFilterInputStream)
|
||||||
|
IMPLEMENT_CLASS(wxZlibOutputStream, wxFilterOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
|
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
|
||||||
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
|
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
|
||||||
|
@@ -348,21 +348,23 @@ IMPLEMENT_DYNAMIC_CLASS(wxProcess, wxEvtHandler)
|
|||||||
#include "wx/stream.h"
|
#include "wx/stream.h"
|
||||||
#include "wx/fstream.h"
|
#include "wx/fstream.h"
|
||||||
#include "wx/mstream.h"
|
#include "wx/mstream.h"
|
||||||
|
#include "wx/zstream.h"
|
||||||
#include "wx/datstrm.h"
|
#include "wx/datstrm.h"
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS2(wxStream, wxInputStream, wxOutputStream)
|
|
||||||
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
|
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
|
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
|
IMPLEMENT_CLASS(wxFileInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
|
IMPLEMENT_CLASS(wxFileOutputStream, wxOutputStream)
|
||||||
IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
|
IMPLEMENT_CLASS2(wxFileStream, wxFileInputStream, wxFileOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream)
|
IMPLEMENT_CLASS(wxMemoryInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase)
|
IMPLEMENT_CLASS(wxMemoryOutputStream, wxOutputStream)
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase)
|
IMPLEMENT_CLASS2(wxMemoryStream, wxMemoryInputStream, wxMemoryOutputStream)
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase)
|
|
||||||
|
IMPLEMENT_CLASS(wxZlibInputStream, wxFilterInputStream)
|
||||||
|
IMPLEMENT_CLASS(wxZlibOutputStream, wxFilterOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
|
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
|
||||||
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
|
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
|
||||||
|
@@ -365,18 +365,19 @@ IMPLEMENT_DYNAMIC_CLASS(wxProcess, wxEvtHandler)
|
|||||||
#include "wx/datstrm.h"
|
#include "wx/datstrm.h"
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
|
||||||
IMPLEMENT_ABSTRACT_CLASS2(wxStream, wxInputStream, wxOutputStream)
|
|
||||||
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
|
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
|
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
|
IMPLEMENT_CLASS(wxFileInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
|
IMPLEMENT_CLASS(wxFileOutputStream, wxOutputStream)
|
||||||
IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
|
IMPLEMENT_CLASS2(wxFileStream, wxFileInputStream, wxFileOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream)
|
IMPLEMENT_CLASS(wxMemoryInputStream, wxInputStream)
|
||||||
IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase)
|
IMPLEMENT_CLASS(wxMemoryOutputStream, wxOutputStream)
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase)
|
IMPLEMENT_CLASS2(wxMemoryStream, wxMemoryInputStream, wxMemoryOutputStream)
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase)
|
|
||||||
|
IMPLEMENT_CLASS(wxZlibInputStream, wxFilterInputStream)
|
||||||
|
IMPLEMENT_CLASS(wxZlibOutputStream, wxFilterOutputStream)
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
|
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
|
||||||
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
|
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
|
||||||
|
@@ -108,6 +108,7 @@ COMMONOBJS = \
|
|||||||
$(MSWDIR)\stream.obj \
|
$(MSWDIR)\stream.obj \
|
||||||
$(MSWDIR)\fstream.obj \
|
$(MSWDIR)\fstream.obj \
|
||||||
$(MSWDIR)\mstream.obj \
|
$(MSWDIR)\mstream.obj \
|
||||||
|
$(MSWDIR)\zstream.obj \
|
||||||
$(MSWDIR)\datstrm.obj \
|
$(MSWDIR)\datstrm.obj \
|
||||||
$(MSWDIR)\extended.obj
|
$(MSWDIR)\extended.obj
|
||||||
|
|
||||||
@@ -470,6 +471,8 @@ $(MSWDIR)\datstrm.obj: $(COMMDIR)\datstrm.$(SRCSUFF)
|
|||||||
|
|
||||||
$(MSWDIR)\mstream.obj: $(COMMDIR)\mstream.$(SRCSUFF)
|
$(MSWDIR)\mstream.obj: $(COMMDIR)\mstream.$(SRCSUFF)
|
||||||
|
|
||||||
|
$(MSWDIR)\zstream.obj: $(COMMDIR)\zstream.$(SRCSUFF)
|
||||||
|
|
||||||
$(MSWDIR)\fstream.obj: $(COMMDIR)\fstream.$(SRCSUFF)
|
$(MSWDIR)\fstream.obj: $(COMMDIR)\fstream.$(SRCSUFF)
|
||||||
|
|
||||||
$(MSWDIR)\stream.obj: $(COMMDIR)\stream.$(SRCSUFF)
|
$(MSWDIR)\stream.obj: $(COMMDIR)\stream.$(SRCSUFF)
|
||||||
|
@@ -109,6 +109,7 @@ COMMONOBJS = \
|
|||||||
$(COMMDIR)\stream.obj \
|
$(COMMDIR)\stream.obj \
|
||||||
$(COMMDIR)\fstream.obj \
|
$(COMMDIR)\fstream.obj \
|
||||||
$(COMMDIR)\mstream.obj \
|
$(COMMDIR)\mstream.obj \
|
||||||
|
$(COMMDIR)\zstream.obj \
|
||||||
$(COMMDIR)\datstrm.obj \
|
$(COMMDIR)\datstrm.obj \
|
||||||
$(COMMDIR)\extended.obj
|
$(COMMDIR)\extended.obj
|
||||||
|
|
||||||
|
@@ -114,6 +114,7 @@ COMMONOBJS = \
|
|||||||
$(COMMDIR)/stream.$(OBJSUFF) \
|
$(COMMDIR)/stream.$(OBJSUFF) \
|
||||||
$(COMMDIR)/fstream.$(OBJSUFF) \
|
$(COMMDIR)/fstream.$(OBJSUFF) \
|
||||||
$(COMMDIR)/mstream.$(OBJSUFF) \
|
$(COMMDIR)/mstream.$(OBJSUFF) \
|
||||||
|
$(COMMDIR)/zstream.$(OBJSUFF) \
|
||||||
$(COMMDIR)/datstrm.$(OBJSUFF) \
|
$(COMMDIR)/datstrm.$(OBJSUFF) \
|
||||||
$(COMMDIR)/extended.$(OBJSUFF)
|
$(COMMDIR)/extended.$(OBJSUFF)
|
||||||
|
|
||||||
|
@@ -109,11 +109,11 @@ COMMONOBJS = \
|
|||||||
$(COMMDIR)\y_tab.obj \
|
$(COMMDIR)\y_tab.obj \
|
||||||
$(COMMDIR)\extended.obj \
|
$(COMMDIR)\extended.obj \
|
||||||
$(COMMDIR)\process.obj
|
$(COMMDIR)\process.obj
|
||||||
|
$(COMMDIR)\fstream.obj \
|
||||||
# $(COMMDIR)\fstream.obj \
|
$(COMMDIR)\mstream.obj \
|
||||||
# $(COMMDIR)\mstream.obj \
|
$(COMMDIR)\zstream.obj \
|
||||||
# $(COMMDIR)\datstrm.obj \
|
$(COMMDIR)\stream.obj \
|
||||||
# $(COMMDIR)\stream.obj \
|
$(COMMDIR)\datstrm.obj
|
||||||
|
|
||||||
MSWOBJS = \
|
MSWOBJS = \
|
||||||
$(MSWDIR)\app.obj \
|
$(MSWDIR)\app.obj \
|
||||||
@@ -889,6 +889,26 @@ $(COMMDIR)/time.obj: $*.$(SRCSUFF)
|
|||||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||||
<<
|
<<
|
||||||
|
|
||||||
|
$(COMMDIR)\stream.obj: $*.$(SRCSUFF)
|
||||||
|
cl @<<
|
||||||
|
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||||
|
<<
|
||||||
|
|
||||||
|
$(COMMDIR)\fstream.obj: $*.$(SRCSUFF)
|
||||||
|
cl @<<
|
||||||
|
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||||
|
<<
|
||||||
|
|
||||||
|
$(COMMDIR)\mstream.obj: $*.$(SRCSUFF)
|
||||||
|
cl @<<
|
||||||
|
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||||
|
<<
|
||||||
|
|
||||||
|
$(COMMDIR)\zstream.obj: $*.$(SRCSUFF)
|
||||||
|
cl @<<
|
||||||
|
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||||
|
<<
|
||||||
|
|
||||||
$(COMMDIR)\datstrm.obj: $*.$(SRCSUFF)
|
$(COMMDIR)\datstrm.obj: $*.$(SRCSUFF)
|
||||||
cl @<<
|
cl @<<
|
||||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||||
|
Reference in New Issue
Block a user