// 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
// ----------------------------------------------------------------------------
return;
}
- if (!GetDataLeft() && !FlushBuffer()) {
- CHECK_ERROR(wxStream_READ_ERR);
+ if (GetDataLeft() == 0 && !FlushBuffer()) {
+ CHECK_ERROR(wxStream_WRITE_ERR);
return;
}
}
GetFromBuffer(&c, 1);
+
m_stream->m_lastcount = 1;
return c;
}
{
wxASSERT(m_stream != NULL);
+ if (m_mode == write)
+ return 0;
+
// ------------------
// Buffering disabled
// ------------------
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;
{
wxASSERT(m_stream != NULL);
+ if (m_mode == read)
+ return 0;
+
// ------------------
// Buffering disabled
// ------------------
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);
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 */ ;
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();
}
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 */
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');
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)
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
return stream.Write("\n", 1);
#endif
}
+
+#endif
+ // wxUSE_STREAMS