]> git.saurik.com Git - wxWidgets.git/commitdiff
* New wxStreams (to be documented), new classes: wxBufferedStreams,
authorGuilhem Lavaux <lavaux@easynet.fr>
Wed, 7 Jul 1999 17:45:35 +0000 (17:45 +0000)
committerGuilhem Lavaux <lavaux@easynet.fr>
Wed, 7 Jul 1999 17:45:35 +0000 (17:45 +0000)
  wxTextStreams

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2962 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

24 files changed:
include/wx/Makefile.am
include/wx/datstrm.h
include/wx/sckint.h
include/wx/stream.h
include/wx/txtstrm.h [new file with mode: 0644]
samples/typetest/typetest.cpp
src/common/datstrm.cpp
src/common/http.cpp
src/common/mstream.cpp
src/common/sckint.cpp
src/common/sckipc.cpp
src/common/stream.cpp
src/common/txtstrm.cpp [new file with mode: 0644]
src/common/url.cpp
src/common/valgen.cpp
src/common/variant.cpp
src/common/wfstream.cpp
src/common/zstream.cpp
src/gtk/Makefile.am
src/gtk1/Makefile.am
src/motif/Makefile.am
src/msw/makefile.b32
src/msw/makefile.vc
src/unix/threadpsx.cpp

index e9bcd162bdb16eceff3969f35f102690fe5b9bd5..05ca03688ccdfb5d531dc524aa2671bdabb83eaf 100644 (file)
@@ -153,6 +153,7 @@ wx_include_HEADERS = \
  textctrl.h \
  textdlg.h \
  textfile.h \
+ txtstrm.h \
  thread.h \
  time.h \
  timer.h \
index 40537e32912b014ef346f706bd912f0e4a53a042..1b38a486b375e5fbce6b96cf3af0e73936d122bf 100644 (file)
 
 #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
index 1b1ae550836949d48f7393dfdba4152a8f10e866..103595f5f6a7d30b3ce755838452394b6de25408 100644 (file)
@@ -83,6 +83,7 @@ class SocketWaiter: public wxThread {
   wxSocketInternal *m_internal;
   int m_fd;
 };
+#endif
 
 class SocketRequester
 #if wxUSE_THREADS
@@ -99,17 +100,17 @@ class SocketRequester
 
   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:
@@ -134,6 +135,7 @@ class wxSocketInternal {
   void QueueRequest(SockRequest *request, bool async);
   void WaitForEnd(SockRequest *request);
 
+  // Used by SocketRequester
   SockRequest *WaitForReq();
   void EndRequest(SockRequest *req);
  public:
index 508ca1a25801a093fdff136eab821fd5cdb6cc5d..7e0045323c31fefdc93e81175751456ec8b0581a 100644 (file)
@@ -34,85 +34,6 @@ typedef wxOutputStream& (*__wxOutputManip)(wxOutputStream&);
 
 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
 // ---------------------------------------------------------------------------
@@ -138,7 +59,6 @@ class WXDLLEXPORT wxStreamBase {
   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);
@@ -146,6 +66,8 @@ class WXDLLEXPORT wxStreamBase {
   virtual off_t OnSysTell() const;
 
  protected:
+  friend class wxStreamBuffer;
+
   size_t m_lastcount;
   wxStreamError m_lasterror;
 };
@@ -153,7 +75,6 @@ class WXDLLEXPORT wxStreamBase {
 class WXDLLEXPORT wxInputStream: public wxStreamBase {
  public:
   wxInputStream();
-  wxInputStream(wxStreamBuffer *sbuf);
   virtual ~wxInputStream();
 
   // IO functions
@@ -161,78 +82,56 @@ class WXDLLEXPORT wxInputStream: public wxStreamBase {
   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;
 };
 
 // ---------------------------------------------------------------------------
@@ -267,6 +166,130 @@ class WXDLLEXPORT wxFilterOutputStream: public wxOutputStream {
   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
 
diff --git a/include/wx/txtstrm.h b/include/wx/txtstrm.h
new file mode 100644 (file)
index 0000000..3a951f2
--- /dev/null
@@ -0,0 +1,79 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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_
index 3cc3dc4d83b30485ee22e68a7bbbeb65a6bbd2ef..e2895a4b77b1faab27ef95cbe7cc207e3f9d1ad3 100644 (file)
@@ -44,7 +44,7 @@
 
 #include "wx/wfstream.h"
 #include "wx/datstrm.h"
-
+#include "wx/txtstrm.h"
 
 // Create a new application object
 IMPLEMENT_APP  (MyApp)
@@ -111,36 +111,38 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
     
     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" );
@@ -169,27 +171,29 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
     
     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 );
     
@@ -199,7 +203,7 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
     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 );
@@ -221,12 +225,12 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
     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 );
index 771d9c32d2cb0b637b93e83179ba3268ad745bd0..a13eb8cd3ab5de210eeb0ea4fdede1c93fc9f7d0 100644 (file)
@@ -29,7 +29,7 @@
 // ---------------------------------------------------------------------------
 
 wxDataInputStream::wxDataInputStream(wxInputStream& s)
-  : wxFilterInputStream(s)
+  : m_input(&s)
 {
 }
 
@@ -41,7 +41,7 @@ wxUint32 wxDataInputStream::Read32()
 {
   char buf[4];
 
-  Read(buf, 4);
+  m_input->Read(buf, 4);
 
   return (wxUint32)buf[0] |
          ((wxUint32)buf[1] << 8) |
@@ -53,7 +53,7 @@ wxUint16 wxDataInputStream::Read16()
 {
   char buf[2];
 
-  Read(buf, 2);
+  m_input->Read(buf, 2);
 
   return (wxUint16)buf[0] |
          ((wxUint16)buf[1] << 8);
@@ -63,7 +63,7 @@ wxUint8 wxDataInputStream::Read8()
 {
   wxUint8 buf;
 
-  Read((char *)&buf, 1);
+  m_input->Read((char *)&buf, 1);
   return (wxUint8)buf;
 }
 
@@ -75,7 +75,7 @@ double wxDataInputStream::ReadDouble()
 #if wxUSE_APPLE_IEEE
   char buf[10];
 
-  Read(buf, 10);
+  m_input->Read(buf, 10);
   return ConvertFromIeeeExtended((unsigned char *)buf);
 #else
   return 0.0;
@@ -91,7 +91,7 @@ wxString wxDataInputStream::ReadString()
   len = Read32();
   string = new char[len+1];
 
-  Read(string, len);
+  m_input->Read(string, len);
 
   string[len] = 0;
   wx_string = string;
@@ -99,13 +99,67 @@ wxString wxDataInputStream::ReadString()
 
   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)
 {
 }
 
@@ -121,7 +175,7 @@ void wxDataOutputStream::Write32(wxUint32 i)
   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)
@@ -130,18 +184,18 @@ 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
@@ -157,7 +211,68 @@ void wxDataOutputStream::WriteDouble(double d)
 #  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
index c13c7a1bb7695d73f609aec8683a7f4fb0b29c1a..b433e4f0134b9c5551d50563ac543519c398869b 100644 (file)
@@ -28,6 +28,7 @@
 #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"
 
@@ -178,13 +179,14 @@ bool wxHTTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait))
 
 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;
@@ -194,13 +196,12 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
   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) {
index c6a58a04a19263c3ef1c6b2e6e54d67c5d71a3aa..6519a8bc3a995b81776ab1815554681296359686 100644 (file)
 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;
 }
 
@@ -45,7 +47,10 @@ wxMemoryInputStream::~wxMemoryInputStream()
 
 char wxMemoryInputStream::Peek()
 {
+/*
   return m_i_streambuf->GetBufferStart()[m_i_streambuf->GetIntPosition()];
+*/
+  return 0;
 }
 
 // ----------------------------------------------------------------------------
@@ -55,9 +60,11 @@ char wxMemoryInputStream::Peek()
 wxMemoryOutputStream::wxMemoryOutputStream(char *data, size_t len)
   : wxOutputStream()
 {
+/*
   if (data)
     m_o_streambuf->SetBufferIO(data, data+len);
   m_o_streambuf->Fixed(TRUE);
+*/
 }
 
 wxMemoryOutputStream::~wxMemoryOutputStream()
index 6483df8ee864508b200fb6ec3dd2705a10c17611..f2d56164b007e4f8033fc6651b359c6b3be66dd2 100644 (file)
@@ -186,6 +186,8 @@ void *SocketWaiter::Entry()
   return NULL;
 }
 
+#endif
+
 // --------------------------------------------------------------
 // --------- SocketRequester ------------------------------------
 // --------------------------------------------------------------
@@ -307,6 +309,8 @@ void SocketRequester::ProcessWaitEvent(SockRequest *req)
   m_internal->EndRequest(req);
 }
 
+
+#if wxUSE_THREADS
 void *SocketRequester::Entry()
 {
   SockRequest *req;
index 5528d2eca3e5b10b37bb701d2547fcde38f44c8d..694b94d33697ff4b96590722afcfc3c9716dc3d4 100644 (file)
@@ -229,7 +229,7 @@ bool wxTCPConnection::Execute (wxChar *data, int size, wxIPCFormat format)
     m_codeco->WriteString(data);
   else {
     m_codeco->Write32(size);
-    m_codeco->Write(data, size);
+    m_sockstrm->Write(data, size);
   }
 
   return TRUE;
@@ -256,7 +256,7 @@ char *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat for
 
     s = m_codeci->Read32();
     data = new char[s];
-    m_codeci->Read(data, s);
+    m_sockstrm->Read(data, s);
 
     if (size)
       *size = s;
@@ -276,7 +276,7 @@ bool wxTCPConnection::Poke (const wxString& item, wxChar *data, int size, wxIPCF
     m_codeco->WriteString(data);
   else {
     m_codeco->Write32(size);
-    m_codeco->Write(data, size);
+    m_sockstrm->Write(data, size);
   }
 
   return TRUE;
@@ -332,7 +332,7 @@ bool wxTCPConnection::Advise (const wxString& item,
     m_codeco->WriteString(data);
   else {
     m_codeco->Write32(size);
-    m_codeco->Write(data, size);
+    m_sockstrm->Write(data, size);
   }
 
   return TRUE;
@@ -345,6 +345,7 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt,
   wxTCPConnection *connection = (wxTCPConnection *)cdata;
   wxDataInputStream *codeci;
   wxDataOutputStream *codeco; 
+  wxSocketStream *sockstrm;
   wxString topic_name = connection->m_topic;
   wxString item;
 
@@ -358,6 +359,7 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt,
   // Receive message number.
   codeci = connection->m_codeci;
   codeco = connection->m_codeco;
+  sockstrm = connection->m_sockstrm;
   msg = codeci->Read8();
 
   switch (msg) {
@@ -369,7 +371,7 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt,
     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);
 
@@ -385,7 +387,7 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt,
     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);
 
@@ -423,7 +425,7 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt,
     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);
 
@@ -444,7 +446,7 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt,
       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
index 4d32e503ea6cf92b1a6c7c261b2ce9a7acc0b346..9b83250f1c1886bd6c44f35f573c0c8b77904e84 100644 (file)
 
 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();
@@ -70,48 +68,16 @@ wxStreamBuffer::wxStreamBuffer(const wxStreamBuffer& buffer)
   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)
@@ -154,44 +120,6 @@ void wxStreamBuffer::ResetBuffer()
     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;
@@ -301,13 +229,6 @@ size_t wxStreamBuffer::Read(void *buffer, size_t size)
   // ------------------
 
   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));
 
@@ -408,15 +329,18 @@ size_t wxStreamBuffer::Write(wxStreamBuffer *sbuf)
 {
   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;
@@ -523,79 +447,116 @@ off_t wxStreamBase::OnSysTell() const
 // ----------------------------------------------------------------------------
 
 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]; 
@@ -610,353 +571,221 @@ wxInputStream& wxInputStream::Read(wxOutputStream& stream_out)
 
 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();
 }
 
 // ----------------------------------------------------------------------------
diff --git a/src/common/txtstrm.cpp b/src/common/txtstrm.cpp
new file mode 100644 (file)
index 0000000..9617ae5
--- /dev/null
@@ -0,0 +1,352 @@
+/////////////////////////////////////////////////////////////////////////////////
+// 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
index 89b1f889ccbe9566fe78b3da025573eec330df06..3c8aebe2dc8cda5b303362112c888c0d84bd72e6 100644 (file)
@@ -45,15 +45,13 @@ IMPLEMENT_CLASS(wxURL, wxObject)
 wxProtoInfo *wxURL::g_protocols = NULL;
 wxHTTP *wxURL::g_proxy;
 
-/////////////////////////////////////////////////////////////////
-// wxURL ////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
+// --------------------------------------------------------------
+// wxURL
+// --------------------------------------------------------------
 
-/*
- * --------------------------------------------------------------
- * --------- wxURL CONSTRUCTOR DESTRUCTOR -----------------------
- * --------------------------------------------------------------
- */
+// --------------------------------------------------------------
+// --------- wxURL CONSTRUCTOR DESTRUCTOR -----------------------
+// --------------------------------------------------------------
 
 wxURL::wxURL(const wxString& url)
 {
@@ -118,11 +116,10 @@ wxURL::~wxURL()
   CleanData();
 }
 
-/*
- * --------------------------------------------------------------
- * --------- wxURL urls decoders --------------------------------
- * --------------------------------------------------------------
- */
+// --------------------------------------------------------------
+// --------- wxURL urls decoders --------------------------------
+// --------------------------------------------------------------
+
 bool wxURL::PrepProto(wxString& url)
 {
   int pos;
@@ -219,11 +216,10 @@ bool wxURL::FetchProtocol()
   return FALSE;
 }
 
-/*
- * --------------------------------------------------------------
- * --------- wxURL get ------------------------------------------
- * --------------------------------------------------------------
- */
+// --------------------------------------------------------------
+// --------- wxURL get ------------------------------------------
+// --------------------------------------------------------------
+
 wxInputStream *wxURL::GetInputStream(void)
 {
   wxIPV4address addr;
@@ -318,7 +314,22 @@ void wxURL::SetProxy(const wxString& url_proxy)
 
 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
index 41c659fe64a758f7625392f6b1b5965966c35314..8e94d26dccd183fcb86f4c51e140c23b6ea03f54 100644 (file)
@@ -203,9 +203,9 @@ bool wxGenericValidator::TransferToWindow(void)
       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)
@@ -459,4 +459,4 @@ void wxGenericValidator::Initialize()
 
 #endif
   // wxUSE_VALIDATORS
-  
\ No newline at end of file
+  
index df4651d9f68d01814976175dd92423b441432c10..17a9980397cd0f9c3692c9a436e003c2ae6e9142 100644 (file)
 #   include <fstream>
 #endif
 
+#if wxUSE_STREAMS
 #include "wx/stream.h"
+#include "wx/txtstrm.h"
+#endif
+
 #include "wx/string.h"
 #include "wx/variant.h"
 
@@ -371,13 +375,16 @@ bool wxVariantDataLong::Read(istream& str)
 #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
@@ -469,13 +476,15 @@ bool wxVariantDataReal::Read(istream& str)
 #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
@@ -569,13 +578,17 @@ bool wxVariantDataBool::Read(istream& WXUNUSED(str))
 #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
@@ -667,13 +680,17 @@ bool wxVariantDataChar::Read(istream& WXUNUSED(str))
 #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
@@ -771,13 +788,16 @@ bool wxVariantDataString::Read(istream& str)
 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
index e4da5d94dfdd4d7c21ae3f2d281fecf264e037f3..5191307d4a22d9fa10e8c509348d8ded07d2a7ff 100644 (file)
@@ -39,7 +39,6 @@ wxFileInputStream::wxFileInputStream(const wxString& fileName)
 {
   m_file = new wxFile(fileName, wxFile::read);
   m_file_destroy = TRUE;
-  m_i_streambuf->SetBufferIO(1024);
 }
 
 wxFileInputStream::wxFileInputStream()
@@ -53,14 +52,12 @@ wxFileInputStream::wxFileInputStream(wxFile& file)
 {
   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()
@@ -81,7 +78,18 @@ size_t wxFileInputStream::StreamSize() const
 
 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)
@@ -102,20 +110,17 @@ wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
 {
   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;
 }
@@ -124,7 +129,6 @@ wxFileOutputStream::wxFileOutputStream(int fd)
 {
   m_file = new wxFile(fd);
   m_file_destroy = TRUE;
-  m_o_streambuf->SetBufferIO(1024);
 }
 
 wxFileOutputStream::~wxFileOutputStream()
index 09953c87d10d04849dbc0a9158b6ce0521192efc..1424f3b22bf2b18b638ebecb9c1fc092f04ab05f 100644 (file)
@@ -44,8 +44,6 @@ wxZlibInputStream::wxZlibInputStream(wxInputStream& stream)
   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;
@@ -106,8 +104,6 @@ wxZlibOutputStream::wxZlibOutputStream(wxOutputStream& stream)
 {
   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;
index 3e510bc20b9af4b403f45d40ff8d4630d6816228..5bff538335510f0a69838a51fdf04154338020a8 100644 (file)
@@ -86,6 +86,7 @@ libwx_gtk_la_SOURCES = \
  tbarbase.cpp \
  tbarsmpl.cpp \
  textfile.cpp \
+ txtstrm.cpp \
  time.cpp \
  timercmn.cpp \
  tokenzr.cpp \
index 3e510bc20b9af4b403f45d40ff8d4630d6816228..5bff538335510f0a69838a51fdf04154338020a8 100644 (file)
@@ -86,6 +86,7 @@ libwx_gtk_la_SOURCES = \
  tbarbase.cpp \
  tbarsmpl.cpp \
  textfile.cpp \
+ txtstrm.cpp \
  time.cpp \
  timercmn.cpp \
  tokenzr.cpp \
index 9f05f9e07190e62e08fe1be1529f8641537be47c..7a692f953749b61cf632d4ed2eacbe8506bdf74d 100644 (file)
@@ -96,6 +96,7 @@ libwx_motif_la_SOURCES = \
  tbarbase.cpp \
  tbarsmpl.cpp \
  textfile.cpp \
+ txtstrm.cpp \
  time.cpp \
  url.cpp \
  valgen.cpp \
index 422e3ae1a79dff1dbabe70eb4e73732753e42589..2773aed98fd55c200cb1fb197f9a83791ce72b5c 100644 (file)
@@ -247,6 +247,7 @@ MSWOBJS = \
   $(MSWDIR)\tabctrl.obj \
   $(MSWDIR)\tbarmsw.obj \
   $(MSWDIR)\textctrl.obj \
+  $(MSWDIR)\txtstrm.obj \
   $(MSWDIR)\thread.obj \
   $(MSWDIR)\timer.obj \
   $(MSWDIR)\tooltip.obj \
@@ -464,6 +465,8 @@ $(MSWDIR)\tbarmsw.obj:     $(MSWDIR)\tbarmsw.$(SRCSUFF)
 
 $(MSWDIR)\textctrl.obj:     $(MSWDIR)\textctrl.$(SRCSUFF)
 
+$(MSWDIR)\txtstrm.obj:     $(MSWDIR)\txtstrm.$(SRCSUFF)
+
 $(MSWDIR)\thread.obj:     $(MSWDIR)\thread.$(SRCSUFF)
 
 $(MSWDIR)\timer.obj:     $(MSWDIR)\timer.$(SRCSUFF)
index 4732fd0a47f68273b064a21ef8f2d3806956f46c..7455eb2dab59b2a27f55793e752579e07c4ba10d 100644 (file)
@@ -250,6 +250,7 @@ MSWOBJS = \
   ..\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 \
index aad7082be4d7ab0aa5f6342a5b2c28d388b977b8..a6f79d8db1ca920b157e2feb86a430ac7bf6e685 100644 (file)
@@ -668,6 +668,9 @@ wxThreadError wxThread::Resume()
 
 wxThread::ExitCode wxThread::Delete()
 {
+    if (IsPaused())
+      Resume();
+
     m_critsect.Enter();
     wxThreadState state = p_internal->GetState();