#include <wx/stream.h>
-class wxDataInputStream: public virtual wxFilterInputStream {
+class wxDataInputStream: public wxFilterInputStream {
public:
wxDataInputStream(wxInputStream& s);
virtual ~wxDataInputStream();
wxString ReadString();
};
-class wxDataOutputStream: public virtual wxFilterOutputStream {
+class wxDataOutputStream: public wxFilterOutputStream {
public:
wxDataOutputStream(wxOutputStream& s);
virtual ~wxDataOutputStream();
void WriteString(const wxString& string);
};
-class wxDataStream: public wxDataInputStream, public wxDataOutputStream,
- public wxFilterStream {
- public:
- wxDataStream(wxStream& stream);
-};
-
#endif
// _WX_DATSTREAM_H_
#include <wx/stream.h>
#include <wx/file.h>
-// Disable warnings such as
-// 'wxFileStream' : inherits 'wxFileInputStream::Peek' via dominance
-
-#ifdef _MSC_VER
-#pragma warning(disable:4250)
-#endif
-
-class wxFileStreamBase {
-protected:
- wxFile *m_file;
- bool m_file_destroy;
-};
-
-class wxFileInputStream: public virtual wxInputStream,
- public virtual wxFileStreamBase {
+class wxFileInputStream: public wxInputStream {
public:
- wxFileInputStream(const wxString& fileName);
+ wxFileInputStream(const wxString& ifileName);
+ wxFileInputStream(wxFile& file);
+ wxFileInputStream(int fd);
virtual ~wxFileInputStream();
virtual char Peek();
protected:
wxFileInputStream();
- size_t DoRead(void *buffer, size_t size);
- off_t DoSeekInput(off_t pos, wxSeekMode mode);
- off_t DoTellInput() const;
+ size_t OnSysRead(void *buffer, size_t size);
+ off_t OnSysSeek(off_t pos, wxSeekMode mode);
+ off_t OnSysTell() const;
+
+ protected:
+ wxFile *m_file;
+ bool m_file_destroy;
};
-class wxFileOutputStream: public virtual wxOutputStream,
- public virtual wxFileStreamBase {
+class wxFileOutputStream: public wxOutputStream {
public:
wxFileOutputStream(const wxString& fileName);
+ wxFileOutputStream(wxFile& file);
+ wxFileOutputStream(int fd);
virtual ~wxFileOutputStream();
// To solve an ambiguity on GCC
protected:
wxFileOutputStream();
- size_t DoWrite(const void *buffer, size_t size);
- off_t DoSeekOutput(off_t pos, wxSeekMode mode);
- off_t DoTellOutput() const;
-};
+ size_t OnSysWrite(const void *buffer, size_t size);
+ off_t OnSysSeek(off_t pos, wxSeekMode mode);
+ off_t OnSysTell() const;
-class wxFileStream: public wxStream,
- public wxFileInputStream, public wxFileOutputStream {
- public:
- wxFileStream(const wxString& fileName);
- virtual ~wxFileStream();
+ protected:
+ wxFile *m_file;
+ bool m_file_destroy;
};
-#ifdef _MSC_VER
-#pragma warning(default:4250)
-#endif
-
#endif
#include <wx/stream.h>
-class wxMemoryStreamBase {
- protected:
- wxMemoryStreamBase();
- virtual ~wxMemoryStreamBase();
-
- bool ChangeBufferSize(size_t new_length);
-
- protected:
- bool m_persistent;
- size_t m_length;
- char *m_buffer;
- int m_iolimit;
-};
-
-class wxMemoryInputStream: public virtual wxMemoryStreamBase, public wxInputStream {
+class wxMemoryInputStream: public wxInputStream {
public:
wxMemoryInputStream(const char *data, size_t length);
virtual ~wxMemoryInputStream();
char Peek();
-
- protected:
-
- size_t DoRead(void *buffer, size_t size);
- off_t DoSeekInput(off_t pos, wxSeekMode mode);
- off_t DoTellInput() const { return m_position_i; }
-
- protected:
- off_t m_position_i;
};
-class wxMemoryOutputStream: public virtual wxMemoryStreamBase, public wxOutputStream {
+class wxMemoryOutputStream: public wxOutputStream {
public:
wxMemoryOutputStream(char *data = NULL, size_t length = 0);
virtual ~wxMemoryOutputStream();
-
- char *GetData() { Sync(); return m_buffer; }
- size_t GetLength() { Sync(); return m_length; }
-
- protected:
-
- size_t DoWrite(const void *buffer, size_t size);
- off_t DoSeekOutput(off_t pos, wxSeekMode mode);
- off_t DoTellOutput() const { return m_position_o; }
-
- protected:
- off_t m_position_o;
};
class wxMemoryStream: public wxMemoryInputStream, public wxMemoryOutputStream {
protected:
wxSocketBase *m_sock;
wxSocketStream *m_sockstrm;
- wxDataStream *m_codec;
+ wxDataInputStream *m_codeci;
+ wxDataOutputStream *m_codeco;
wxString m_topic;
friend class wxTCPServer;
#include "wx/stream.h"
#include "wx/socket.h"
-class WXDLLEXPORT wxSocketOutputStream : public virtual wxOutputStream
+class WXDLLEXPORT wxSocketOutputStream : public wxOutputStream
{
public:
wxSocketOutputStream(wxSocketBase& s);
- virtual ~wxSocketOutputStream();
+ ~wxSocketOutputStream();
wxOutputStream& Write(const void *buffer, size_t size);
off_t SeekO( off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
off_t TellO()
{ return -1; }
- bool Bad() { return m_o_socket->IsDisconnected(); }
- size_t LastWrite() { return m_o_socket->LastCount(); }
protected:
wxSocketBase *m_o_socket;
};
-class WXDLLEXPORT wxSocketInputStream : public virtual wxInputStream
+class WXDLLEXPORT wxSocketInputStream : public wxInputStream
{
public:
wxSocketInputStream(wxSocketBase& s);
off_t TellI()
{ return -1; }
- bool Eof() { return m_i_socket->IsDisconnected(); }
- size_t LastRead() { return m_i_socket->LastCount(); }
protected:
wxSocketBase *m_i_socket;
};
class WXDLLEXPORT wxSocketStream : public wxSocketInputStream,
- public wxSocketOutputStream,
- public wxStream {
-
+ public wxSocketOutputStream
+{
public:
- wxSocketStream(wxSocketBase& i_s, wxSocketBase& o_s);
wxSocketStream(wxSocketBase& s);
+ ~wxSocketStream();
};
#endif
virtual bool Connect(wxSockAddress& addr_man, bool wait = TRUE);
- bool WaitOnConnect(long seconds = -1);
+ bool WaitOnConnect(long seconds = -1, long microseconds = 0);
virtual void OnRequest(wxRequestEvent flags);
};
#include "wx/string.h"
#include "wx/filefn.h" // for off_t, wxInvalidOffset and wxSeekMode
+class WXDLLEXPORT wxStreamBase;
class WXDLLEXPORT wxInputStream;
class WXDLLEXPORT wxOutputStream;
wxOutputStream& WXDLLEXPORT wxEndL(wxOutputStream& o_stream);
-// Disable warnings such as
-// 'wxFilterStream' : inherits 'wxFilterInputStream::Peek' via dominance
-
-#ifdef _MSC_VER
-#pragma warning(disable:4250)
-#endif
-
// ---------------------------------------------------------------------------
// Stream buffer
// ---------------------------------------------------------------------------
class WXDLLEXPORT wxStreamBuffer {
public:
- wxStreamBuffer(wxInputStream& stream);
- wxStreamBuffer(wxOutputStream& stream);
+ typedef enum {
+ read, write
+ } BufMode;
+
+ // -----------
+ // ctor & dtor
+ // -----------
+ wxStreamBuffer(wxStreamBase& stream, BufMode mode);
~wxStreamBuffer();
+ // -----------
+ // Filtered IO
+ // -----------
void Read(void *buffer, size_t size);
void Write(const void *buffer, size_t size);
- void WriteBack(char c);
-
+ bool WriteBack(const char *buffer, size_t size);
+ bool WriteBack(char c);
+ off_t Tell() const;
+ off_t Seek(off_t pos, wxSeekMode mode);
+
+ // --------------
+ // Buffer control
+ // --------------
+ void ResetBuffer();
void SetBufferIO(char *buffer_start, char *buffer_end);
void SetBufferIO(size_t bufsize);
- void ResetBuffer();
-
- void SetBufferPosition(char *buffer_position)
- { m_buffer_pos = buffer_position; }
- void SetIntPosition(size_t pos)
- { m_buffer_pos = m_buffer_start + pos; }
- char *GetBufferPosition() const { return m_buffer_pos; }
- size_t GetIntPosition() const { return m_buffer_pos - m_buffer_start; }
-
- char *GetBufferStart() const { return m_buffer_start; }
- char *GetBufferEnd() const { return m_buffer_end; }
- size_t GetBufferSize() const { return m_buffer_size; }
- size_t GetLastAccess() const { return m_buffer_end - m_buffer_start; }
+ char *GetBufferStart() const { return m_buffer_start; }
+ char *GetBufferEnd() const { return m_buffer_end; }
+ char *GetBufferPos() const { return m_buffer_pos; }
+ off_t GetIntPosition() const { return m_buffer_pos-m_buffer_start; }
+ void SetIntPosition(off_t pos) { m_buffer_pos = m_buffer_start+pos; }
+ size_t GetLastAccess() const { return m_buffer_end-m_buffer_start; }
+ void Fixed(bool fixed) { m_fixed = fixed; }
+
+ bool FlushBuffer();
+ bool FillBuffer();
+ size_t GetDataLeft() const;
+
+ protected:
+ char *AllocSpaceWBack(size_t needed_size);
+ size_t GetWBack(char *buf, size_t bsize);
+
+ void GetFromBuffer(void *buffer, size_t size);
+ void PutToBuffer(const void *buffer, size_t size);
protected:
char *m_buffer_start, *m_buffer_end, *m_buffer_pos;
size_t m_buffer_size;
- wxInputStream *m_istream;
- wxOutputStream *m_ostream;
+ char *m_wback;
+ size_t m_wbacksize, m_wbackcur;
+
+ bool m_fixed;
+
+ wxStreamBase *m_stream;
+ BufMode m_mode;
};
// ---------------------------------------------------------------------------
// wxStream: base classes
// ---------------------------------------------------------------------------
-class WXDLLEXPORT wxInputStream {
+typedef enum {
+ wxStream_NOERROR,
+ wxStream_EOF
+} wxStreamError;
+
+class WXDLLEXPORT wxStreamBase {
+ public:
+ wxStreamBase();
+ virtual ~wxStreamBase();
+
+ wxStreamError LastError() { return m_lasterror; }
+
+ protected:
+ friend class wxStreamBuffer;
+
+ virtual size_t OnSysRead(void *buffer, size_t bufsize);
+ virtual size_t OnSysWrite(const void *buffer, size_t bufsize);
+ virtual off_t OnSysSeek(off_t seek, wxSeekMode mode);
+ virtual off_t OnSysTell();
+
+ protected:
+ size_t m_lastcount;
+ wxStreamError m_lasterror;
+};
+
+class WXDLLEXPORT wxInputStream: public wxStreamBase {
public:
wxInputStream();
+ wxInputStream(wxStreamBuffer *sbuf);
virtual ~wxInputStream();
// IO functions
- virtual char Peek() { return 0; }
- virtual char GetC();
- virtual wxInputStream& Read(void *buffer, size_t size);
+ virtual char Peek();
+ char GetC();
+ wxInputStream& Read(void *buffer, size_t size);
wxInputStream& Read(wxOutputStream& stream_out);
// Position functions
- virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
- virtual off_t TellI() const;
+ off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
+ off_t TellI() const;
// State functions
- bool Eof() const { return m_eof; }
- size_t LastRead() { return m_lastread; }
wxStreamBuffer *InputStreamBuffer() { return m_i_streambuf; }
+ size_t LastRead() { return wxStreamBase::m_lastcount; }
// Operators
wxInputStream& operator>>(wxOutputStream& out) { return Read(out); }
wxInputStream& operator>>(short& i);
wxInputStream& operator>>(int& i);
wxInputStream& operator>>(long& i);
- wxInputStream& operator>>(float& i);
+ wxInputStream& operator>>(double& i);
#if wxUSE_SERIAL
wxInputStream& operator>>(wxObject *& obj);
#endif
+ wxInputStream& operator>>(float& f) { double d; operator>>((double&)d); f = (float)d; return *this; }
wxInputStream& operator>>(unsigned char& c) { return operator>>((char&)c); }
wxInputStream& operator>>(unsigned short& i) { return operator>>((short&)i); }
wxInputStream& operator>>(unsigned int& i) { return operator>>((int&)i); }
wxInputStream& operator>>( __wxInputManip func) { return func(*this); }
protected:
- friend class wxStreamBuffer;
- friend class wxFilterInputStream;
-
- wxInputStream(wxStreamBuffer *buffer);
-
- virtual size_t DoRead(void *WXUNUSED(buffer), size_t WXUNUSED(size) )
- { return 0; }
- virtual off_t DoSeekInput( off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
- { return wxInvalidOffset; }
- virtual off_t DoTellInput() const
- { return wxInvalidOffset; }
-
- protected:
- bool m_eof, m_i_destroybuf;
- size_t m_lastread;
+ bool m_i_destroybuf;
wxStreamBuffer *m_i_streambuf;
};
-class WXDLLEXPORT wxOutputStream {
+class WXDLLEXPORT wxOutputStream: public wxStreamBase {
public:
wxOutputStream();
+ wxOutputStream(wxStreamBuffer *sbuf);
virtual ~wxOutputStream();
- virtual wxOutputStream& Write(const void *buffer, size_t size);
+ wxOutputStream& Write(const void *buffer, size_t size);
wxOutputStream& Write(wxInputStream& stream_in);
- virtual off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
- virtual off_t TellO() const;
+ off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
+ off_t TellO() const;
- virtual bool Bad() const { return m_bad; }
- virtual size_t LastWrite() const { return m_lastwrite; }
+ size_t LastWrite() const { return wxStreamBase::m_lastcount; }
wxStreamBuffer *OutputStreamBuffer() { return m_o_streambuf; }
- virtual void Sync();
+ void Sync();
wxOutputStream& operator<<(wxInputStream& out) { return Write(out); }
wxOutputStream& operator<<(const char *string);
wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); }
protected:
- friend class wxStreamBuffer;
- friend class wxFilterOutputStream;
-
- wxOutputStream(wxStreamBuffer *buffer);
-
- virtual size_t DoWrite( const void *WXUNUSED(buffer), size_t WXUNUSED(size) )
- { return 0; }
- virtual off_t DoSeekOutput( off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
- { return wxInvalidOffset; }
- virtual off_t DoTellOutput() const
- { return wxInvalidOffset; }
-
- protected:
- bool m_bad, m_o_destroybuf;
- size_t m_lastwrite;
+ bool m_o_destroybuf;
wxStreamBuffer *m_o_streambuf;
};
-class WXDLLEXPORT wxStream: public virtual wxInputStream,
- public virtual wxOutputStream
-{
- public:
- wxStream();
-};
-
// ---------------------------------------------------------------------------
// "Filter" streams
// ---------------------------------------------------------------------------
-class WXDLLEXPORT wxFilterInputStream: public virtual wxInputStream {
+class WXDLLEXPORT wxFilterInputStream: public wxInputStream {
public:
wxFilterInputStream();
wxFilterInputStream(wxInputStream& stream);
char Peek() { return m_parent_i_stream->Peek(); }
- bool Eof() const { return m_parent_i_stream->Eof(); }
- size_t LastRead() const { return m_parent_i_stream->LastRead(); }
- off_t TellI() const { return m_parent_i_stream->TellI(); }
-
- protected:
- size_t DoRead(void *buffer, size_t size);
- off_t DoSeekInput(off_t pos, wxSeekMode mode);
- off_t DoTellInput() const;
-
protected:
wxInputStream *m_parent_i_stream;
};
-class WXDLLEXPORT wxFilterOutputStream: public virtual wxOutputStream {
+class WXDLLEXPORT wxFilterOutputStream: public wxOutputStream {
public:
wxFilterOutputStream();
wxFilterOutputStream(wxOutputStream& stream);
- virtual ~wxFilterOutputStream();
-
- bool Bad() const { return m_parent_o_stream->Bad(); }
- size_t LastWrite() const { return m_parent_o_stream->LastWrite(); }
- off_t TellO() const { return m_parent_o_stream->TellO(); }
-
- protected:
- // The forward is implicitely done by wxStreamBuffer.
-
- size_t DoWrite(const void *buffer, size_t size);
- off_t DoSeekOutput(off_t pos, wxSeekMode mode);
- off_t DoTellOutput() const;
+ ~wxFilterOutputStream();
protected:
wxOutputStream *m_parent_o_stream;
};
-class WXDLLEXPORT wxFilterStream: public wxStream,
- public virtual wxFilterInputStream,
- public virtual wxFilterOutputStream {
- public:
- wxFilterStream(wxStream& stream);
- wxFilterStream();
-};
-
-#ifdef _MSC_VER
-#pragma warning(default:4250)
-#endif
-
#endif
// ---------------------------------------------------------------------------
// Global variables
-// GUI mutex.
-WXDLLEXPORT_DATA(extern wxMutex) wxMainMutex;
+// GUI mutex handling.
+void WXDLLEXPORT wxMutexGuiEnter();
+void WXDLLEXPORT wxMutexGuiLeave();
#endif
wxZlibInputStream(wxInputStream& stream);
virtual ~wxZlibInputStream();
- bool Eof() const;
-
protected:
- size_t DoRead(void *buffer, size_t size);
- off_t DoSeekInput(off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode)) { return wxInvalidOffset; }
- off_t DoTellInput() const { return wxInvalidOffset; }
+ size_t OnSysRead(void *buffer, size_t size);
protected:
size_t m_z_size;
void Sync();
- bool Bad() const;
-
protected:
- size_t DoWrite(const void *buffer, size_t size);
- off_t DoSeekOutput(off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode)) { return wxInvalidOffset; }
- off_t DoTellOutput() const { return wxInvalidOffset; }
+ size_t OnSysWrite(const void *buffer, size_t size);
protected:
size_t m_z_size;
#endif
Write(buf, 10);
}
-
-// ---------------------------------------------------------------------------
-// wxDataStream
-// ---------------------------------------------------------------------------
-
-wxDataStream::wxDataStream(wxStream& stream)
- : wxDataInputStream(stream), wxDataOutputStream(stream)
-{
-}
return 0;
}
-size_t wxFileInputStream::DoRead(void *buffer, size_t size)
+size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
{
return m_file->Read(buffer, size);
}
-off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
+off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
{
return m_file->Seek(pos, mode);
}
-off_t wxFileInputStream::DoTellInput() const
+off_t wxFileInputStream::OnSysTell() const
{
return m_file->Tell();
}
}
}
-size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size)
+size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
{
size_t ret = m_file->Write(buffer, size);
- m_bad = m_file->Error();
+ m_lasterror = wxStream_EOF; // TODO
return ret;
}
-off_t wxFileOutputStream::DoTellOutput() const
+off_t wxFileOutputStream::OnSysTell() const
{
return m_file->Tell();
}
-off_t wxFileOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode)
+off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
{
return m_file->Seek(pos, mode);
}
wxOutputStream::Sync();
m_file->Flush();
}
-
-// ----------------------------------------------------------------------------
-// wxFileStream
-// ----------------------------------------------------------------------------
-
-wxFileStream::wxFileStream(const wxString& fileName)
- : wxFileInputStream(), wxFileOutputStream()
-{
- m_file = new wxFile(fileName, wxFile::read_write);
- // Reread the initial buffer.
- m_i_streambuf->SetBufferIO(1024);
-}
-
-wxFileStream::~wxFileStream()
-{
- Sync();
- delete m_file;
-}
: wxSocketInputStream(*sock), m_ftp(ftp_clt) {}
virtual ~wxInputFTPStream(void)
{
- if (Eof())
+ if (LastError() != wxStream_NOERROR)
m_ftp->GetResult('2');
else
m_ftp->Abort();
: wxSocketOutputStream(*sock), m_ftp(ftp_clt) {}
virtual ~wxOutputFTPStream(void)
{
- if (Bad())
+ if (LastError() != wxStream_NOERROR)
m_ftp->GetResult('2');
else
m_ftp->Abort();
#pragma hdrstop
#endif
-// ----------------------------------------------------------------------------
-// wxMemoryStreamBase
-// ----------------------------------------------------------------------------
-wxMemoryStreamBase::wxMemoryStreamBase()
-{
- m_buffer = NULL;
- m_iolimit = 0;
- m_persistent = FALSE;
- m_length = 0;
-}
-
-wxMemoryStreamBase::~wxMemoryStreamBase()
-{
- 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)
+ : wxInputStream()
{
- 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;
-
- m_i_streambuf->SetBufferIO(0);
+ m_i_streambuf->SetBufferIO((char *)data, data+len);
+ m_i_streambuf->Fixed(TRUE);
}
wxMemoryInputStream::~wxMemoryInputStream()
char wxMemoryInputStream::Peek()
{
- // wxStreamBuffer is disabled so just peek the current character.
-
- return m_buffer[m_position_i];
-}
-
-size_t wxMemoryInputStream::DoRead(void *buffer, size_t size)
-{
- if (m_iolimit == 2) {
- m_eof = TRUE;
- return 0;
- }
- if (m_position_i+size > m_length)
- size = m_length-m_position_i;
-
- memcpy((void *)((unsigned long)buffer+m_position_i), m_buffer, size);
- m_position_i += size;
-
- return size;
-}
-
-off_t wxMemoryInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
-{
- if (m_iolimit == 2)
- return 0;
-
- switch (mode) {
- case wxFromStart:
- if ((size_t)pos > m_length)
- return m_position_i;
- return (m_position_i = pos);
-
- case wxFromCurrent:
- if ((size_t)(m_position_i+pos) > m_length)
- return m_position_i;
-
- return (m_position_i += pos);
-
- case wxFromEnd:
- if ((size_t)(m_length-pos) > m_length)
- return m_position_i;
-
- return (m_position_i = m_length-pos);
- }
-
- return m_position_i;
+ return m_i_streambuf->GetBufferStart()[m_i_streambuf->GetIntPosition()];
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
wxMemoryOutputStream::wxMemoryOutputStream(char *data, size_t len)
+ : wxOutputStream()
{
- m_persistent = FALSE;
- m_buffer = data;
- m_length = len;
- m_position_o = 0;
- m_lastwrite = 0;
- m_bad = FALSE;
- m_iolimit = 2;
-
- m_o_streambuf->SetBufferIO(0);
+ if (data)
+ m_o_streambuf->SetBufferIO(data, data+len);
+ m_o_streambuf->Fixed(TRUE);
}
wxMemoryOutputStream::~wxMemoryOutputStream()
-{
- Sync();
-}
-
-size_t wxMemoryOutputStream::DoWrite(const void *buffer, size_t size)
-{
- if (m_iolimit == 1) {
- m_bad = TRUE;
- return 0;
- }
-
- if (m_position_o+size > m_length)
- if (!ChangeBufferSize(m_position_o+size)) {
- m_bad = TRUE;
- return 0;
- }
-
- memcpy(m_buffer+m_position_o, buffer, size);
- m_position_o += size;
-
- return size;
-}
-
-off_t wxMemoryOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode)
-{
- if (m_iolimit == 1)
- return 0;
-
- switch (mode) {
- case wxFromStart:
- if ((size_t)pos > m_length)
- return m_position_o;
- return (m_position_o = pos);
-
- case wxFromCurrent:
- if ((size_t)(m_position_o+pos) > m_length)
- return m_position_o;
-
- return (m_position_o += pos);
-
- case wxFromEnd:
- if ((size_t)(m_length-pos) > m_length)
- return m_position_o;
-
- return (m_position_o = m_length-pos);
- }
-
- return m_position_o;
-}
-
-// ----------------------------------------------------------------------------
-// wxMemoryStream
-// ----------------------------------------------------------------------------
-
-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()
{
}
#include "wx/listbox.h"
#include "wx/choice.h"
#include "wx/checkbox.h"
+#include "wx/settings.h"
#include "wx/slider.h"
#include "wx/statbox.h"
#if wxUSE_GAUGE
wxSocketHandler *hsock = &wxSocketHandler::Master();
wxSocketClient *client = hsock->CreateClient();
wxSocketStream *stream = new wxSocketStream(*client);
- wxDataStream data_s(*stream);
+ wxDataInputStream data_is(*stream);
+ wxDataOutputStream data_os(*stream);
client->SetNotify(wxSocketBase::REQ_READ | wxSocketBase::REQ_LOST);
addr.Service(server_name);
// Send topic name, and enquire whether this has succeeded
unsigned char msg;
- data_s.Write8(IPC_CONNECT);
- data_s.WriteString(topic);
+ data_os.Write8(IPC_CONNECT);
+ data_os.WriteString(topic);
- msg = data_s.Read8();
+ msg = data_is.Read8();
// OK! Confirmation.
if (msg == IPC_CONNECT) {
wxTCPConnection::wxTCPConnection (void)
: wxConnectionBase(),
- m_sock(NULL), m_sockstrm(NULL), m_codec(NULL)
+ m_sock(NULL), m_sockstrm(NULL), m_codeci(NULL), m_codeco(NULL)
{
}
wxTCPConnection::~wxTCPConnection (void)
{
wxDELETE(m_sock);
- wxDELETE(m_codec);
+ wxDELETE(m_codeci);
+ wxDELETE(m_codeco);
wxDELETE(m_sockstrm);
}
bool wxTCPConnection::Disconnect (void)
{
// Send the the disconnect message to the peer.
- m_codec->Write8(IPC_DISCONNECT);
+ m_codeco->Write8(IPC_DISCONNECT);
m_sock->Close();
return TRUE;
return FALSE;
// Prepare EXECUTE message
- m_codec->Write8(IPC_EXECUTE);
- m_codec->Write8(format);
+ m_codeco->Write8(IPC_EXECUTE);
+ m_codeco->Write8(format);
if (size < 0)
- m_codec->WriteString(data);
+ m_codeco->WriteString(data);
else {
- m_codec->Write32(size);
- m_codec->Write(data, size);
+ m_codeco->Write32(size);
+ m_codeco->Write(data, size);
}
return TRUE;
if (!m_sock->IsConnected())
return NULL;
- m_codec->Write8(IPC_REQUEST);
- m_codec->WriteString(item);
- m_codec->Write8(format);
+ m_codeco->Write8(IPC_REQUEST);
+ m_codeco->WriteString(item);
+ m_codeco->Write8(format);
// If Unpack doesn't initialize it.
int ret;
- ret = m_codec->Read8();
+ ret = m_codeci->Read8();
if (ret == IPC_FAIL)
return NULL;
else {
size_t s;
char *data = NULL;
- s = m_codec->Read32();
+ s = m_codeci->Read32();
data = new char[s];
- m_codec->Read(data, s);
+ m_codeci->Read(data, s);
if (size)
*size = s;
if (!m_sock->IsConnected())
return FALSE;
- m_codec->Write8(IPC_POKE);
- m_codec->WriteString(item);
- m_codec->Write8(format);
+ m_codeco->Write8(IPC_POKE);
+ m_codeco->WriteString(item);
+ m_codeco->Write8(format);
if (size < 0)
- m_codec->WriteString(data);
+ m_codeco->WriteString(data);
else {
- m_codec->Write32(size);
- m_codec->Write(data, size);
+ m_codeco->Write32(size);
+ m_codeco->Write(data, size);
}
return TRUE;
if (!m_sock->IsConnected())
return FALSE;
- m_codec->Write8(IPC_ADVISE_START);
- m_codec->WriteString(item);
+ m_codeco->Write8(IPC_ADVISE_START);
+ m_codeco->WriteString(item);
- ret = m_codec->Read8();
+ ret = m_codeci->Read8();
if (ret != IPC_FAIL)
return TRUE;
if (!m_sock->IsConnected())
return FALSE;
- m_codec->Write8(IPC_ADVISE_STOP);
- m_codec->WriteString(item);
+ m_codeco->Write8(IPC_ADVISE_STOP);
+ m_codeco->WriteString(item);
- msg = m_codec->Read8();
+ msg = m_codeci->Read8();
if (msg != IPC_FAIL)
return TRUE;
if (!m_sock->IsConnected())
return FALSE;
- m_codec->Write8(IPC_ADVISE);
- m_codec->WriteString(item);
- m_codec->Write8(format);
+ m_codeco->Write8(IPC_ADVISE);
+ m_codeco->WriteString(item);
+ m_codeco->Write8(format);
if (size < 0)
- m_codec->WriteString(data);
+ m_codeco->WriteString(data);
else {
- m_codec->Write32(size);
- m_codec->Write(data, size);
+ m_codeco->Write32(size);
+ m_codeco->Write(data, size);
}
return TRUE;
{
int msg = 0;
wxTCPConnection *connection = (wxTCPConnection *)cdata;
- wxDataStream *codec;
+ wxDataInputStream *codeci;
+ wxDataOutputStream *codeco;
wxString topic_name = connection->m_topic;
wxString item;
}
// Receive message number.
- codec = connection->m_codec;
- msg = codec->Read8();
+ codeci = connection->m_codeci;
+ codeco = connection->m_codeco;
+ msg = codeci->Read8();
switch (msg) {
case IPC_EXECUTE: {
size_t size;
wxDataFormat format;
- format = (wxDataFormat)codec->Read8();
- size = codec->Read32();
+ format = (wxDataFormat)codeci->Read8();
+ size = codeci->Read32();
data = new char[size];
- codec->Read(data, size);
+ codeci->Read(data, size);
connection->OnExecute (topic_name, data, size, format);
size_t size;
wxDataFormat format;
- item = codec->ReadString();
- format = (wxDataFormat)codec->Read8();
- size = codec->Read32();
+ item = codeci->ReadString();
+ format = (wxDataFormat)codeci->Read8();
+ size = codeci->Read32();
data = new char[size];
- codec->Read(data, size);
+ codeci->Read(data, size);
connection->OnAdvise (topic_name, item, data, size, format);
break;
}
case IPC_ADVISE_START: {
- item = codec->ReadString();
+ item = codeci->ReadString();
bool ok = connection->OnStartAdvise (topic_name, item);
if (ok)
- codec->Write8(IPC_ADVISE_START);
+ codeco->Write8(IPC_ADVISE_START);
else
- codec->Write8(IPC_FAIL);
+ codeco->Write8(IPC_FAIL);
break;
}
case IPC_ADVISE_STOP: {
- item = codec->ReadString();
+ item = codeci->ReadString();
bool ok = connection->OnStopAdvise (topic_name, item);
if (ok)
- codec->Write8(IPC_ADVISE_STOP);
+ codeco->Write8(IPC_ADVISE_STOP);
else
- codec->Write8(IPC_FAIL);
+ codeco->Write8(IPC_FAIL);
break;
}
size_t size;
char *data;
- item = codec->ReadString();
- format = (wxDataFormat)codec->Read8();
- size = codec->Read32();
+ item = codeci->ReadString();
+ format = (wxDataFormat)codeci->Read8();
+ size = codeci->Read32();
data = new char[size];
- codec->Read(data, size);
+ codeci->Read(data, size);
connection->OnPoke (topic_name, item, data, size, format);
case IPC_REQUEST: {
wxDataFormat format;
- item = codec->ReadString();
- format = (wxDataFormat)codec->Read8();
+ item = codeci->ReadString();
+ format = (wxDataFormat)codeci->Read8();
int user_size = -1;
char *user_data = connection->OnRequest (topic_name, item, &user_size, format);
if (user_data) {
- codec->Write8(IPC_REQUEST_REPLY);
+ codeco->Write8(IPC_REQUEST_REPLY);
if (user_size != -1) {
- codec->Write32(user_size);
- codec->Write(user_data, user_size);
+ codeco->Write32(user_size);
+ codeco->Write(user_data, user_size);
} else
- codec->WriteString(user_data);
+ codeco->WriteString(user_data);
} else
- codec->Write8(IPC_FAIL);
+ codeco->Write8(IPC_FAIL);
break;
}
break;
}
default:
- codec->Write8(IPC_FAIL);
+ codeco->Write8(IPC_FAIL);
break;
}
}
{
wxTCPServer *ipcserv = (wxTCPServer *)cdata;
wxSocketStream *stream;
- wxDataStream *codec;
+ wxDataInputStream *codeci;
+ wxDataOutputStream *codeco;
if (evt != wxSocketBase::EVT_ACCEPT)
return;
sock->SetNotify(wxSocketBase::REQ_READ | wxSocketBase::REQ_LOST);
stream = new wxSocketStream(*sock);
- codec = new wxDataStream(*stream);
+ codeci = new wxDataInputStream(*stream);
+ codeco = new wxDataOutputStream(*stream);
if (!sock->Ok())
return;
int msg;
- msg = codec->Read8();
+ msg = codeci->Read8();
if (msg == IPC_CONNECT) {
wxString topic_name;
- topic_name = codec->ReadString();
+ topic_name = codeci->ReadString();
/* Register new socket with the notifier */
wxTCPConnection *new_connection =
if (new_connection) {
if (!new_connection->IsKindOf(CLASSINFO(wxTCPConnection))) {
delete new_connection;
- codec->Write8(IPC_FAIL);
+ codeco->Write8(IPC_FAIL);
return;
}
// Acknowledge success
- codec->Write8(IPC_CONNECT);
+ codeco->Write8(IPC_CONNECT);
new_connection->m_topic = topic_name;
new_connection->m_sockstrm = stream;
- new_connection->m_codec = codec;
+ new_connection->m_codeci = codeci;
+ new_connection->m_codeco = codeco;
sock->Callback(Client_OnRequest);
sock->CallbackData((char *)new_connection);
sock->Notify(TRUE);
} else {
// Send failure message
- codec->Write8(IPC_FAIL);
+ codeco->Write8(IPC_FAIL);
}
}
}
wxOutputStream& wxSocketOutputStream::Write(const void *buffer, size_t size)
{
- m_o_socket->Write((const char *)buffer, size);
+ m_lastcount = m_o_socket->Write((const char *)buffer, size).LastCount();
return *this;
}
wxInputStream& wxSocketInputStream::Read(void *buffer, size_t size)
{
- m_i_socket->Read((char *)buffer, size);
+ m_lastcount = m_i_socket->Read((char *)buffer, size).LastCount();
return *this;
}
// ---------------------------------------------------------------------------
-// wxSocketStream (IO)
+// wxSocketStream
// ---------------------------------------------------------------------------
-wxSocketStream::wxSocketStream(wxSocketBase& i_s, wxSocketBase& o_s)
- : wxSocketInputStream(i_s), wxSocketOutputStream(o_s)
-{
-}
wxSocketStream::wxSocketStream(wxSocketBase& s)
: wxSocketInputStream(s), wxSocketOutputStream(s)
{
}
+
+wxSocketStream::~wxSocketStream()
+{
+}
return TRUE;
}
-bool wxSocketClient::WaitOnConnect(long seconds)
+bool wxSocketClient::WaitOnConnect(long seconds, long microseconds)
{
- int ret = _Wait(seconds, 0, REQ_CONNECT | REQ_LOST);
+ int ret = _Wait(seconds, microseconds, REQ_CONNECT | REQ_LOST);
if (ret)
m_connected = TRUE;
// wxStreamBuffer
// ----------------------------------------------------------------------------
-wxStreamBuffer::wxStreamBuffer(wxInputStream& i_stream)
+wxStreamBuffer::wxStreamBuffer(wxStreamBase& stream, BufMode mode)
: m_buffer_start(NULL), m_buffer_end(NULL), m_buffer_pos(NULL),
- m_buffer_size(0), m_istream(&i_stream), m_ostream(NULL)
+ m_buffer_size(0), m_stream(&stream), m_mode(mode)
{
}
-wxStreamBuffer::wxStreamBuffer(wxOutputStream& o_stream)
- : m_buffer_start(NULL), m_buffer_end(NULL), m_buffer_pos(NULL),
- m_buffer_size(0), m_istream(NULL), m_ostream(&o_stream)
+wxStreamBuffer::~wxStreamBuffer()
{
+ wxDELETEA(m_buffer_start);
}
-wxStreamBuffer::~wxStreamBuffer()
+bool wxStreamBuffer::WriteBack(const char *buf, size_t bufsize)
{
- wxDELETEA(m_buffer_start);
+ char *ptrback;
+
+ ptrback = AllocSpaceWBack(bufsize);
+ if (!ptrback)
+ return FALSE;
+
+ memcpy(ptrback, buf, bufsize);
+ return TRUE;
}
-void wxStreamBuffer::WriteBack(char c)
+bool wxStreamBuffer::WriteBack(char c)
{
- if (m_ostream)
- return;
+ char *ptrback;
- // Assume that if we write "back" we have read a few bytes: so we have some
- // space.
- if (m_buffer_pos == m_buffer_start)
- return;
+ ptrback = AllocSpaceWBack(1);
+ if (!ptrback)
+ return FALSE;
- m_buffer_pos--;
- *m_buffer_pos = c;
+ *ptrback = c;
+ return TRUE;
}
void wxStreamBuffer::SetBufferIO(char *buffer_start, char *buffer_end)
{
- size_t ret;
-
m_buffer_start = buffer_start;
m_buffer_end = buffer_end;
m_buffer_size = m_buffer_end-m_buffer_start;
-
- if (m_istream) {
- ret = m_istream->DoRead(m_buffer_start, m_buffer_size);
- m_buffer_end = m_buffer_start + ret;
- }
- m_buffer_pos = m_buffer_start;
+ ResetBuffer();
}
void wxStreamBuffer::SetBufferIO(size_t bufsize)
void wxStreamBuffer::ResetBuffer()
{
- if (m_istream)
+ if (m_mode == read)
m_buffer_pos = m_buffer_end;
else
m_buffer_pos = m_buffer_start;
}
+char *wxStreamBuffer::AllocSpaceWBack(size_t needed_size)
+{
+ char *temp_b;
+
+ m_wbacksize += needed_size;
+
+ if (!m_wback)
+ temp_b = (char *)malloc(m_wbacksize);
+ else
+ temp_b = (char *)realloc(m_wback, m_wbacksize);
+
+ if (!temp_b)
+ return NULL;
+ return (char *)((size_t)m_wback+(m_wbacksize-needed_size));
+}
+
+size_t wxStreamBuffer::GetWBack(char *buf, size_t bsize)
+{
+ size_t s_toget = m_wbacksize-m_wbackcur;
+
+ if (bsize < s_toget)
+ s_toget = bsize;
+
+ memcpy(buf, (m_wback+m_wbackcur), s_toget);
+
+ m_wbackcur += s_toget;
+ if (m_wbackcur == m_wbacksize) {
+ free(m_wback);
+ m_wback = (char *)NULL;
+ m_wbacksize = 0;
+ m_wbackcur = 0;
+ }
+
+ return s_toget;
+}
+
+bool wxStreamBuffer::FillBuffer()
+{
+ size_t count;
+
+ count = m_stream->OnSysRead(m_buffer_start, m_buffer_size);
+ m_buffer_end = m_buffer_start+count;
+ m_buffer_pos = m_buffer_start;
+
+ if (count == 0)
+ return FALSE;
+ return TRUE;
+}
+
+bool wxStreamBuffer::FlushBuffer()
+{
+ size_t count, current;
+
+ if (m_buffer_pos == m_buffer_start)
+ return FALSE;
+
+ current = m_buffer_pos-m_buffer_start;
+ count = m_stream->OnSysWrite(m_buffer_start, current);
+ if (count != current)
+ return FALSE;
+ m_buffer_pos = m_buffer_start;
+
+ return TRUE;
+}
+
+void wxStreamBuffer::GetFromBuffer(void *buffer, size_t size)
+{
+ size_t s_toget = m_buffer_end-m_buffer_pos;
+
+ if (size < s_toget)
+ s_toget = size;
+
+ memcpy(buffer, m_buffer_pos, s_toget);
+ m_buffer_pos += s_toget;
+}
+
+void wxStreamBuffer::PutToBuffer(const void *buffer, size_t size)
+{
+ size_t s_toput = m_buffer_end-m_buffer_pos;
+
+ if (s_toput < size && !m_fixed) {
+ m_buffer_start = (char *)realloc(m_buffer_start, m_buffer_size+size);
+ // I round a bit
+ m_buffer_end = m_buffer_start+m_buffer_size;
+ s_toput = size;
+ }
+ if (s_toput > size)
+ s_toput = size;
+ memcpy(m_buffer_pos, buffer, s_toput);
+ m_buffer_pos += s_toput;
+}
+
void wxStreamBuffer::Read(void *buffer, size_t size)
{
- wxASSERT(m_istream != NULL);
+ wxASSERT(m_stream != NULL);
// ------------------
// Buffering disabled
// ------------------
+ m_stream->m_lastcount = GetWBack((char *)buffer, size);
+ size -= m_stream->m_lastcount;
+ if (size == 0)
+ return;
+
+ buffer = (void *)((char *)buffer+m_stream->m_lastcount);
+
if (!m_buffer_size) {
- m_istream->m_lastread = m_istream->DoRead(buffer, size);
+ m_stream->m_lastcount += m_stream->OnSysRead(buffer, size);
return;
}
// Buffering enabled
// -----------------
size_t buf_left, orig_size = size;
- size_t read_ret;
while (size > 0) {
- buf_left = m_buffer_end - m_buffer_pos;
+ buf_left = GetDataLeft();
// First case: the requested buffer is larger than the stream buffer,
// we split
if (size > buf_left) {
- memcpy(buffer, m_buffer_pos, buf_left);
- size -= buf_left;
+ GetFromBuffer(buffer, buf_left);
+ size -= buf_left;
buffer = (char *)buffer + buf_left; // ANSI C++ violation.
- read_ret = m_istream->DoRead(m_buffer_start, m_buffer_size);
-
- // Read failed: EOF
- if (read_ret == 0) {
- m_istream->m_lastread = orig_size-size;
- m_istream->m_eof = TRUE;
- m_buffer_pos = m_buffer_end = m_buffer_start;
+ if (!FillBuffer()) {
+ m_stream->m_lastcount = orig_size-size;
return;
- } else {
- m_buffer_end = m_buffer_start+read_ret;
- m_buffer_pos = m_buffer_start;
}
} else {
// Second case: we just copy from the stream buffer.
- memcpy(buffer, m_buffer_pos, size);
- m_buffer_pos += size;
+ GetFromBuffer(buffer, size);
break;
}
}
- m_istream->m_lastread = orig_size;
+ m_stream->m_lastcount += orig_size;
}
void wxStreamBuffer::Write(const void *buffer, size_t size)
{
- wxASSERT(m_ostream != NULL);
+ wxASSERT(m_stream != NULL);
// ------------------
// Buffering disabled
// ------------------
if (!m_buffer_size) {
- m_ostream->m_lastwrite = m_ostream->DoWrite(buffer, size);
+ m_stream->m_lastcount = m_stream->OnSysWrite(buffer, size);
return;
}
// ------------------
size_t buf_left, orig_size = size;
- size_t write_ret;
while (size > 0) {
buf_left = m_buffer_end - m_buffer_pos;
// First case: the buffer to write is larger than the stream buffer,
// we split it
if (size > buf_left) {
- memcpy(m_buffer_pos, buffer, buf_left);
+ PutToBuffer(buffer, buf_left);
size -= buf_left;
buffer = (char *)buffer + buf_left; // ANSI C++ violation.
- write_ret = m_ostream->DoWrite(m_buffer_start, m_buffer_size);
- if (write_ret != m_buffer_size) {
- m_ostream->m_bad = TRUE;
- m_ostream->m_lastwrite = orig_size-size;
- m_buffer_pos = m_buffer_end = m_buffer_start;
+ if (!FlushBuffer()) {
+ m_stream->m_lastcount = orig_size-size;
return;
}
m_buffer_pos = m_buffer_start;
} else {
// Second case: just copy it in the stream buffer.
-
- memcpy(m_buffer_pos, buffer, size);
- m_buffer_pos += size;
+ PutToBuffer(buffer, size);
break;
}
}
- m_ostream->m_lastwrite = orig_size;
+ m_stream->m_lastcount = orig_size;
+}
+
+off_t wxStreamBuffer::Seek(off_t pos, wxSeekMode mode)
+{
+ off_t ret_off, diff, last_access;
+
+ last_access = GetLastAccess();
+
+ switch (mode) {
+ case wxFromStart: {
+ // We'll try to compute an internal position later ...
+ ret_off = m_stream->OnSysSeek(pos, wxFromStart);
+ ResetBuffer();
+ return ret_off;
+ }
+ case wxFromCurrent: {
+ diff = pos + GetIntPosition();
+
+ if ( (diff > last_access) || (diff < 0) ) {
+ ret_off = m_stream->OnSysSeek(pos, wxFromCurrent);
+ ResetBuffer();
+ return ret_off;
+ } else {
+ SetIntPosition(diff);
+ return pos;
+ }
+ }
+ case wxFromEnd:
+ // Hard to compute: always seek to the requested position.
+ ret_off = m_stream->OnSysSeek(pos, wxFromEnd);
+ ResetBuffer();
+ return ret_off;
+ }
+ return wxInvalidOffset;
+}
+
+off_t wxStreamBuffer::Tell() const
+{
+ off_t pos;
+
+ pos = m_stream->OnSysTell();
+ if (pos == wxInvalidOffset)
+ return wxInvalidOffset;
+
+ return pos - GetLastAccess() + GetIntPosition();
+}
+
+size_t wxStreamBuffer::GetDataLeft() const
+{
+ return m_buffer_end-m_buffer_pos;
+}
+
+// ----------------------------------------------------------------------------
+// wxStreamBase
+// ----------------------------------------------------------------------------
+
+wxStreamBase::wxStreamBase()
+{
+ m_lasterror = wxStream_NOERROR;
+ m_lastcount = 0;
+}
+
+wxStreamBase::~wxStreamBase()
+{
+}
+
+size_t wxStreamBase::OnSysRead(void *buffer, size_t size)
+{
+ return 0;
+}
+
+size_t wxStreamBase::OnSysWrite(const void *buffer, size_t bufsize)
+{
+ return 0;
+}
+
+off_t wxStreamBase::OnSysSeek(off_t seek, wxSeekMode mode)
+{
+ return wxInvalidOffset;
+}
+
+off_t wxStreamBase::OnSysTell()
+{
+ return wxInvalidOffset;
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
wxInputStream::wxInputStream()
+ : wxStreamBase()
{
m_i_destroybuf = TRUE;
- m_i_streambuf = new wxStreamBuffer(*this);
- m_eof = FALSE;
- m_lastread = 0;
+ m_i_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::read);
}
wxInputStream::wxInputStream(wxStreamBuffer *buffer)
+ : wxStreamBase()
{
m_i_destroybuf = FALSE;
m_i_streambuf = buffer;
- m_eof = FALSE;
- m_lastread = 0;
}
wxInputStream::~wxInputStream()
return *this;
}
+char wxInputStream::Peek()
+{
+ if (!m_i_streambuf->GetDataLeft())
+ m_i_streambuf->FillBuffer();
+
+ return *(m_i_streambuf->GetBufferPos());
+}
+
#define BUF_TEMP_SIZE 10000
wxInputStream& wxInputStream::Read(wxOutputStream& stream_out)
char buf[BUF_TEMP_SIZE];
size_t bytes_read = BUF_TEMP_SIZE;
- while (bytes_read == BUF_TEMP_SIZE && !stream_out.Bad()) {
+ while (bytes_read == BUF_TEMP_SIZE && stream_out.LastError() != wxStream_NOERROR) {
bytes_read = Read(buf, bytes_read).LastRead();
stream_out.Write(buf, bytes_read);
return *this;
}
+off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode)
+{
+ return m_i_streambuf->Seek(pos, mode);
+}
+
+off_t wxInputStream::TellI() const
+{
+ return m_i_streambuf->Tell();
+}
+
+// --------------------
+// Overloaded operators
+// --------------------
+
wxInputStream& wxInputStream::operator>>(wxString& line)
{
wxDataInputStream s(*this);
return *this;
}
-wxInputStream& wxInputStream::operator>>(float& f)
+wxInputStream& wxInputStream::operator>>(double& f)
{
/* I only implemented a simple float parser */
int c, sign;
sign = 1;
while (isdigit(c)) {
- f = f*10 + c;
+ f = f*10 + (c - '0');
c = GetC();
}
if (c == '.') {
- float f_multiplicator = (float) 0.1;
+ double f_multiplicator = (double) 0.1;
c = GetC();
while (isdigit(c)) {
- f += c*f_multiplicator;
+ f += (c-'0')*f_multiplicator;
f_multiplicator /= 10;
c = GetC();
}
}
#endif
-off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode)
-{
- off_t ret_off, diff, last_access;
-
- last_access = m_i_streambuf->GetLastAccess();
-
- switch (mode) {
- case wxFromStart:
- diff = DoTellInput() - pos;
- if ( diff < 0 || diff > last_access ) {
- ret_off = DoSeekInput(pos, wxFromStart);
- m_i_streambuf->ResetBuffer();
- return ret_off;
- } else {
- m_i_streambuf->SetIntPosition(last_access - diff);
- return pos;
- }
- case wxFromCurrent:
- diff = pos + m_i_streambuf->GetIntPosition();
-
- if ( (diff > last_access) || (diff < 0) ) {
- ret_off = DoSeekInput(pos, wxFromCurrent);
- m_i_streambuf->ResetBuffer();
- return ret_off;
- } else {
- m_i_streambuf->SetIntPosition(diff);
- return pos;
- }
- case wxFromEnd:
- // Hard to compute: always seek to the requested position.
- ret_off = DoSeekInput(pos, wxFromEnd);
- m_i_streambuf->ResetBuffer();
- return ret_off;
- }
- return wxInvalidOffset;
-}
-
-off_t wxInputStream::TellI() const
-{
- return DoTellInput() - m_i_streambuf->GetLastAccess() +
- m_i_streambuf->GetIntPosition();
-}
// ----------------------------------------------------------------------------
// wxOutputStream
// ----------------------------------------------------------------------------
wxOutputStream::wxOutputStream()
+ : wxStreamBase()
{
m_o_destroybuf = TRUE;
- m_o_streambuf = new wxStreamBuffer(*this);
- m_bad = FALSE;
- m_lastwrite = 0;
+ m_o_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::write);
}
wxOutputStream::wxOutputStream(wxStreamBuffer *buffer)
+ : wxStreamBase()
{
m_o_destroybuf = FALSE;
m_o_streambuf = buffer;
- m_bad = FALSE;
- m_lastwrite = 0;
}
wxOutputStream::~wxOutputStream()
return *this;
}
-off_t wxOutputStream::SeekO(off_t pos, wxSeekMode mode)
+off_t wxOutputStream::TellO() const
{
- off_t ret_off;
-
- switch (mode) {
- case wxFromStart:
- if ( (unsigned)abs (DoTellOutput()-pos) > m_o_streambuf->GetLastAccess() ) {
- ret_off = DoSeekOutput(pos, wxFromStart);
- m_o_streambuf->ResetBuffer();
- return ret_off;
- } else {
- m_o_streambuf->SetIntPosition( DoTellOutput() - pos);
- return pos;
- }
- case wxFromCurrent:
- if ( ((unsigned)pos > m_o_streambuf->GetLastAccess()) || (pos < 0) ) {
- ret_off = DoSeekOutput(pos, wxFromCurrent);
- m_o_streambuf->ResetBuffer();
- return ret_off;
- } else {
- m_o_streambuf->SetIntPosition(pos);
- return pos;
- }
- case wxFromEnd:
- // Hard to compute: always seek to the requested position.
- ret_off = DoSeekOutput(pos, wxFromEnd);
- m_o_streambuf->ResetBuffer();
- return ret_off;
- }
- return wxInvalidOffset;
+ return m_o_streambuf->Tell();
}
-off_t wxOutputStream::TellO() const
+off_t wxOutputStream::SeekO(off_t pos, wxSeekMode mode)
{
- return DoTellOutput() - m_o_streambuf->GetLastAccess()
- + m_o_streambuf->GetIntPosition();
+ return m_o_streambuf->Seek(pos, mode);
}
void wxOutputStream::Sync()
{
- DoWrite(m_o_streambuf->GetBufferStart(), m_o_streambuf->GetIntPosition());
-
- m_o_streambuf->ResetBuffer();
+ m_o_streambuf->FlushBuffer();
}
wxOutputStream& wxOutputStream::operator<<(const char *string)
}
#endif
-// ----------------------------------------------------------------------------
-// wxStream
-// ----------------------------------------------------------------------------
-
-wxStream::wxStream()
- : wxInputStream(), wxOutputStream()
-{
-}
-
// ----------------------------------------------------------------------------
// wxFilterInputStream
// ----------------------------------------------------------------------------
wxFilterInputStream::wxFilterInputStream()
: wxInputStream(NULL)
{
+ // WARNING streambuf set to NULL !
}
wxFilterInputStream::wxFilterInputStream(wxInputStream& stream)
- : wxInputStream(NULL)
+ : wxInputStream(stream.InputStreamBuffer())
{
m_parent_i_stream = &stream;
- wxDELETE(m_i_streambuf); // In case m_i_streambuf has been initialized.
- m_i_destroybuf = FALSE;
- m_i_streambuf = stream.InputStreamBuffer();
}
wxFilterInputStream::~wxFilterInputStream()
{
}
-size_t wxFilterInputStream::DoRead(void *buffer, size_t size)
-{
- return m_parent_i_stream->Read(buffer, size).LastRead();
-}
-
-off_t wxFilterInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
-{
- return m_parent_i_stream->SeekI(pos, mode);
-}
-
-off_t wxFilterInputStream::DoTellInput() const
-{
- return m_parent_i_stream->TellI();
-}
-
// ----------------------------------------------------------------------------
// wxFilterOutputStream
// ----------------------------------------------------------------------------
}
wxFilterOutputStream::wxFilterOutputStream(wxOutputStream& stream)
- : wxOutputStream(NULL)
+ : wxOutputStream(stream.OutputStreamBuffer())
{
m_parent_o_stream = &stream;
- wxDELETE(m_o_streambuf); // In case m_o_streambuf has been initialized.
- m_o_destroybuf = FALSE;
- m_o_streambuf = stream.OutputStreamBuffer();
}
wxFilterOutputStream::~wxFilterOutputStream()
{
}
-size_t wxFilterOutputStream::DoWrite(const void *buffer, size_t size)
-{
- return m_parent_o_stream->Write(buffer, size).LastWrite();
-}
-
-off_t wxFilterOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode)
-{
- return m_parent_o_stream->SeekO(pos, mode);
-}
-
-off_t wxFilterOutputStream::DoTellOutput() const
-{
- return m_parent_o_stream->TellO();
-}
-
-// ----------------------------------------------------------------------------
-// wxFilterStream
-// ----------------------------------------------------------------------------
-
-wxFilterStream::wxFilterStream()
-{
-}
-
-wxFilterStream::wxFilterStream(wxStream& stream)
- : wxFilterInputStream(stream), wxFilterOutputStream(stream)
-{
-}
-
// ----------------------------------------------------------------------------
// Some IOManip function
// ----------------------------------------------------------------------------
# endif
#endif
+#include "wx/stream.h"
#include "wx/string.h"
#include "wx/variant.h"
virtual bool Eq(wxVariantData& data) const;
virtual bool Write(ostream& str) const;
virtual bool Write(wxString& str) const;
+ virtual bool Write(wxOutputStream &str) const;
virtual bool Read(istream& str);
+ virtual bool Read(wxInputStream& str);
virtual bool Read(wxString& str);
virtual wxString GetType() const { return "long"; };
return TRUE;
}
+bool wxVariantDataLong::Write(wxOutputStream& str) const
+{
+ str << m_value;
+ return TRUE;
+}
+
bool wxVariantDataLong::Write(wxString& str) const
{
str.Printf("%ld", m_value);
return TRUE;
}
+bool wxVariantDataLong::Read(wxInputStream& str)
+{
+ str >> m_value;
+ return TRUE;
+}
+
bool wxVariantDataLong::Read(wxString& str)
{
m_value = atol((const char*) str);
virtual bool Eq(wxVariantData& data) const;
virtual bool Write(ostream& str) const;
virtual bool Write(wxString& str) const;
+ virtual bool Write(wxOutputStream &str) const;
virtual bool Read(istream& str);
+ virtual bool Read(wxInputStream& str);
virtual bool Read(wxString& str);
virtual wxString GetType() const { return "double"; };
return TRUE;
}
+bool wxVariantDataReal::Write(wxOutputStream& str) const
+{
+ str << m_value;
+ return TRUE;
+}
+
bool wxVariantDataReal::Write(wxString& str) const
{
str.Printf("%.4f", m_value);
return TRUE;
}
+bool wxVariantDataReal::Read(wxInputStream& str)
+{
+ str >> (float&)m_value;
+ return TRUE;
+}
+
bool wxVariantDataReal::Read(wxString& str)
{
m_value = atof((const char*) str);
virtual void Copy(wxVariantData& data);
virtual bool Eq(wxVariantData& data) const;
virtual bool Write(ostream& str) const;
+ virtual bool Write(wxOutputStream& str) const;
virtual bool Write(wxString& str) const;
virtual bool Read(istream& str);
+ virtual bool Read(wxInputStream& str);
virtual bool Read(wxString& str);
virtual wxString GetType() const { return "bool"; };
return TRUE;
}
+bool wxVariantDataBool::Write(wxOutputStream& str) const
+{
+ str << (char)m_value;
+ return TRUE;
+}
+
bool wxVariantDataBool::Write(wxString& str) const
{
str.Printf("%d", (int) m_value);
return FALSE;
}
+bool wxVariantDataBool::Read(wxInputStream& str)
+{
+ str >> (char&)m_value;
+ return TRUE;
+}
+
bool wxVariantDataBool::Read(wxString& str)
{
m_value = (atol((const char*) str) != 0);
virtual void Copy(wxVariantData& data);
virtual bool Eq(wxVariantData& data) const;
virtual bool Write(ostream& str) const;
+ virtual bool Write(wxOutputStream& str) const;
virtual bool Write(wxString& str) const;
virtual bool Read(istream& str);
+ virtual bool Read(wxInputStream& str);
virtual bool Read(wxString& str);
virtual wxString GetType() const { return "char"; };
return TRUE;
}
+bool wxVariantDataChar::Write(wxOutputStream& str) const
+{
+ str << m_value;
+ return TRUE;
+}
+
bool wxVariantDataChar::Write(wxString& str) const
{
str.Printf("%c", m_value);
return FALSE;
}
+bool wxVariantDataChar::Read(wxInputStream& str)
+{
+ str >> m_value;
+ return TRUE;
+}
+
bool wxVariantDataChar::Read(wxString& str)
{
m_value = str[(size_t)0];
virtual void Copy(wxVariantData& data);
virtual bool Eq(wxVariantData& data) const;
virtual bool Write(ostream& str) const;
+ virtual bool Write(wxOutputStream& str) const;
virtual bool Write(wxString& str) const;
virtual bool Read(istream& str);
+ virtual bool Read(wxInputStream& str);
virtual bool Read(wxString& str);
virtual wxString GetType() const { return "string"; };
return TRUE;
}
+bool wxVariantDataString::Write(wxOutputStream& str) const
+{
+ str << m_value;
+ return TRUE;
+}
+
bool wxVariantDataString::Write(wxString& str) const
{
str = m_value;
return TRUE;
}
+bool wxVariantDataString::Read(wxInputStream& str)
+{
+ str >> m_value;
+ return TRUE;
+}
+
bool wxVariantDataString::Read(wxString& str)
{
m_value = str;
int err;
// I need a private stream buffer.
- m_i_streambuf = new wxStreamBuffer(*this);
+ m_i_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::read);
m_i_destroybuf = TRUE;
m_inflate = new z_stream_s;
delete m_inflate;
}
-size_t wxZlibInputStream::DoRead(void *buffer, size_t size)
+size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size)
{
int err;
m_inflate->next_in = m_z_buffer;
m_inflate->avail_in = m_parent_i_stream->LastRead();
- if (m_parent_i_stream->Eof())
+ if (m_parent_i_stream->LastError() != wxStream_NOERROR)
return (size - m_inflate->avail_in);
}
err = inflate(m_inflate, Z_FINISH);
return size-m_inflate->avail_in;
}
-bool wxZlibInputStream::Eof() const
-{
- if (!m_eof)
- return m_parent_i_stream->Eof();
- return m_eof;
-}
-
//////////////////////
// wxZlibOutputStream
//////////////////////
{
int err;
- m_o_streambuf = new wxStreamBuffer(*this);
+ m_o_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::write);
m_o_destroybuf = TRUE;
m_deflate = new z_stream_s;
err = deflate(m_deflate, Z_FULL_FLUSH);
if (err != Z_OK) {
- m_bad = TRUE;
return;
}
m_deflate->avail_out = m_z_size;
}
-size_t wxZlibOutputStream::DoWrite(const void *buffer, size_t size)
+size_t wxZlibOutputStream::OnSysWrite(const void *buffer, size_t size)
{
int err;
if (m_deflate->avail_out == 0) {
m_parent_o_stream->Write(m_z_buffer, m_z_size);
- if (m_parent_o_stream->Bad())
+ if (m_parent_o_stream->LastError() != wxStream_NOERROR)
return (size - m_deflate->avail_in);
m_deflate->next_out = m_z_buffer;
}
return size;
}
-
-bool wxZlibOutputStream::Bad() const
-{
- if (!m_bad)
- return m_parent_o_stream->Bad();
- return m_bad;
-}
void wxComboBox::Copy(void)
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_copy_clipboard( GTK_EDITABLE(entry) );
+#else
gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
+#endif
}
void wxComboBox::Cut(void)
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_cut_clipboard( GTK_EDITABLE(entry) );
+#else
gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
+#endif
}
void wxComboBox::Paste(void)
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_paste_clipboard( GTK_EDITABLE(entry) );
+#else
gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
+#endif
}
void wxComboBox::SetInsertionPoint( long pos )
void wxTextCtrl::Cut()
{
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) );
+#else
gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 );
+#endif
}
void wxTextCtrl::Copy()
{
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) );
+#else
gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 );
+#endif
}
void wxTextCtrl::Paste()
{
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) );
+#else
gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 );
+#endif
}
void wxTextCtrl::Clear()
#include <gdk/gdk.h>
-
/////////////////////////////////////////////////////////////////////////////
// Static variables
/////////////////////////////////////////////////////////////////////////////
close(p_thrd_pipe[0]);
close(p_thrd_pipe[1]);
}
+
+#ifdef NO_DEFINE_GDK_1_1
+
+void wxMutexGuiEnter()
+{
+ gdk_mutex_enter();
+}
+
+void wxMutexGuiLeave()
+{
+ gdk_mutex_leave();
+}
+
+#else
+
+void wxMutexGuiEnter()
+{
+ wxMainMutex.Lock();
+}
+
+void wxMutexGuiLeave()
+{
+ wxMainMutex.Unlock();
+}
+
+#endif
/////////////////////////////////////////////////////////////////////////// */
#include "wx/gtk/win_gtk.h"
+#include <gtk/gtkfeatures.h>
#ifdef __cplusplus
extern "C" {
static void gtk_myfixed_remove (GtkContainer *container,
GtkWidget *widget);
static void gtk_myfixed_foreach (GtkContainer *container,
+#if (GTK_MINOR_VERSION == 1)
+ gboolean include_internals,
+#endif
GtkCallback callback,
gpointer callback_data);
container_class->add = gtk_myfixed_add;
container_class->remove = gtk_myfixed_remove;
+#if (GTK_MINOR_VERSION == 1)
+ container_class->forall = gtk_myfixed_foreach;
+#else
container_class->foreach = gtk_myfixed_foreach;
+#endif
}
static void
static void
gtk_myfixed_foreach (GtkContainer *container,
+#if (GTK_MINOR_VERSION == 1)
+ gboolean include_internals,
+#endif
GtkCallback callback,
gpointer callback_data)
{
void wxComboBox::Copy(void)
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_copy_clipboard( GTK_EDITABLE(entry) );
+#else
gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
+#endif
}
void wxComboBox::Cut(void)
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_cut_clipboard( GTK_EDITABLE(entry) );
+#else
gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
+#endif
}
void wxComboBox::Paste(void)
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_paste_clipboard( GTK_EDITABLE(entry) );
+#else
gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
+#endif
}
void wxComboBox::SetInsertionPoint( long pos )
void wxTextCtrl::Cut()
{
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) );
+#else
gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 );
+#endif
}
void wxTextCtrl::Copy()
{
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) );
+#else
gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 );
+#endif
}
void wxTextCtrl::Paste()
{
+#if (GTK_MINOR_VERSION == 1)
+ gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) );
+#else
gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 );
+#endif
}
void wxTextCtrl::Clear()
#include <gdk/gdk.h>
-
/////////////////////////////////////////////////////////////////////////////
// Static variables
/////////////////////////////////////////////////////////////////////////////
close(p_thrd_pipe[0]);
close(p_thrd_pipe[1]);
}
+
+#ifdef NO_DEFINE_GDK_1_1
+
+void wxMutexGuiEnter()
+{
+ gdk_mutex_enter();
+}
+
+void wxMutexGuiLeave()
+{
+ gdk_mutex_leave();
+}
+
+#else
+
+void wxMutexGuiEnter()
+{
+ wxMainMutex.Lock();
+}
+
+void wxMutexGuiLeave()
+{
+ wxMainMutex.Unlock();
+}
+
+#endif
/////////////////////////////////////////////////////////////////////////// */
#include "wx/gtk/win_gtk.h"
+#include <gtk/gtkfeatures.h>
#ifdef __cplusplus
extern "C" {
static void gtk_myfixed_remove (GtkContainer *container,
GtkWidget *widget);
static void gtk_myfixed_foreach (GtkContainer *container,
+#if (GTK_MINOR_VERSION == 1)
+ gboolean include_internals,
+#endif
GtkCallback callback,
gpointer callback_data);
container_class->add = gtk_myfixed_add;
container_class->remove = gtk_myfixed_remove;
+#if (GTK_MINOR_VERSION == 1)
+ container_class->forall = gtk_myfixed_foreach;
+#else
container_class->foreach = gtk_myfixed_foreach;
+#endif
}
static void
static void
gtk_myfixed_foreach (GtkContainer *container,
+#if (GTK_MINOR_VERSION == 1)
+ gboolean include_internals,
+#endif
GtkCallback callback,
gpointer callback_data)
{
WXDIR = $(WXWIN)
# Set all these to 1 if you want to build a dynamic library
-#DLL=1
-#WXMAKINGDLL=1
-#WXBUILDDLL=1
+!if "$(DLL)" == "1"
+WXMAKINGDLL=1
+WXBUILDDLL=1
+!endif
!include $(WXDIR)\src\makeb32.env
WXDIR = $(WXWIN)
-DLL=1
+!if "$(DLL)" == "1"
WXBUILDDLL=1
WXUSINGDLL=1
+!endif
!include $(WXDIR)\src\makeb32.env