]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/stream.cpp
file I forgot to add...
[wxWidgets.git] / src / common / stream.cpp
index f2bb737c0d266072769c9f8e48a3ee253b9984ff..9750fef812d9aebf254c8a85196076dcc8dcd90d 100644 (file)
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+  #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+  #include "wx/defs.h"
+#endif
+
+#if wxUSE_STREAMS
+
 #include <ctype.h>
 #include <wx/stream.h>
 #include <wx/datstrm.h>
 #include <wx/objstrm.h>
 
-#ifdef __BORLANDC__
-#pragma hdrstop
-#endif
-
 #define BUF_TEMP_SIZE 10000
 
 // ----------------------------------------------------------------------------
@@ -251,8 +258,8 @@ void wxStreamBuffer::PutChar(char c)
     return;
   }
 
-  if (!GetDataLeft() && !FlushBuffer()) {
-    CHECK_ERROR(wxStream_READ_ERR);
+  if (GetDataLeft() == 0 && !FlushBuffer()) {
+    CHECK_ERROR(wxStream_WRITE_ERR);
     return;
   }
 
@@ -277,6 +284,7 @@ char wxStreamBuffer::GetChar()
   }
 
   GetFromBuffer(&c, 1);
+  
   m_stream->m_lastcount = 1;
   return c;
 }
@@ -285,6 +293,9 @@ size_t wxStreamBuffer::Read(void *buffer, size_t size)
 {
   wxASSERT(m_stream != NULL);
 
+  if (m_mode == write)
+    return 0;
+
   // ------------------
   // Buffering disabled
   // ------------------
@@ -334,7 +345,10 @@ size_t wxStreamBuffer::Read(wxStreamBuffer *s_buf)
   char buf[BUF_TEMP_SIZE];
   size_t s = 0, bytes_read = BUF_TEMP_SIZE;
 
-  while (bytes_read == BUF_TEMP_SIZE) {
+  if (m_mode == write)
+    return 0;
+
+  while (bytes_read != 0) {
     bytes_read = Read(buf, bytes_read);
     bytes_read = s_buf->Write(buf, bytes_read);
     s += bytes_read;
@@ -346,6 +360,9 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size)
 {
   wxASSERT(m_stream != NULL);
 
+  if (m_mode == read)
+    return 0;
+
   // ------------------
   // Buffering disabled
   // ------------------
@@ -392,6 +409,9 @@ size_t wxStreamBuffer::Write(wxStreamBuffer *sbuf)
   char buf[BUF_TEMP_SIZE];
   size_t s = 0, bytes_count = BUF_TEMP_SIZE, b_count2;
 
+  if (m_mode == read)
+    return 0;
+
   while (bytes_count == BUF_TEMP_SIZE) {
     b_count2 = sbuf->Read(buf, bytes_count);
     bytes_count = Write(buf, b_count2);
@@ -584,28 +604,29 @@ wxInputStream& wxInputStream::operator>>(char& c)
   return *this;
 }
 
-wxInputStream& wxInputStream::operator>>(short& i)
+wxInputStream& wxInputStream::operator>>(signed short& i)
 {
-  long l;
+  signed long l;
 
   *this >> l;
-  i = (short)l;
+  i = (signed short)l;
   return *this;
 }
 
-wxInputStream& wxInputStream::operator>>(int& i)
+wxInputStream& wxInputStream::operator>>(signed int& i)
 {
-  long l;
+  signed long l;
 
   *this >> l;
-  i = (short)l;
+  i = (signed int)l;
   return *this;
 }
 
-wxInputStream& wxInputStream::operator>>(long& i)
+wxInputStream& wxInputStream::operator>>(signed long& i)
 {
   /* I only implemented a simple integer parser */
-  int c, sign;
+  int c; 
+  int sign;
 
   while (isspace( c = GetC() ) )
      /* Do nothing */ ;
@@ -619,11 +640,15 @@ wxInputStream& wxInputStream::operator>>(long& i)
   if (c == '-') {
     sign = -1;
     c = GetC();
-  } else
+  } else if (c == '+') {
+    sign = 1;
+    c = GetC();
+  } else {
     sign = 1;
+  }
 
   while (isdigit(c)) {
-    i = i*10 + c;
+    i = i*10 + (c - (int)'0');
     c = GetC();
   }
 
@@ -632,6 +657,46 @@ wxInputStream& wxInputStream::operator>>(long& i)
   return *this;
 }
 
+wxInputStream& wxInputStream::operator>>(unsigned short& i)
+{
+  unsigned long l;
+
+  *this >> l;
+  i = (unsigned short)l;
+  return *this;
+}
+
+wxInputStream& wxInputStream::operator>>(unsigned int& i)
+{
+  unsigned long l;
+
+  *this >> l;
+  i = (unsigned int)l;
+  return *this;
+}
+
+wxInputStream& wxInputStream::operator>>(unsigned long& i)
+{
+  /* 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;
+}
+
 wxInputStream& wxInputStream::operator>>(double& f)
 {
   /* I only implemented a simple float parser */
@@ -649,8 +714,12 @@ wxInputStream& wxInputStream::operator>>(double& f)
   if (c == '-') {
     sign = -1;
     c = GetC();
-  } else
+  } else if (c == '+') {
     sign = 1;
+    c = GetC();
+  } else {
+    sign = 1;
+  }
 
   while (isdigit(c)) {
     f = f*10 + (c - '0');
@@ -740,7 +809,12 @@ wxOutputStream& wxOutputStream::operator<<(const char *string)
 
 wxOutputStream& wxOutputStream::operator<<(wxString& string)
 {
+#if wxUSE_UNICODE
+  const wxWX2MBbuf buf = string.mb_str();
+  return *this << buf;
+#else
   return Write(string, string.Len());
+#endif
 }
 
 wxOutputStream& wxOutputStream::operator<<(char c)
@@ -748,36 +822,50 @@ wxOutputStream& wxOutputStream::operator<<(char c)
   return Write(&c, 1);
 }
 
-wxOutputStream& wxOutputStream::operator<<(short i)
+wxOutputStream& wxOutputStream::operator<<(signed short i)
+{
+  signed long l = (signed long)i;
+  return *this << l;
+}
+
+wxOutputStream& wxOutputStream::operator<<(signed int i)
 {
-  wxString strint;
+  signed long l = (signed long)i;
+  return *this << l;
+}
 
-  strint.Printf("%i", i);
-  return Write(strint, strint.Len());
+wxOutputStream& wxOutputStream::operator<<(signed long i)
+{
+  wxString strlong;
+  strlong.Printf(_T("%ld"), i);
+  return *this << strlong;
 }
 
-wxOutputStream& wxOutputStream::operator<<(int i)
+wxOutputStream& wxOutputStream::operator<<(unsigned short i)
 {
-  wxString strint;
+  unsigned long l = (unsigned long)i;
+  return *this << l;
+}
 
-  strint.Printf("%i", i);
-  return Write(strint, strint.Len());
+wxOutputStream& wxOutputStream::operator<<(unsigned int i)
+{
+  unsigned long l = (unsigned long)i;
+  return *this << l;
 }
 
-wxOutputStream& wxOutputStream::operator<<(long i)
+wxOutputStream& wxOutputStream::operator<<(unsigned long i)
 {
   wxString strlong;
-
-  strlong.Printf("%i", i);
-  return Write((const char *)strlong, strlong.Len());
+  strlong.Printf(_T("%lu"), i);
+  return *this << strlong;
 }
 
 wxOutputStream& wxOutputStream::operator<<(double f)
 {
   wxString strfloat;
 
-  strfloat.Printf("%f", f);
-  return Write(strfloat, strfloat.Len());
+  strfloat.Printf(_T("%f"), f);
+  return *this << strfloat;
 }
 
 #if wxUSE_SERIAL
@@ -838,3 +926,6 @@ wxOutputStream& wxEndL(wxOutputStream& stream)
   return stream.Write("\n", 1);
 #endif
 }
+
+#endif
+  // wxUSE_STREAMS