textctrl.h \
textdlg.h \
textfile.h \
+ txtstrm.h \
thread.h \
time.h \
timer.h \
#if wxUSE_STREAMS
-class WXDLLEXPORT wxDataInputStream: public wxFilterInputStream {
+class WXDLLEXPORT wxDataInputStream {
public:
wxDataInputStream(wxInputStream& s);
- virtual ~wxDataInputStream();
+ ~wxDataInputStream();
wxUint32 Read32();
wxUint16 Read16();
wxUint8 Read8();
double ReadDouble();
wxString ReadString();
+
+ wxDataInputStream& operator>>(wxString& s);
+ wxDataInputStream& operator>>(wxInt8& c);
+ wxDataInputStream& operator>>(wxInt16& i);
+ wxDataInputStream& operator>>(wxInt32& i);
+ wxDataInputStream& operator>>(wxUint8& c);
+ wxDataInputStream& operator>>(wxUint16& i);
+ wxDataInputStream& operator>>(wxUint32& i);
+ wxDataInputStream& operator>>(double& i);
+ wxDataInputStream& operator>>(float& f);
+ protected:
+ wxInputStream *m_input;
};
-class WXDLLEXPORT wxDataOutputStream: public wxFilterOutputStream {
+class WXDLLEXPORT wxDataOutputStream {
public:
wxDataOutputStream(wxOutputStream& s);
- virtual ~wxDataOutputStream();
+ ~wxDataOutputStream();
void Write32(wxUint32 i);
void Write16(wxUint16 i);
void Write8(wxUint8 i);
void WriteDouble(double d);
void WriteString(const wxString& string);
+
+ wxDataOutputStream& operator<<(const wxChar *string);
+ wxDataOutputStream& operator<<(wxString& string);
+ wxDataOutputStream& operator<<(wxInt8 c);
+ wxDataOutputStream& operator<<(wxInt16 i);
+ wxDataOutputStream& operator<<(wxInt32 i);
+ wxDataOutputStream& operator<<(wxUint8 c);
+ wxDataOutputStream& operator<<(wxUint16 i);
+ wxDataOutputStream& operator<<(wxUint32 i);
+ wxDataOutputStream& operator<<(double f);
+ wxDataOutputStream& operator<<(float f);
+
+ protected:
+ wxOutputStream *m_output;
};
#endif
wxSocketInternal *m_internal;
int m_fd;
};
+#endif
class SocketRequester
#if wxUSE_THREADS
bool WaitFor(wxSocketBase::wxRequestNotify req, int millisec);
+#if wxUSE_THREADS
// Thread Entry point
// ---
virtual void *Entry();
+#endif
public:
wxSocketBase *m_socket;
wxSocketInternal *m_internal;
int m_fd;
};
-#endif
- // wxUSE_THREADS
class wxSocketInternal {
public:
void QueueRequest(SockRequest *request, bool async);
void WaitForEnd(SockRequest *request);
+ // Used by SocketRequester
SockRequest *WaitForReq();
void EndRequest(SockRequest *req);
public:
WXDLLEXPORT wxOutputStream& wxEndL(wxOutputStream& o_stream);
-// ---------------------------------------------------------------------------
-// Stream buffer
-// ---------------------------------------------------------------------------
-
-class WXDLLEXPORT wxStreamBuffer {
- public:
- typedef enum {
- read = 0, write, read_write
- } BufMode;
-
- // -----------
- // ctor & dtor
- // -----------
- wxStreamBuffer(wxStreamBase& stream, BufMode mode);
- wxStreamBuffer(BufMode mode);
- wxStreamBuffer(const wxStreamBuffer& buf);
- ~wxStreamBuffer();
-
- // -----------
- // Filtered IO
- // -----------
- size_t Read(void *buffer, size_t size);
- size_t Read(wxStreamBuffer *buf);
- size_t Write(const void *buffer, size_t size);
- size_t Write(wxStreamBuffer *buf);
-
- size_t WriteBack(const char *buffer, size_t size);
- bool WriteBack(char c);
- char GetChar();
- void PutChar(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);
- 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; }
- void Flushable(bool f) { m_flushable = f; }
-
- bool FlushBuffer();
- bool FillBuffer();
- size_t GetDataLeft();
-
- // --------------
- // Administration
- // --------------
- wxStreamBase *Stream() { return m_stream; }
-
- 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;
-
- char *m_wback;
- size_t m_wbacksize, m_wbackcur;
-
- bool m_fixed, m_flushable;
-
- wxStreamBase *m_stream;
- BufMode m_mode;
- bool m_destroybuf, m_destroystream;
-};
-
// ---------------------------------------------------------------------------
// wxStream: base classes
// ---------------------------------------------------------------------------
virtual size_t StreamSize() const { return ~((size_t)0); }
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 OnSysTell() const;
protected:
+ friend class wxStreamBuffer;
+
size_t m_lastcount;
wxStreamError m_lasterror;
};
class WXDLLEXPORT wxInputStream: public wxStreamBase {
public:
wxInputStream();
- wxInputStream(wxStreamBuffer *sbuf);
virtual ~wxInputStream();
// IO functions
char GetC();
virtual wxInputStream& Read(void *buffer, size_t size);
wxInputStream& Read(wxOutputStream& stream_out);
- wxString ReadLine();
// Position functions
- off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
- off_t TellI() const;
+ virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
+ virtual off_t TellI() const;
// State functions
- wxStreamBuffer *InputStreamBuffer() { return m_i_streambuf; }
- size_t LastRead() { return wxStreamBase::m_lastcount; }
+ virtual size_t LastRead() { return wxStreamBase::m_lastcount; }
+
+ // Ungetch
+ size_t Ungetch(void *buffer, size_t size);
+ bool Ungetch(char c);
// Operators
wxInputStream& operator>>(wxOutputStream& out) { return Read(out); }
- wxInputStream& operator>>(wxString& line);
- wxInputStream& operator>>(char& c);
- wxInputStream& operator>>(signed short& i);
- wxInputStream& operator>>(signed int& i);
- wxInputStream& operator>>(signed long& i);
- wxInputStream& operator>>(unsigned char& c);
- wxInputStream& operator>>(unsigned short& i);
- wxInputStream& operator>>(unsigned int& i);
- wxInputStream& operator>>(unsigned long& i);
- wxInputStream& operator>>(double& i);
- wxInputStream& operator>>(float& f) { double d; operator>>((double&)d); f = (float)d; return *this; }
#if wxUSE_SERIAL
wxInputStream& operator>>(wxObject *& obj);
#endif
wxInputStream& operator>>( __wxInputManip func) { return func(*this); }
protected:
- bool m_i_destroybuf;
- wxStreamBuffer *m_i_streambuf;
+ // Ungetch managers
+ char *m_wback;
+ size_t m_wbacksize;
+ size_t m_wbackcur;
+
+ char *AllocSpaceWBack(size_t needed_size);
+ size_t GetWBack(char *buf, size_t bsize);
+
};
class WXDLLEXPORT wxOutputStream: public wxStreamBase {
public:
wxOutputStream();
- wxOutputStream(wxStreamBuffer *sbuf);
virtual ~wxOutputStream();
virtual wxOutputStream& Write(const void *buffer, size_t size);
wxOutputStream& Write(wxInputStream& stream_in);
- void WriteLine(const wxString& line);
- off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
- off_t TellO() const;
+ virtual off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
+ virtual off_t TellO() const;
- size_t LastWrite() const { return wxStreamBase::m_lastcount; }
- wxStreamBuffer *OutputStreamBuffer() { return m_o_streambuf; }
+ virtual size_t LastWrite() const { return wxStreamBase::m_lastcount; }
- void Sync();
+ virtual void Sync();
wxOutputStream& operator<<(wxInputStream& out) { return Write(out); }
- wxOutputStream& operator<<(const char *string);
- wxOutputStream& operator<<(wxString& string);
- wxOutputStream& operator<<(char c);
- wxOutputStream& operator<<(signed short i);
- wxOutputStream& operator<<(signed int i);
- wxOutputStream& operator<<(signed long i);
- wxOutputStream& operator<<(unsigned char c);
- wxOutputStream& operator<<(unsigned short i);
- wxOutputStream& operator<<(unsigned int i);
- wxOutputStream& operator<<(unsigned long i);
- wxOutputStream& operator<<(double f);
- wxOutputStream& operator<<(float f) { return operator<<((double)f); }
#if wxUSE_SERIAL
wxOutputStream& operator<<(wxObject& obj);
#endif
wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); }
-
- protected:
- bool m_o_destroybuf;
- wxStreamBuffer *m_o_streambuf;
};
// ---------------------------------------------------------------------------
wxOutputStream *m_parent_o_stream;
};
+// ---------------------------------------------------------------------------
+// Stream buffer
+// ---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxStreamBuffer {
+ public:
+ typedef enum {
+ read = 0, write, read_write
+ } BufMode;
+
+ // -----------
+ // ctor & dtor
+ // -----------
+ wxStreamBuffer(wxStreamBase& stream, BufMode mode);
+ wxStreamBuffer(BufMode mode);
+ wxStreamBuffer(const wxStreamBuffer& buf);
+ ~wxStreamBuffer();
+
+ // -----------
+ // Filtered IO
+ // -----------
+ size_t Read(void *buffer, size_t size);
+ size_t Read(wxStreamBuffer *buf);
+ size_t Write(const void *buffer, size_t size);
+ size_t Write(wxStreamBuffer *buf);
+
+ char GetChar();
+ void PutChar(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);
+ 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; }
+ void Flushable(bool f) { m_flushable = f; }
+
+ bool FlushBuffer();
+ bool FillBuffer();
+ size_t GetDataLeft();
+
+ // --------------
+ // Administration
+ // --------------
+ wxStreamBase *Stream() { return m_stream; }
+
+ protected:
+ 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;
+
+ char *m_wback;
+ size_t m_wbacksize, m_wbackcur;
+
+ bool m_fixed, m_flushable;
+
+ wxStreamBase *m_stream;
+ BufMode m_mode;
+ bool m_destroybuf, m_destroystream;
+};
+
+// ---------------------------------------------------------------------------
+// wxBufferedStreams
+// ---------------------------------------------------------------------------
+
+class wxBufferedInputStream: public wxFilterInputStream {
+ public:
+ wxBufferedInputStream(wxInputStream& stream);
+ ~wxBufferedInputStream();
+
+ wxInputStream& Read(void *buffer, size_t size);
+
+ // Position functions
+ off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
+ off_t TellI() const;
+
+ wxStreamBuffer *InputStreamBuffer() const { return m_i_streambuf; }
+
+ protected:
+ size_t OnSysRead(void *buffer, size_t bufsize);
+ off_t OnSysSeek(off_t seek, wxSeekMode mode);
+ off_t OnSysTell() const;
+
+ protected:
+ wxStreamBuffer *m_i_streambuf;
+};
+
+class wxBufferedOutputStream: public wxFilterOutputStream {
+ public:
+ wxBufferedOutputStream(wxOutputStream& stream);
+ ~wxBufferedOutputStream();
+
+ wxOutputStream& Write(const void *buffer, size_t size);
+
+ // Position functions
+ off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
+ off_t TellO() const;
+
+ void Sync();
+
+ wxStreamBuffer *OutputStreamBuffer() const { return m_o_streambuf; }
+
+ protected:
+ size_t OnSysWrite(const void *buffer, size_t bufsize);
+ off_t OnSysSeek(off_t seek, wxSeekMode mode);
+ off_t OnSysTell() const;
+
+ protected:
+ wxStreamBuffer *m_o_streambuf;
+};
+
#endif
// wxUSE_STREAMS
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: txtstrm.h
+// Purpose: Text stream classes
+// Author: Guilhem Lavaux
+// Modified by:
+// Created: 28/06/1998
+// RCS-ID: $Id$
+// Copyright: (c) Guilhem Lavaux
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_TXTSTREAM_H_
+#define _WX_TXTSTREAM_H_
+
+#ifdef __GNUG__
+#pragma interface "txtstrm.h"
+#endif
+
+#include <wx/stream.h>
+
+#if wxUSE_STREAMS
+
+class WXDLLEXPORT wxTextInputStream {
+public:
+ wxTextInputStream(wxInputStream& s);
+ ~wxTextInputStream();
+
+ wxUint32 Read32();
+ wxUint16 Read16();
+ wxUint8 Read8();
+ double ReadDouble();
+ wxString ReadString();
+
+ // Operators
+ wxTextInputStream& operator>>(wxString& line);
+ wxTextInputStream& operator>>(wxInt8& c);
+ wxTextInputStream& operator>>(wxInt16& i);
+ wxTextInputStream& operator>>(wxInt32& i);
+ wxTextInputStream& operator>>(wxUint8& c);
+ wxTextInputStream& operator>>(wxUint16& i);
+ wxTextInputStream& operator>>(wxUint32& i);
+ wxTextInputStream& operator>>(double& i);
+ wxTextInputStream& operator>>(float& f);
+
+ protected:
+ wxInputStream *m_input;
+};
+
+class WXDLLEXPORT wxTextOutputStream {
+ public:
+ wxTextOutputStream(wxOutputStream& s);
+ ~wxTextOutputStream();
+
+ void Write32(wxUint32 i);
+ void Write16(wxUint16 i);
+ void Write8(wxUint8 i);
+ void WriteDouble(double d);
+ void WriteString(const wxString& string);
+
+ wxTextOutputStream& operator<<(const wxChar *string);
+ wxTextOutputStream& operator<<(const wxString& string);
+ wxTextOutputStream& operator<<(wxInt8 c);
+ wxTextOutputStream& operator<<(wxInt16 c);
+ wxTextOutputStream& operator<<(wxInt32 c);
+ wxTextOutputStream& operator<<(wxUint8 c);
+ wxTextOutputStream& operator<<(wxUint16 c);
+ wxTextOutputStream& operator<<(wxUint32 c);
+ wxTextOutputStream& operator<<(double f);
+ wxTextOutputStream& operator<<(float f);
+
+ protected:
+ wxOutputStream *m_output;
+};
+
+#endif
+ // wxUSE_STREAMS
+
+#endif
+ // _WX_DATSTREAM_H_
#include "wx/wfstream.h"
#include "wx/datstrm.h"
-
+#include "wx/txtstrm.h"
// Create a new application object
IMPLEMENT_APP (MyApp)
ofstream std_file_output( "test_std.dat" );
wxFileOutputStream file_output( "test_wx.dat" );
+ wxBufferedOutputStream buf_output( file_output );
+ wxTextOutputStream text_output( buf_output );
wxString tmp;
signed int si = 0xFFFFFFFF;
tmp.Printf( "Signed int: %d\n", si );
textCtrl.WriteText( tmp );
- file_output << si << "\n";
+ text_output << si << "\n";
std_file_output << si << "\n";
unsigned int ui = 0xFFFFFFFF;
tmp.Printf( "Unsigned int: %u\n", ui );
textCtrl.WriteText( tmp );
- file_output << ui << "\n";
+ text_output << ui << "\n";
std_file_output << ui << "\n";
double d = 2.01234567890123456789;
tmp.Printf( "Double: %f\n", d );
textCtrl.WriteText( tmp );
- file_output << d << "\n";
+ text_output << d << "\n";
std_file_output << d << "\n";
float f = 0.00001;
tmp.Printf( "Float: %f\n", f );
textCtrl.WriteText( tmp );
- file_output << f << "\n";
+ text_output << f << "\n";
std_file_output << f << "\n";
wxString str( "Hello!" );
tmp.Printf( "String: %s\n", str.c_str() );
textCtrl.WriteText( tmp );
- file_output << str << "\n";
+ text_output << str << "\n";
std_file_output << str.c_str() << "\n";
textCtrl.WriteText( "\nReading from ifstream:\n" );
textCtrl.WriteText( "\nReading from wxFileInputStream:\n" );
- file_output.OutputStreamBuffer()->FlushBuffer();
+ buf_output.Sync();
wxFileInputStream file_input( "test_wx.dat" );
+ wxBufferedInputStream buf_input( file_input );
+ wxTextInputStream text_input( buf_input );
- file_input >> si;
+ text_input >> si;
tmp.Printf( "Signed int: %d\n", si );
textCtrl.WriteText( tmp );
- file_input >> ui;
+ text_input >> ui;
tmp.Printf( "Unsigned int: %u\n", ui );
textCtrl.WriteText( tmp );
- file_input >> d;
+ text_input >> d;
tmp.Printf( "Double: %f\n", d );
textCtrl.WriteText( tmp );
- file_input >> f;
+ text_input >> f;
tmp.Printf( "Float: %f\n", f );
textCtrl.WriteText( tmp );
- file_input >> str;
+ text_input >> str;
tmp.Printf( "String: %s\n", str.c_str() );
textCtrl.WriteText( tmp );
textCtrl.WriteText( "Writing to wxDataOutputStream:\n" );
file_output.SeekO( 0 );
- wxDataOutputStream data_output( file_output );
+ wxDataOutputStream data_output( buf_output );
wxInt16 i16 = 0xFFFF;
tmp.Printf( "Signed int16: %d\n", (int)i16 );
textCtrl.WriteText( tmp );
data_output.WriteString( str );
- file_output.OutputStreamBuffer()->FlushBuffer();
+ buf_output.Sync();
textCtrl.WriteText( "\nReading from wxDataInputStream:\n" );
file_input.SeekI( 0 );
- wxDataInputStream data_input( file_input );
+ wxDataInputStream data_input( buf_input );
i16 = data_input.Read16();
tmp.Printf( "Signed int16: %d\n", (int)i16 );
// ---------------------------------------------------------------------------
wxDataInputStream::wxDataInputStream(wxInputStream& s)
- : wxFilterInputStream(s)
+ : m_input(&s)
{
}
{
char buf[4];
- Read(buf, 4);
+ m_input->Read(buf, 4);
return (wxUint32)buf[0] |
((wxUint32)buf[1] << 8) |
{
char buf[2];
- Read(buf, 2);
+ m_input->Read(buf, 2);
return (wxUint16)buf[0] |
((wxUint16)buf[1] << 8);
{
wxUint8 buf;
- Read((char *)&buf, 1);
+ m_input->Read((char *)&buf, 1);
return (wxUint8)buf;
}
#if wxUSE_APPLE_IEEE
char buf[10];
- Read(buf, 10);
+ m_input->Read(buf, 10);
return ConvertFromIeeeExtended((unsigned char *)buf);
#else
return 0.0;
len = Read32();
string = new char[len+1];
- Read(string, len);
+ m_input->Read(string, len);
string[len] = 0;
wx_string = string;
return wx_string;
}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxString& s)
+{
+ s = ReadString();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxInt8& c)
+{
+ c = (wxInt8)Read8();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxInt16& i)
+{
+ i = (wxInt16)Read16();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxInt32& i)
+{
+ i = (wxInt32)Read32();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxUint8& c)
+{
+ c = Read8();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxUint16& i)
+{
+ i = Read16();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxUint32& i)
+{
+ i = Read32();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(double& i)
+{
+ i = ReadDouble();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(float& f)
+{
+ f = (float)ReadDouble();
+ return *this;
+}
// ---------------------------------------------------------------------------
// wxDataOutputStream
// ---------------------------------------------------------------------------
wxDataOutputStream::wxDataOutputStream(wxOutputStream& s)
- : wxFilterOutputStream(s)
+ : m_output(&s)
{
}
buf[1] = (i >> 8) & 0xff;
buf[2] = (i >> 16) & 0xff;
buf[3] = (i >> 24) & 0xff;
- Write(buf, 4);
+ m_output->Write(buf, 4);
}
void wxDataOutputStream::Write16(wxUint16 i)
buf[0] = i & 0xff;
buf[1] = (i >> 8) & 0xff;
- Write(buf, 2);
+ m_output->Write(buf, 2);
}
void wxDataOutputStream::Write8(wxUint8 i)
{
- Write(&i, 1);
+ m_output->Write(&i, 1);
}
void wxDataOutputStream::WriteString(const wxString& string)
{
Write32(string.Length());
- Write((const wxChar *) string, string.Length()*sizeof(wxChar));
+ m_output->Write((const wxChar *) string, string.Length()*sizeof(wxChar));
}
// Must be at global scope for VC++ 5
# pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
buf[0] = '\0';
#endif
- Write(buf, 10);
+ m_output->Write(buf, 10);
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(const wxChar *string)
+{
+ Write32(wxStrlen(string));
+ m_output->Write((const char *)string, wxStrlen(string)*sizeof(wxChar));
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(wxString& string)
+{
+ WriteString(string);
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(wxInt8 c)
+{
+ Write8((wxUint8)c);
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(wxInt16 i)
+{
+ Write16((wxUint16)i);
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(wxInt32 i)
+{
+ Write32((wxUint32)i);
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(wxUint8 c)
+{
+ Write8(c);
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(wxUint16 i)
+{
+ Write16(i);
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(wxUint32 i)
+{
+ Write32(i);
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(double f)
+{
+ WriteDouble(f);
+ return *this;
+}
+
+wxDataOutputStream& wxDataOutputStream::operator<<(float f)
+{
+ WriteDouble((double)f);
+ return *this;
}
#endif
#include "wx/tokenzr.h"
#include "wx/socket.h"
#include "wx/protocol/protocol.h"
+#include "wx/url.h"
#include "wx/protocol/http.h"
#include "wx/sckstrm.h"
bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
{
- char *tmp_buf;
- char buf[HTTP_BSIZE];
- const wxWX2MBbuf pathbuf = path.mb_str();
+ wxChar *tmp_buf;
+ wxCharBuffer buf("");
+ const wxWX2MBbuf pathbuf;
+ wxString tmp_str;
switch (req) {
case wxHTTP_GET:
- tmp_buf = "GET";
+ tmp_buf = _T("GET");
break;
default:
return FALSE;
SetFlags(NONE);
Notify(FALSE);
- sprintf(buf, "%s %s\n\r", tmp_buf, (const char*) pathbuf);
- Write(buf, strlen(buf));
+ tmp_str = wxURL::ConvertToValidURI(path);
+ wxSprintf(buf, _T("%s %s\n\r"), tmp_buf, tmp_str.GetData());
+ pathbuf = wxConvLibc.cWX2MB(buf);
+ Write(pathbuf, strlen(pathbuf));
SendHeaders();
- sprintf(buf, "\n\r");
- Write(buf, strlen(buf));
-
- wxString tmp_str;
+ Write("\n\r", 2);
m_error = GetLine(this, tmp_str);
if (m_error != wxPROTO_NOERR) {
wxMemoryInputStream::wxMemoryInputStream(const char *data, size_t len)
: wxInputStream()
{
+/*
m_i_streambuf->SetBufferIO((char*) data, (char*) (data+len));
m_i_streambuf->SetIntPosition(0); // seek to start pos
m_i_streambuf->Fixed(TRUE);
+*/
m_length = len;
}
char wxMemoryInputStream::Peek()
{
+/*
return m_i_streambuf->GetBufferStart()[m_i_streambuf->GetIntPosition()];
+*/
+ return 0;
}
// ----------------------------------------------------------------------------
wxMemoryOutputStream::wxMemoryOutputStream(char *data, size_t len)
: wxOutputStream()
{
+/*
if (data)
m_o_streambuf->SetBufferIO(data, data+len);
m_o_streambuf->Fixed(TRUE);
+*/
}
wxMemoryOutputStream::~wxMemoryOutputStream()
return NULL;
}
+#endif
+
// --------------------------------------------------------------
// --------- SocketRequester ------------------------------------
// --------------------------------------------------------------
m_internal->EndRequest(req);
}
+
+#if wxUSE_THREADS
void *SocketRequester::Entry()
{
SockRequest *req;
m_codeco->WriteString(data);
else {
m_codeco->Write32(size);
- m_codeco->Write(data, size);
+ m_sockstrm->Write(data, size);
}
return TRUE;
s = m_codeci->Read32();
data = new char[s];
- m_codeci->Read(data, s);
+ m_sockstrm->Read(data, s);
if (size)
*size = s;
m_codeco->WriteString(data);
else {
m_codeco->Write32(size);
- m_codeco->Write(data, size);
+ m_sockstrm->Write(data, size);
}
return TRUE;
m_codeco->WriteString(data);
else {
m_codeco->Write32(size);
- m_codeco->Write(data, size);
+ m_sockstrm->Write(data, size);
}
return TRUE;
wxTCPConnection *connection = (wxTCPConnection *)cdata;
wxDataInputStream *codeci;
wxDataOutputStream *codeco;
+ wxSocketStream *sockstrm;
wxString topic_name = connection->m_topic;
wxString item;
// Receive message number.
codeci = connection->m_codeci;
codeco = connection->m_codeco;
+ sockstrm = connection->m_sockstrm;
msg = codeci->Read8();
switch (msg) {
format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32();
data = new char[size];
- codeci->Read(data, size);
+ sockstrm->Read(data, size);
connection->OnExecute (topic_name, data, size, format);
format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32();
data = new char[size];
- codeci->Read(data, size);
+ sockstrm->Read(data, size);
connection->OnAdvise (topic_name, item, data, size, format);
format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32();
data = new wxChar[size];
- codeci->Read(data, size);
+ sockstrm->Read(data, size);
connection->OnPoke (topic_name, item, data, size, format);
codeco->Write8(IPC_REQUEST_REPLY);
if (user_size != -1) {
codeco->Write32(user_size);
- codeco->Write(user_data, user_size);
+ sockstrm->Write(user_data, user_size);
} else
codeco->WriteString(user_data);
} else
wxStreamBuffer::wxStreamBuffer(wxStreamBase& stream, BufMode mode)
: m_buffer_start(NULL), m_buffer_end(NULL), m_buffer_pos(NULL),
- m_buffer_size(0), m_wback(NULL), m_wbacksize(0), m_wbackcur(0),
- m_fixed(TRUE), m_flushable(TRUE), m_stream(&stream),
+ m_buffer_size(0), m_fixed(TRUE), m_flushable(TRUE), m_stream(&stream),
m_mode(mode), m_destroybuf(FALSE), m_destroystream(FALSE)
{
}
wxStreamBuffer::wxStreamBuffer(BufMode mode)
: m_buffer_start(NULL), m_buffer_end(NULL), m_buffer_pos(NULL),
- m_buffer_size(0), m_wback(NULL), m_wbacksize(0), m_wbackcur(0),
- m_fixed(TRUE), m_flushable(FALSE), m_stream(NULL),
+ m_buffer_size(0), m_fixed(TRUE), m_flushable(FALSE), m_stream(NULL),
m_mode(mode), m_destroybuf(FALSE), m_destroystream(TRUE)
{
m_stream = new wxStreamBase();
m_mode = buffer.m_mode;
m_destroybuf = FALSE;
m_destroystream = FALSE;
- m_wback = NULL;
- m_wbacksize = 0;
- m_wbackcur = 0;
}
wxStreamBuffer::~wxStreamBuffer()
{
- if (m_wback)
- free(m_wback);
if (m_destroybuf)
wxDELETEA(m_buffer_start);
if (m_destroystream)
delete m_stream;
}
-size_t wxStreamBuffer::WriteBack(const char *buf, size_t bufsize)
-{
- char *ptrback;
-
- if (m_mode != read)
- return 0;
-
- ptrback = AllocSpaceWBack(bufsize);
- if (!ptrback)
- return 0;
-
- memcpy(ptrback, buf, bufsize);
- return bufsize;
-}
-
-bool wxStreamBuffer::WriteBack(char c)
-{
- char *ptrback;
-
- ptrback = AllocSpaceWBack(1);
- if (!ptrback)
- return FALSE;
-
- *ptrback = c;
- return TRUE;
-}
-
void wxStreamBuffer::SetBufferIO(char *buffer_start, char *buffer_end)
{
if (m_destroybuf)
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;
- m_wback = temp_b;
-
- return (char *)(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;
// ------------------
m_stream->m_lasterror = wxStream_NOERROR;
- m_stream->m_lastcount = GetWBack((char *)buffer, size);
- size -= m_stream->m_lastcount;
- if (size == 0)
- return m_stream->m_lastcount;
-
- buffer = (void *)((char *)buffer+m_stream->m_lastcount);
-
if (!m_buffer_size)
return (m_stream->m_lastcount += m_stream->OnSysRead(buffer, size));
{
char buf[BUF_TEMP_SIZE];
size_t s = 0, bytes_count = BUF_TEMP_SIZE, b_count2;
+ wxInputStream *in_stream;
if (m_mode == read)
return 0;
+ in_stream = (wxInputStream *)sbuf->Stream();
+
while (bytes_count == BUF_TEMP_SIZE) {
b_count2 = sbuf->Read(buf, bytes_count);
bytes_count = Write(buf, b_count2);
if (b_count2 > bytes_count)
- sbuf->WriteBack(buf+bytes_count, b_count2-bytes_count);
+ in_stream->Ungetch(buf+bytes_count, b_count2-bytes_count);
s += bytes_count;
}
return s;
// ----------------------------------------------------------------------------
wxInputStream::wxInputStream()
- : wxStreamBase()
+ : wxStreamBase(),
+ m_wback(NULL), m_wbacksize(0), m_wbackcur(0)
{
- m_i_destroybuf = TRUE;
- m_i_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::read);
}
-wxInputStream::wxInputStream(wxStreamBuffer *buffer)
- : wxStreamBase()
+wxInputStream::~wxInputStream()
{
- m_i_destroybuf = FALSE;
- m_i_streambuf = buffer;
+ if (m_wback)
+ free(m_wback);
}
-wxInputStream::~wxInputStream()
+char *wxInputStream::AllocSpaceWBack(size_t needed_size)
{
- if (m_i_destroybuf)
- delete m_i_streambuf;
+ 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;
+ m_wback = temp_b;
+
+ return (char *)(m_wback+(m_wbacksize-needed_size));
}
-char wxInputStream::GetC()
+size_t wxInputStream::GetWBack(char *buf, size_t bsize)
{
- char c;
- m_i_streambuf->Read(&c, 1);
- return c;
+ 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;
}
+size_t wxInputStream::Ungetch(void *buf, size_t bufsize)
+{
+ char *ptrback;
+
+ ptrback = AllocSpaceWBack(bufsize);
+ if (!ptrback)
+ return 0;
-wxString wxInputStream::ReadLine()
+ memcpy(ptrback, buf, bufsize);
+ return bufsize;
+}
+
+bool wxInputStream::Ungetch(char c)
{
- char c, last_endl = 0;
- bool end_line = FALSE;
- wxString line;
+ char *ptrback;
- while (!end_line) {
- c = GetC();
- if (LastError() != wxStream_NOERROR)
- break;
+ ptrback = AllocSpaceWBack(1);
+ if (!ptrback)
+ return FALSE;
- switch (c) {
- case '\n':
- end_line = TRUE;
- break;
- case '\r':
- last_endl = '\r';
- break;
- default:
- if (last_endl == '\r') {
- end_line = TRUE;
- InputStreamBuffer()->WriteBack(c);
- break;
- }
- line += c;
- break;
- }
- }
- return line;
+ *ptrback = c;
+ return TRUE;
+}
+
+char wxInputStream::GetC()
+{
+ char c;
+ Read(&c, 1);
+ return c;
}
wxInputStream& wxInputStream::Read(void *buffer, size_t size)
{
- m_i_streambuf->Read(buffer, size);
- // wxStreamBuffer sets all variables for us
+ size_t retsize;
+ char *buf = (char *)buffer;
+
+ retsize = GetWBack(buf, size);
+ if (retsize == size) {
+ m_lastcount = size;
+ m_lasterror = wxStream_NOERROR;
+ return *this;
+ }
+ size -= retsize;
+ buf += retsize;
+
+ m_lastcount = OnSysRead(buf, size);
return *this;
}
char wxInputStream::Peek()
{
- m_i_streambuf->GetDataLeft();
+ char c;
- return *(m_i_streambuf->GetBufferPos());
+ Read(&c, 1);
+ if (m_lasterror == wxStream_NOERROR) {
+ Ungetch(c);
+ return c;
+ }
+ return 0;
}
-
wxInputStream& wxInputStream::Read(wxOutputStream& stream_out)
{
char buf[BUF_TEMP_SIZE];
off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode)
{
- return m_i_streambuf->Seek(pos, mode);
+ return wxInvalidOffset;
}
off_t wxInputStream::TellI() const
{
- return m_i_streambuf->Tell();
+ return wxInvalidOffset;
}
// --------------------
// Overloaded operators
// --------------------
-wxInputStream& wxInputStream::operator>>(wxString& line)
+#if wxUSE_SERIAL
+wxInputStream& wxInputStream::operator>>(wxObject *& obj)
{
- line = ReadLine();
+ wxObjectInputStream obj_s(*this);
+ obj = obj_s.LoadObject();
return *this;
}
+#endif
-wxInputStream& wxInputStream::operator>>(char& c)
-{
- c = GetC();
- return *this;
-}
-wxInputStream& wxInputStream::operator>>(signed short& i)
+// ----------------------------------------------------------------------------
+// wxOutputStream
+// ----------------------------------------------------------------------------
+wxOutputStream::wxOutputStream()
+ : wxStreamBase()
{
- signed long l;
-
- *this >> l;
- i = (signed short)l;
- return *this;
}
-wxInputStream& wxInputStream::operator>>(signed int& i)
+wxOutputStream::~wxOutputStream()
{
- signed long l;
-
- *this >> l;
- i = (signed int)l;
- return *this;
}
-wxInputStream& wxInputStream::operator>>(signed long& i)
+wxOutputStream& wxOutputStream::Write(const void *buffer, size_t size)
{
- /* I only implemented a simple integer parser */
- int c;
- int sign;
-
- while (isspace( c = GetC() ) )
- /* Do nothing */ ;
-
- i = 0;
- if (! (c == '-' || isdigit(c)) ) {
- InputStreamBuffer()->WriteBack(c);
- return *this;
- }
-
- if (c == '-') {
- sign = -1;
- c = GetC();
- } else if (c == '+') {
- sign = 1;
- c = GetC();
- } else {
- sign = 1;
- }
-
- while (isdigit(c)) {
- i = i*10 + (c - (int)'0');
- c = GetC();
- }
-
- i *= sign;
-
+ m_lastcount = OnSysWrite(buffer, size);
return *this;
}
-wxInputStream& wxInputStream::operator>>(unsigned short& i)
+wxOutputStream& wxOutputStream::Write(wxInputStream& stream_in)
{
- unsigned long l;
-
- *this >> l;
- i = (unsigned short)l;
+ stream_in.Read(*this);
return *this;
}
-wxInputStream& wxInputStream::operator>>(unsigned int& i)
+off_t wxOutputStream::TellO() const
{
- unsigned long l;
-
- *this >> l;
- i = (unsigned int)l;
- return *this;
+ return wxInvalidOffset;
}
-wxInputStream& wxInputStream::operator>>(unsigned long& i)
+off_t wxOutputStream::SeekO(off_t pos, wxSeekMode mode)
{
- /* I only implemented a simple integer parser */
- int c;
-
- while (isspace( c = GetC() ) )
- /* Do nothing */ ;
-
- i = 0;
- if (!isdigit(c)) {
- InputStreamBuffer()->WriteBack(c);
- return *this;
- }
-
- while (isdigit(c)) {
- i = i*10 + c - '0';
- c = GetC();
- }
-
- return *this;
+ return wxInvalidOffset;
}
-wxInputStream& wxInputStream::operator>>(double& f)
+void wxOutputStream::Sync()
{
- /* I only implemented a simple float parser */
- int c, sign;
-
- while (isspace( c = GetC() ) )
- /* Do nothing */ ;
-
- f = 0.0;
- if (! (c == '-' || isdigit(c)) ) {
- InputStreamBuffer()->WriteBack(c);
- return *this;
- }
-
- if (c == '-') {
- sign = -1;
- c = GetC();
- } else if (c == '+') {
- sign = 1;
- c = GetC();
- } else {
- sign = 1;
- }
-
- while (isdigit(c)) {
- f = f*10 + (c - '0');
- c = GetC();
- }
-
- if (c == '.') {
- double f_multiplicator = (double) 0.1;
- c = GetC();
-
- while (isdigit(c)) {
- f += (c-'0')*f_multiplicator;
- f_multiplicator /= 10;
- c = GetC();
- }
- }
-
- f *= sign;
-
- return *this;
}
#if wxUSE_SERIAL
-wxInputStream& wxInputStream::operator>>(wxObject *& obj)
+wxOutputStream& wxOutputStream::operator<<(wxObject& obj)
{
- wxObjectInputStream obj_s(*this);
- obj = obj_s.LoadObject();
+ wxObjectOutputStream obj_s(*this);
+ obj_s.SaveObject(obj);
return *this;
}
#endif
-
// ----------------------------------------------------------------------------
-// wxOutputStream
+// wxFilterInputStream
// ----------------------------------------------------------------------------
-wxOutputStream::wxOutputStream()
- : wxStreamBase()
+wxFilterInputStream::wxFilterInputStream()
+ : wxInputStream()
{
- m_o_destroybuf = TRUE;
- m_o_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::write);
}
-wxOutputStream::wxOutputStream(wxStreamBuffer *buffer)
- : wxStreamBase()
+wxFilterInputStream::wxFilterInputStream(wxInputStream& stream)
+ : wxInputStream()
{
- m_o_destroybuf = FALSE;
- m_o_streambuf = buffer;
+ m_parent_i_stream = &stream;
}
-wxOutputStream::~wxOutputStream()
+wxFilterInputStream::~wxFilterInputStream()
{
- if (m_o_destroybuf)
- delete m_o_streambuf;
}
-wxOutputStream& wxOutputStream::Write(const void *buffer, size_t size)
+// ----------------------------------------------------------------------------
+// wxFilterOutputStream
+// ----------------------------------------------------------------------------
+wxFilterOutputStream::wxFilterOutputStream()
+ : wxOutputStream()
{
- m_o_streambuf->Write(buffer, size);
- return *this;
}
-wxOutputStream& wxOutputStream::Write(wxInputStream& stream_in)
+wxFilterOutputStream::wxFilterOutputStream(wxOutputStream& stream)
+ : wxOutputStream()
{
- stream_in.Read(*this);
- return *this;
+ m_parent_o_stream = &stream;
}
-off_t wxOutputStream::TellO() const
+wxFilterOutputStream::~wxFilterOutputStream()
{
- return m_o_streambuf->Tell();
}
-off_t wxOutputStream::SeekO(off_t pos, wxSeekMode mode)
+// ----------------------------------------------------------------------------
+// wxBufferedInputStream
+// ----------------------------------------------------------------------------
+wxBufferedInputStream::wxBufferedInputStream(wxInputStream& s)
+ : wxFilterInputStream(s)
{
- return m_o_streambuf->Seek(pos, mode);
+ m_i_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::read);
+ m_i_streambuf->SetBufferIO(1024);
}
-void wxOutputStream::Sync()
+wxBufferedInputStream::~wxBufferedInputStream()
{
- m_o_streambuf->FlushBuffer();
+ delete m_i_streambuf;
}
-void wxOutputStream::WriteLine(const wxString& line)
+wxInputStream& wxBufferedInputStream::Read(void *buffer, size_t size)
{
-#ifdef __WXMSW__
- wxString tmp_string = line + _T("\r\n");
-#else
-#ifdef __WXMAC__
- wxString tmp_string = line + _T('\r');
-#else
- wxString tmp_string = line + _T('\n');
-#endif
-#endif
+ size_t retsize;
+ char *buf = (char *)buffer;
- Write((const wxChar *) tmp_string, tmp_string.Length()*sizeof(wxChar));
-}
+ retsize = GetWBack(buf, size);
+ if (retsize == size) {
+ m_lastcount = size;
+ m_lasterror = wxStream_NOERROR;
+ return *this;
+ }
+ size -= retsize;
+ buf += retsize;
-wxOutputStream& wxOutputStream::operator<<(const char *string)
-{
- return Write(string, strlen(string));
-}
+ m_i_streambuf->Read(buf, size);
-wxOutputStream& wxOutputStream::operator<<(wxString& string)
-{
-#if wxUSE_UNICODE
- const wxWX2MBbuf buf = string.mb_str();
- return *this << buf;
-#else
- return Write(string, string.Len());
-#endif
+ return *this;
}
-wxOutputStream& wxOutputStream::operator<<(char c)
+off_t wxBufferedInputStream::SeekI(off_t pos, wxSeekMode mode)
{
- return Write(&c, 1);
+ return m_i_streambuf->Seek(pos, mode);
}
-wxOutputStream& wxOutputStream::operator<<(signed short i)
+off_t wxBufferedInputStream::TellI() const
{
- signed long l = (signed long)i;
- return *this << l;
+ return m_i_streambuf->Tell();
}
-wxOutputStream& wxOutputStream::operator<<(signed int i)
+size_t wxBufferedInputStream::OnSysRead(void *buffer, size_t bufsize)
{
- signed long l = (signed long)i;
- return *this << l;
+ return m_parent_i_stream->Read(buffer, bufsize).LastRead();
}
-wxOutputStream& wxOutputStream::operator<<(signed long i)
+off_t wxBufferedInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
{
- wxString strlong;
- strlong.Printf(_T("%ld"), i);
- return *this << strlong;
+ return m_parent_i_stream->SeekI(seek, mode);
}
-wxOutputStream& wxOutputStream::operator<<(unsigned short i)
+off_t wxBufferedInputStream::OnSysTell() const
{
- unsigned long l = (unsigned long)i;
- return *this << l;
+ return m_parent_i_stream->TellI();
}
-wxOutputStream& wxOutputStream::operator<<(unsigned int i)
-{
- unsigned long l = (unsigned long)i;
- return *this << l;
-}
+// ----------------------------------------------------------------------------
+// wxBufferedOutputStream
+// ----------------------------------------------------------------------------
-wxOutputStream& wxOutputStream::operator<<(unsigned long i)
+wxBufferedOutputStream::wxBufferedOutputStream(wxOutputStream& s)
+ : wxFilterOutputStream(s)
{
- wxString strlong;
- strlong.Printf(_T("%lu"), i);
- return *this << strlong;
+ m_o_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::write);
+ m_o_streambuf->SetBufferIO(1024);
}
-wxOutputStream& wxOutputStream::operator<<(double f)
+wxBufferedOutputStream::~wxBufferedOutputStream()
{
- wxString strfloat;
-
- strfloat.Printf(_T("%f"), f);
- return *this << strfloat;
+ delete m_o_streambuf;
}
-#if wxUSE_SERIAL
-wxOutputStream& wxOutputStream::operator<<(wxObject& obj)
+wxOutputStream& wxBufferedOutputStream::Write(const void *buffer, size_t size)
{
- wxObjectOutputStream obj_s(*this);
- obj_s.SaveObject(obj);
+ m_o_streambuf->Write(buffer, size);
return *this;
}
-#endif
-// ----------------------------------------------------------------------------
-// wxFilterInputStream
-// ----------------------------------------------------------------------------
-wxFilterInputStream::wxFilterInputStream()
- : wxInputStream(NULL)
+off_t wxBufferedOutputStream::SeekO(off_t pos, wxSeekMode mode)
{
- // WARNING streambuf set to NULL !
+ return m_o_streambuf->Seek(pos, mode);
}
-wxFilterInputStream::wxFilterInputStream(wxInputStream& stream)
- : wxInputStream(stream.InputStreamBuffer())
+off_t wxBufferedOutputStream::TellO() const
{
- m_parent_i_stream = &stream;
+ return m_o_streambuf->Tell();
}
-wxFilterInputStream::~wxFilterInputStream()
+void wxBufferedOutputStream::Sync()
{
+ m_o_streambuf->FlushBuffer();
+ m_parent_o_stream->Sync();
}
-// ----------------------------------------------------------------------------
-// wxFilterOutputStream
-// ----------------------------------------------------------------------------
-wxFilterOutputStream::wxFilterOutputStream()
- : wxOutputStream(NULL)
+size_t wxBufferedOutputStream::OnSysWrite(const void *buffer, size_t bufsize)
{
+ return m_parent_o_stream->Write(buffer, bufsize).LastWrite();
}
-wxFilterOutputStream::wxFilterOutputStream(wxOutputStream& stream)
- : wxOutputStream(stream.OutputStreamBuffer())
+off_t wxBufferedOutputStream::OnSysSeek(off_t seek, wxSeekMode mode)
{
- m_parent_o_stream = &stream;
+ return m_parent_o_stream->SeekO(seek, mode);
}
-wxFilterOutputStream::~wxFilterOutputStream()
+off_t wxBufferedOutputStream::OnSysTell() const
{
+ return m_parent_o_stream->TellO();
}
// ----------------------------------------------------------------------------
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////////
+// Name: txtstrm.cpp
+// Purpose: Text stream classes
+// Author: Guilhem Lavaux
+// Modified by:
+// Created: 28/06/98
+// RCS-ID: $Id$
+// Copyright: (c) Guilhem Lavaux
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "txtstrm.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#if wxUSE_STREAMS
+
+#include "wx/txtstrm.h"
+
+wxTextInputStream::wxTextInputStream(wxInputStream& s)
+ : m_input(&s)
+{
+}
+
+wxTextInputStream::~wxTextInputStream()
+{
+}
+
+wxUint32 wxTextInputStream::Read32()
+{
+ /* I only implemented a simple integer parser */
+ int c;
+ int sign;
+ wxInt32 i;
+
+ while (isspace( c = m_input->GetC() ) )
+ /* Do nothing */ ;
+
+ i = 0;
+ if (! (c == '-' || isdigit(c)) ) {
+ m_input->Ungetch(c);
+ return 0;
+ }
+
+ if (c == '-') {
+ sign = -1;
+ c = m_input->GetC();
+ } else if (c == '+') {
+ sign = 1;
+ c = m_input->GetC();
+ } else {
+ sign = 1;
+ }
+
+ while (isdigit(c)) {
+ i = i*10 + (c - (int)'0');
+ c = m_input->GetC();
+ }
+
+ if (c != '\n' && c != '\r')
+ m_input->Ungetch(c);
+
+ i *= sign;
+
+ return (wxUint32)i;
+}
+
+wxUint16 wxTextInputStream::Read16()
+{
+ return (wxUint16)Read32();
+}
+
+wxUint8 wxTextInputStream::Read8()
+{
+ return (wxUint8)Read32();
+}
+
+double wxTextInputStream::ReadDouble()
+{
+ /* I only implemented a simple float parser */
+ double f;
+ int c, sign;
+
+ while (isspace( c = m_input->GetC() ) || c == '\n' || c == '\r')
+ /* Do nothing */ ;
+
+ f = 0.0;
+ if (! (c == '-' || isdigit(c)) ) {
+ m_input->Ungetch(c);
+ return 0.0;
+ }
+
+ if (c == '-') {
+ sign = -1;
+ c = m_input->GetC();
+ } else if (c == '+') {
+ sign = 1;
+ c = m_input->GetC();
+ } else {
+ sign = 1;
+ }
+
+ while (isdigit(c)) {
+ f = f*10 + (c - '0');
+ c = m_input->GetC();
+ }
+
+ if (c == '.') {
+ double f_multiplicator = (double) 0.1;
+
+ c = m_input->GetC();
+
+ while (isdigit(c)) {
+ f += (c-'0')*f_multiplicator;
+ f_multiplicator /= 10;
+ c = m_input->GetC();
+ }
+
+ if (c == 'e') {
+ double f_multiplicator = 0.0;
+ int i, e;
+
+ c = m_input->GetC();
+
+ switch(c) {
+ case '-':
+ f_multiplicator = 0.1;
+ break;
+ case '+':
+ f_multiplicator = 10.0;
+ break;
+ }
+
+ e = Read8();
+
+ for (i=0;i<e;i++)
+ f *= f_multiplicator;
+ } else if (c != '\n' && c != '\r')
+ m_input->Ungetch(c);
+
+ }
+
+ f *= sign;
+
+ return f;
+}
+
+wxString wxTextInputStream::ReadString()
+{
+ char c, last_endl = 0;
+ bool end_line = FALSE;
+ wxString line;
+
+ while (!end_line) {
+ c = m_input->GetC();
+ if (m_input->LastError() != wxStream_NOERROR)
+ break;
+
+ switch (c) {
+ case '\n':
+ end_line = TRUE;
+ break;
+ case '\r':
+ last_endl = '\r';
+ break;
+ default:
+ if (last_endl == '\r') {
+ end_line = TRUE;
+ m_input->Ungetch(c);
+ break;
+ }
+ line += c;
+ break;
+ }
+ }
+ return line;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(wxString& line)
+{
+ line = ReadString();
+ return *this;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(wxInt8& c)
+{
+ c = (wxInt8)Read8();
+ return *this;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(wxInt16& i)
+{
+ i = (wxInt16)Read16();
+ return *this;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(wxInt32& i)
+{
+ i = (wxInt32)Read32();
+ return *this;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(wxUint8& c)
+{
+ c = Read8();
+ return *this;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(wxUint16& i)
+{
+ i = Read16();
+ return *this;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(wxUint32& i)
+{
+ i = Read32();
+ return *this;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(double& i)
+{
+ i = ReadDouble();
+ return *this;
+}
+
+wxTextInputStream& wxTextInputStream::operator>>(float& f)
+{
+ f = (float)ReadDouble();
+ return *this;
+}
+
+wxTextOutputStream::wxTextOutputStream(wxOutputStream& s)
+ : m_output(&s)
+{
+}
+
+wxTextOutputStream::~wxTextOutputStream()
+{
+}
+
+void wxTextOutputStream::Write32(wxUint32 i)
+{
+ wxString str;
+
+ str.Printf(_T("%u"), i);
+ WriteString(str);
+}
+
+void wxTextOutputStream::Write16(wxUint16 i)
+{
+ wxString str;
+
+ str.Printf(_T("%u"), i);
+ WriteString(str);
+}
+
+void wxTextOutputStream::Write8(wxUint8 i)
+{
+ wxString str;
+
+ str.Printf(_T("%u"), i);
+ WriteString(str);
+}
+
+void wxTextOutputStream::WriteDouble(double d)
+{
+ wxString str;
+
+ str.Printf(_T("%f"), d);
+ WriteString(str);
+}
+
+void wxTextOutputStream::WriteString(const wxString& string)
+{
+#if wxUSE_UNICODE
+ const wxWX2MBbuf buf = string.mb_str();
+ m_output->Write(buf, string.Len());
+#else
+ m_output->Write(string, string.Len());
+#endif
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(const wxChar *string)
+{
+ WriteString(wxString(string));
+ return *this;
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(const wxString& string)
+{
+ WriteString(string);
+ return *this;
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(wxInt8 c)
+{
+ Write8((wxUint8)c);
+ return *this;
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(wxInt16 c)
+{
+ Write16((wxUint16)c);
+ return *this;
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(wxInt32 c)
+{
+ Write32((wxUint32)c);
+ return *this;
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(wxUint8 c)
+{
+ Write8(c);
+ return *this;
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(wxUint16 c)
+{
+ Write16(c);
+ return *this;
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(wxUint32 c)
+{
+ Write32(c);
+ return *this;
+}
+
+wxTextOutputStream &wxTextOutputStream::operator<<(double f)
+{
+ WriteDouble(f);
+ return *this;
+}
+
+wxTextOutputStream& wxTextOutputStream::operator<<(float f)
+{
+ WriteDouble((double)f);
+ return *this;
+}
+
+#endif
+ // wxUSE_STREAMS
wxProtoInfo *wxURL::g_protocols = NULL;
wxHTTP *wxURL::g_proxy;
-/////////////////////////////////////////////////////////////////
-// wxURL ////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
+// --------------------------------------------------------------
+// wxURL
+// --------------------------------------------------------------
-/*
- * --------------------------------------------------------------
- * --------- wxURL CONSTRUCTOR DESTRUCTOR -----------------------
- * --------------------------------------------------------------
- */
+// --------------------------------------------------------------
+// --------- wxURL CONSTRUCTOR DESTRUCTOR -----------------------
+// --------------------------------------------------------------
wxURL::wxURL(const wxString& url)
{
CleanData();
}
-/*
- * --------------------------------------------------------------
- * --------- wxURL urls decoders --------------------------------
- * --------------------------------------------------------------
- */
+// --------------------------------------------------------------
+// --------- wxURL urls decoders --------------------------------
+// --------------------------------------------------------------
+
bool wxURL::PrepProto(wxString& url)
{
int pos;
return FALSE;
}
-/*
- * --------------------------------------------------------------
- * --------- wxURL get ------------------------------------------
- * --------------------------------------------------------------
- */
+// --------------------------------------------------------------
+// --------- wxURL get ------------------------------------------
+// --------------------------------------------------------------
+
wxInputStream *wxURL::GetInputStream(void)
{
wxIPV4address addr;
wxString wxURL::ConvertToValidURI(const wxString& uri)
{
- return wxString(uri);
+ wxString out_str;
+ wxString hexa_code;
+ size_t i;
+
+ for (i=0;i<uri.Len();i++) {
+ wxChar c = uri.GetChar(i);
+
+ if (!isalpha(c) && c != _T('.') && c != _T('+') && c != _T('.') &&
+ c != _T('/')) {
+ hexa_code.Printf(_T("%02X"), c);
+ out_str += hexa_code;
+ } else
+ out_str += c;
+ }
+
+ return out_str;
}
#endif
pControl->SetSelection(*m_pInt) ;
return TRUE;
}
- }
+ } else
#endif
- else if (m_validatorWindow->IsKindOf(CLASSINFO(wxStaticText)) )
+ if (m_validatorWindow->IsKindOf(CLASSINFO(wxStaticText)) )
{
wxStaticText* pControl = (wxStaticText*) m_validatorWindow;
if (m_pString)
#endif
// wxUSE_VALIDATORS
-
\ No newline at end of file
+
# include <fstream>
#endif
+#if wxUSE_STREAMS
#include "wx/stream.h"
+#include "wx/txtstrm.h"
+#endif
+
#include "wx/string.h"
#include "wx/variant.h"
#if wxUSE_STREAMS
bool wxVariantDataLong::Write(wxOutputStream& str) const
{
- str << m_value;
+ wxTextOutputStream s(str);
+
+ s.Write32(m_value);
return TRUE;
}
bool wxVariantDataLong::Read(wxInputStream& str)
{
- str >> m_value;
+ wxTextInputStream s(str);
+ m_value = s.Read32();
return TRUE;
}
#endif // wxUSE_STREAMS
#if wxUSE_STREAMS
bool wxVariantDataReal::Write(wxOutputStream& str) const
{
- str << m_value;
+ wxTextOutputStream s(str);
+ s.WriteDouble((double)m_value);
return TRUE;
}
bool wxVariantDataReal::Read(wxInputStream& str)
{
- str >> (float&)m_value;
+ wxTextInputStream s(str);
+ m_value = (float)s.ReadDouble();
return TRUE;
}
#endif // wxUSE_STREAMS
#if wxUSE_STREAMS
bool wxVariantDataBool::Write(wxOutputStream& str) const
{
- str << (char)m_value;
+ wxTextOutputStream s(str);
+
+ s.Write8(m_value);
return TRUE;
}
bool wxVariantDataBool::Read(wxInputStream& str)
{
- str >> (char&)m_value;
+ wxTextInputStream s(str);
+
+ m_value = s.Read8();
return TRUE;
}
#endif // wxUSE_STREAMS
#if wxUSE_STREAMS
bool wxVariantDataChar::Write(wxOutputStream& str) const
{
- str << m_value;
+ wxTextOutputStream s(str);
+
+ s.Write8(m_value);
return TRUE;
}
bool wxVariantDataChar::Read(wxInputStream& str)
{
- str >> m_value;
+ wxTextInputStream s(str);
+
+ m_value = s.Read8();
return TRUE;
}
#endif // wxUSE_STREAMS
bool wxVariantDataString::Write(wxOutputStream& str) const
{
// why doesn't wxOutputStream::operator<< take "const wxString&"
- str << (const char*) m_value.mb_str();
+ wxTextOutputStream s(str);
+ s.WriteString(m_value);
return TRUE;
}
bool wxVariantDataString::Read(wxInputStream& str)
{
- str >> m_value;
+ wxTextInputStream s(str);
+
+ m_value = s.ReadString();
return TRUE;
}
#endif // wxUSE_STREAMS
{
m_file = new wxFile(fileName, wxFile::read);
m_file_destroy = TRUE;
- m_i_streambuf->SetBufferIO(1024);
}
wxFileInputStream::wxFileInputStream()
{
m_file = &file;
m_file_destroy = FALSE;
- m_i_streambuf->SetBufferIO(1024);
}
wxFileInputStream::wxFileInputStream(int fd)
{
m_file = new wxFile(fd);
m_file_destroy = TRUE;
- m_i_streambuf->SetBufferIO(1024);
}
wxFileInputStream::~wxFileInputStream()
size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
{
- return m_file->Read(buffer, size);
+ off_t ret;
+
+ ret = m_file->Read(buffer, size);
+
+ if (m_file->Eof())
+ m_lasterror = wxStream_EOF;
+ if (ret == wxInvalidOffset) {
+ m_lasterror = wxStream_READ_ERR;
+ ret = 0;
+ }
+
+ return ret;
}
off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
{
m_file = new wxFile(fileName, wxFile::write);
m_file_destroy = TRUE;
- m_o_streambuf->SetBufferIO(1024);
}
wxFileOutputStream::wxFileOutputStream(wxFile& file)
{
m_file = &file;
m_file_destroy = FALSE;
- m_o_streambuf->SetBufferIO(1024);
}
wxFileOutputStream::wxFileOutputStream()
: wxOutputStream()
{
- m_o_streambuf->SetBufferIO(1024);
m_file_destroy = FALSE;
m_file = NULL;
}
{
m_file = new wxFile(fd);
m_file_destroy = TRUE;
- m_o_streambuf->SetBufferIO(1024);
}
wxFileOutputStream::~wxFileOutputStream()
int err;
// I need a private stream buffer.
- m_i_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::read);
- m_i_destroybuf = TRUE;
m_inflate = new z_stream_s;
m_inflate->zalloc = (alloc_func)0;
{
int err;
- m_o_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::write);
- m_o_destroybuf = TRUE;
m_deflate = new z_stream_s;
m_deflate->zalloc = (alloc_func)0;
tbarbase.cpp \
tbarsmpl.cpp \
textfile.cpp \
+ txtstrm.cpp \
time.cpp \
timercmn.cpp \
tokenzr.cpp \
tbarbase.cpp \
tbarsmpl.cpp \
textfile.cpp \
+ txtstrm.cpp \
time.cpp \
timercmn.cpp \
tokenzr.cpp \
tbarbase.cpp \
tbarsmpl.cpp \
textfile.cpp \
+ txtstrm.cpp \
time.cpp \
url.cpp \
valgen.cpp \
$(MSWDIR)\tabctrl.obj \
$(MSWDIR)\tbarmsw.obj \
$(MSWDIR)\textctrl.obj \
+ $(MSWDIR)\txtstrm.obj \
$(MSWDIR)\thread.obj \
$(MSWDIR)\timer.obj \
$(MSWDIR)\tooltip.obj \
$(MSWDIR)\textctrl.obj: $(MSWDIR)\textctrl.$(SRCSUFF)
+$(MSWDIR)\txtstrm.obj: $(MSWDIR)\txtstrm.$(SRCSUFF)
+
$(MSWDIR)\thread.obj: $(MSWDIR)\thread.$(SRCSUFF)
$(MSWDIR)\timer.obj: $(MSWDIR)\timer.$(SRCSUFF)
..\msw\$D\tbar95.obj \
..\msw\$D\tbarmsw.obj \
..\msw\$D\textctrl.obj \
+ ..\msw\$D\txtstrm.obj \
..\msw\$D\thread.obj \
..\msw\$D\timer.obj \
..\msw\$D\tooltip.obj \
wxThread::ExitCode wxThread::Delete()
{
+ if (IsPaused())
+ Resume();
+
m_critsect.Enter();
wxThreadState state = p_internal->GetState();