#include "wx/string.h"
#include "wx/filefn.h"
+#include "wx/stream.h" // for wxSeekMode
// define off_t
#include <sys/types.h>
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
// ----------------
// 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
// 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
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();
wxFile& operator=(const wxFile&);
int m_fd; // file descriptor or INVALID_FD if not opened
+ bool m_error; // error memory
};
// ----------------------------------------------------------------------------
#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();
- protected:
- size_t m_lastread, m_lastwrite;
- bool m_eof, m_bad;
- FILE *m_file;
-};
+ bool IsOpened() const { return wxFile::IsOpened(); }
-class wxFileInputStream: public wxFileStreamBase {
- DECLARE_CLASS(wxFileInputStream)
- public:
- wxFileInputStream(const wxString& fileName) : wxFileStreamBase(fileName, 1) {}
- virtual ~wxFileInputStream() {}
-};
+ protected:
+ wxFileOutputStream() {}
-class wxFileOutputStream: public wxFileStreamBase {
- DECLARE_CLASS(wxFileOutputStream)
- public:
- wxFileOutputStream(const wxString& fileName) : wxFileStreamBase(fileName, 2) {}
- virtual ~wxFileOutputStream() {}
+ protected:
+ bool m_bad;
+ size_t m_lastwrite;
};
-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
#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
#define __WXSTREAM_H__
#ifdef __GNUG__
-#pragma interface "stream.h"
+#pragma interface
#endif
#include <stdio.h>
*/
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();
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();
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;
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() { }
};
/*
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;
};
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(); }
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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
common/stream.cpp \
common/fstream.cpp \
common/mstream.cpp \
+ common/zstream.cpp \
common/datstrm.cpp \
\
gtk/app.cpp \
wxFile::wxFile(const char *szFileName, OpenMode mode)
{
m_fd = fd_invalid;
+ m_error = FALSE;
Open(szFileName, mode);
}
}
// write
-bool wxFile::Write(const void *pBuf, uint nCount)
+uint wxFile::Write(const void *pBuf, uint nCount)
{
wxCHECK( (pBuf != NULL) && IsOpened(), 0 );
int iRc = ::write(m_fd, pBuf, nCount);
if ( iRc == -1 ) {
wxLogSysError("can't write to file descriptor %d", m_fd);
- return FALSE;
+ m_error = TRUE;
+ return 0;
}
else
- return TRUE;
+ return iRc;
}
// flush
// ----------------------------------------------------------------------------
// seek
-off_t wxFile::Seek(off_t ofs, SeekMode mode)
+off_t wxFile::Seek(off_t ofs, wxSeekMode mode)
{
wxASSERT( IsOpened() );
int flag = -1;
switch ( mode ) {
- case FromStart:
+ case wxFromStart:
flag = SEEK_SET;
break;
- case FromCurrent:
+ case wxFromCurrent:
flag = SEEK_CUR;
break;
- case FromEnd:
+ case wxFromEnd:
flag = SEEK_END;
break;
#pragma implementation "fstream.h"
#endif
-#include <wx/object.h>
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
#include <stdio.h>
#include <wx/stream.h>
#include <wx/fstream.h>
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+
#define BUF_TEMP_SIZE 10000
#if !USE_SHARED_LIBRARY
-IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
-IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
-IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
-IMPLEMENT_CLASS(wxFileStream, wxFileStreamBase)
+IMPLEMENT_CLASS(wxFileInputStream, wxInputStream)
+IMPLEMENT_CLASS(wxFileOutputStream, wxOutputStream)
+IMPLEMENT_CLASS2(wxFileStream, wxInputStream, wxOutputStream)
#endif
-wxFileStreamBase::wxFileStreamBase(const wxString& fileName, int iolimit)
- : wxStream()
+// ----------------------------------------------------------------------------
+// wxFileInputStream
+// ----------------------------------------------------------------------------
+
+wxFileInputStream::wxFileInputStream(const wxString& fileName)
+ : wxFile(fileName, read)
{
- char *open_mode;
-
- 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;
+ m_lastread = 0;
}
-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_eof = feof(m_file);
+ m_lastread = wxFile::Read(buffer, size);
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);
- m_bad = ferror(m_file) != 0;
- return *this;
+ return wxFile::Seek(pos, mode);
+}
+
+off_t wxFileInputStream::TellI() const
+{
+ return wxFile::Tell();
+}
+
+// ----------------------------------------------------------------------------
+// wxFileOutputStream
+// ----------------------------------------------------------------------------
+
+wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
+ : wxFile(fileName, write)
+{
+ m_lastwrite = 0;
}
-size_t wxFileStreamBase::SeekI(int pos, wxWhenceType whence)
+wxFileOutputStream::~wxFileOutputStream()
{
- int real_whence;
+}
- if (whence == wxBeginPosition)
- real_whence = SEEK_SET;
- else if (whence == wxCurrentPosition)
- real_whence = SEEK_CUR;
- else if (whence == wxEndPosition)
- real_whence = SEEK_END;
+wxOutputStream& wxFileOutputStream::Write(const void *buffer, size_t size)
+{
+ m_lastwrite = wxFile::Write(buffer, size);
+ m_bad = wxFile::Error();
+ return *this;
+}
- fseek(m_file, pos, real_whence);
- return ftell(m_file);
+off_t wxFileOutputStream::TellO() const
+{
+ return wxFile::Tell();
}
-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);
}
#pragma implementation "mstream.h"
#endif
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
#include <stdlib.h>
-#include "wx/stream.h"
-#include "wx/mstream.h"
+#include <wx/stream.h>
+#include <wx/mstream.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
#if !USE_SHARED_LIBRARY
-IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream)
-IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase)
-//IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase)
-//IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase)
+IMPLEMENT_CLASS(wxMemoryInputStream, wxInputStream)
+IMPLEMENT_CLASS(wxMemoryOutputStream, wxOutputStream)
+IMPLEMENT_CLASS2(wxMemoryStream, wxInputStream, wxOutputStream)
#endif
-wxMemoryStreamBase::wxMemoryStreamBase(char *data, size_t length, int iolimit)
+// ----------------------------------------------------------------------------
+// wxMemoryStreamBase
+// ----------------------------------------------------------------------------
+wxMemoryStreamBase::wxMemoryStreamBase()
{
- m_buffer = data;
- m_iolimit = iolimit;
+ m_buffer = NULL;
+ m_iolimit = 0;
m_persistent = FALSE;
- m_length = length;
- m_position_i = m_position_o = 0;
+ m_length = 0;
}
wxMemoryStreamBase::~wxMemoryStreamBase()
{
- free(m_buffer);
+ if (!m_persistent && m_buffer)
+ free(m_buffer);
+}
+
+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& wxMemoryStreamBase::Read(void *buffer, size_t size)
+wxInputStream& wxMemoryInputStream::Read(void *buffer, size_t size)
{
if (m_iolimit == 2) {
m_eof = TRUE;
return *this;
}
-size_t wxMemoryStreamBase::SeekI(int pos, wxWhenceType whence)
+off_t wxMemoryInputStream::SeekI(off_t pos, wxSeekMode mode)
{
if (m_iolimit == 2)
return 0;
- switch (whence) {
- case wxBeginPosition:
+ switch (mode) {
+ case wxFromStart:
if ((size_t)pos > m_length)
return m_position_i;
return (m_position_i = pos);
- case wxCurrentPosition:
+ case wxFromCurrent:
if ((size_t)(m_position_i+pos) > m_length)
return m_position_i;
return (m_position_i += pos);
- case wxEndPosition:
+ case wxFromEnd:
if ((size_t)(m_length-pos) > m_length)
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) {
m_bad = TRUE;
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;
- switch (whence) {
- case wxBeginPosition:
+ switch (mode) {
+ case wxFromStart:
if ((size_t)pos > m_length)
return m_position_o;
return (m_position_o = pos);
- case wxCurrentPosition:
+ case wxFromCurrent:
if ((size_t)(m_position_o+pos) > m_length)
return m_position_o;
return (m_position_o += pos);
- case wxEndPosition:
+ case wxFromEnd:
if ((size_t)(m_length-pos) > m_length)
return m_position_o;
return m_position_o;
}
-bool wxMemoryStreamBase::ChangeBufferSize(size_t new_size)
+// ----------------------------------------------------------------------------
+// wxMemoryStream
+// ----------------------------------------------------------------------------
+
+wxMemoryStream::wxMemoryStream(char *data, size_t len)
+ : wxMemoryInputStream(NULL, 0), wxMemoryOutputStream(NULL, 0)
{
- m_length = new_size;
- if (!m_buffer)
- m_buffer = (char *)malloc(m_length);
- else
- m_buffer = (char *)realloc(m_buffer, m_length);
+ m_persistent = FALSE;
+ m_buffer = data;
+ m_length = len;
+ m_iolimit = 0;
+}
- return (m_buffer != NULL);
+wxMemoryStream::~wxMemoryStream()
+{
}
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
+#include <wx/stream.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
-#ifndef WX_PRECOMP
-#include "wx/setup.h"
-#endif
-
-#include "wx/object.h"
-#include "wx/stream.h"
-
#if !USE_SHARED_LIBRARY
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
-IMPLEMENT_ABSTRACT_CLASS2(wxStream, wxInputStream, wxOutputStream)
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
#endif
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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;
+}
#include "wx/stream.h"
#include "wx/fstream.h"
#include "wx/mstream.h"
+#include "wx/zstream.h"
#include "wx/datstrm.h"
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
-IMPLEMENT_ABSTRACT_CLASS2(wxStream, wxInputStream, wxOutputStream)
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
-IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
-IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
-IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
+IMPLEMENT_CLASS(wxFileInputStream, wxInputStream)
+IMPLEMENT_CLASS(wxFileOutputStream, wxOutputStream)
+IMPLEMENT_CLASS2(wxFileStream, wxFileInputStream, wxFileOutputStream)
-IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream)
-IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase)
-IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase)
-IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase)
+IMPLEMENT_CLASS(wxMemoryInputStream, wxInputStream)
+IMPLEMENT_CLASS(wxMemoryOutputStream, wxOutputStream)
+IMPLEMENT_CLASS2(wxMemoryStream, wxMemoryInputStream, wxMemoryOutputStream)
+
+IMPLEMENT_CLASS(wxZlibInputStream, wxFilterInputStream)
+IMPLEMENT_CLASS(wxZlibOutputStream, wxFilterOutputStream)
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
#include "wx/stream.h"
#include "wx/fstream.h"
#include "wx/mstream.h"
+#include "wx/zstream.h"
#include "wx/datstrm.h"
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
-IMPLEMENT_ABSTRACT_CLASS2(wxStream, wxInputStream, wxOutputStream)
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
-IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
-IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
-IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
+IMPLEMENT_CLASS(wxFileInputStream, wxInputStream)
+IMPLEMENT_CLASS(wxFileOutputStream, wxOutputStream)
+IMPLEMENT_CLASS2(wxFileStream, wxFileInputStream, wxFileOutputStream)
-IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream)
-IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase)
-IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase)
-IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase)
+IMPLEMENT_CLASS(wxMemoryInputStream, wxInputStream)
+IMPLEMENT_CLASS(wxMemoryOutputStream, wxOutputStream)
+IMPLEMENT_CLASS2(wxMemoryStream, wxMemoryInputStream, wxMemoryOutputStream)
+
+IMPLEMENT_CLASS(wxZlibInputStream, wxFilterInputStream)
+IMPLEMENT_CLASS(wxZlibOutputStream, wxFilterOutputStream)
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
#include "wx/datstrm.h"
IMPLEMENT_ABSTRACT_CLASS(wxInputStream, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxOutputStream, wxObject)
-IMPLEMENT_ABSTRACT_CLASS2(wxStream, wxInputStream, wxOutputStream)
IMPLEMENT_CLASS(wxFilterInputStream, wxInputStream)
IMPLEMENT_CLASS(wxFilterOutputStream, wxOutputStream)
-IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
-IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
-IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
+IMPLEMENT_CLASS(wxFileInputStream, wxInputStream)
+IMPLEMENT_CLASS(wxFileOutputStream, wxOutputStream)
+IMPLEMENT_CLASS2(wxFileStream, wxFileInputStream, wxFileOutputStream)
-IMPLEMENT_CLASS(wxMemoryStreamBase, wxStream)
-IMPLEMENT_CLASS(wxMemoryInputStream, wxMemoryStreamBase)
-IMPLEMENT_DYNAMIC_CLASS(wxMemoryOutputStream, wxMemoryStreamBase)
-IMPLEMENT_DYNAMIC_CLASS(wxMemoryStream, wxMemoryStreamBase)
+IMPLEMENT_CLASS(wxMemoryInputStream, wxInputStream)
+IMPLEMENT_CLASS(wxMemoryOutputStream, wxOutputStream)
+IMPLEMENT_CLASS2(wxMemoryStream, wxMemoryInputStream, wxMemoryOutputStream)
+
+IMPLEMENT_CLASS(wxZlibInputStream, wxFilterInputStream)
+IMPLEMENT_CLASS(wxZlibOutputStream, wxFilterOutputStream)
IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream)
IMPLEMENT_CLASS(wxDataOutputStream, wxFilterInputStream)
$(MSWDIR)\stream.obj \
$(MSWDIR)\fstream.obj \
$(MSWDIR)\mstream.obj \
+ $(MSWDIR)\zstream.obj \
$(MSWDIR)\datstrm.obj \
$(MSWDIR)\extended.obj
$(MSWDIR)\mstream.obj: $(COMMDIR)\mstream.$(SRCSUFF)
+$(MSWDIR)\zstream.obj: $(COMMDIR)\zstream.$(SRCSUFF)
+
$(MSWDIR)\fstream.obj: $(COMMDIR)\fstream.$(SRCSUFF)
$(MSWDIR)\stream.obj: $(COMMDIR)\stream.$(SRCSUFF)
$(COMMDIR)\stream.obj \
$(COMMDIR)\fstream.obj \
$(COMMDIR)\mstream.obj \
+ $(COMMDIR)\zstream.obj \
$(COMMDIR)\datstrm.obj \
$(COMMDIR)\extended.obj
$(COMMDIR)/stream.$(OBJSUFF) \
$(COMMDIR)/fstream.$(OBJSUFF) \
$(COMMDIR)/mstream.$(OBJSUFF) \
+ $(COMMDIR)/zstream.$(OBJSUFF) \
$(COMMDIR)/datstrm.$(OBJSUFF) \
$(COMMDIR)/extended.$(OBJSUFF)
$(COMMDIR)\y_tab.obj \
$(COMMDIR)\extended.obj \
$(COMMDIR)\process.obj
-
-# $(COMMDIR)\fstream.obj \
-# $(COMMDIR)\mstream.obj \
-# $(COMMDIR)\datstrm.obj \
-# $(COMMDIR)\stream.obj \
+ $(COMMDIR)\fstream.obj \
+ $(COMMDIR)\mstream.obj \
+ $(COMMDIR)\zstream.obj \
+ $(COMMDIR)\stream.obj \
+ $(COMMDIR)\datstrm.obj
MSWOBJS = \
$(MSWDIR)\app.obj \
$(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)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@