* wxStream: - new inheritance, new stream buffer, nearly the same API for the
end user
- updated other streams consequently
* wxGTK: some change to make it compile on GTK 1.0 and GTK 1.1
* small changes on wxThread to prepare a more reentrant lib
* wxVariant works with wxStream too now
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@829 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
203 lines
3.8 KiB
C++
203 lines
3.8 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
|
// Name: datstrm.cpp
|
|
// Purpose: Data 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 "datstrm.h"
|
|
#endif
|
|
|
|
// 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
|
|
|
|
#include "wx/datstrm.h"
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// wxDataInputStream
|
|
// ---------------------------------------------------------------------------
|
|
|
|
wxDataInputStream::wxDataInputStream(wxInputStream& s)
|
|
: wxFilterInputStream(s)
|
|
{
|
|
}
|
|
|
|
wxDataInputStream::~wxDataInputStream()
|
|
{
|
|
}
|
|
|
|
unsigned long wxDataInputStream::Read32()
|
|
{
|
|
char buf[4];
|
|
|
|
Read(buf, 4);
|
|
|
|
return (unsigned long)buf[0] |
|
|
((unsigned long)buf[1] << 8) |
|
|
((unsigned long)buf[2] << 16) |
|
|
((unsigned long)buf[3] << 24);
|
|
}
|
|
|
|
unsigned short wxDataInputStream::Read16()
|
|
{
|
|
char buf[2];
|
|
|
|
Read(buf, 2);
|
|
|
|
return (unsigned short)buf[0] |
|
|
((unsigned short)buf[1] << 8);
|
|
}
|
|
|
|
unsigned char wxDataInputStream::Read8()
|
|
{
|
|
char buf;
|
|
|
|
Read(&buf, 1);
|
|
return (unsigned char)buf;
|
|
}
|
|
|
|
// Must be at global scope for VC++ 5
|
|
extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes);
|
|
|
|
double wxDataInputStream::ReadDouble()
|
|
{
|
|
#if wxUSE_APPLE_IEEE
|
|
char buf[10];
|
|
|
|
Read(buf, 10);
|
|
return ConvertFromIeeeExtended((unsigned char *)buf);
|
|
#else
|
|
return 0.0;
|
|
#endif
|
|
}
|
|
|
|
wxString wxDataInputStream::ReadLine()
|
|
{
|
|
char c, last_endl = 0;
|
|
bool end_line = FALSE;
|
|
wxString line;
|
|
|
|
while (!end_line) {
|
|
c = GetC();
|
|
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;
|
|
}
|
|
|
|
wxString wxDataInputStream::ReadString()
|
|
{
|
|
wxString wx_string;
|
|
char *string;
|
|
unsigned long len;
|
|
|
|
len = Read32();
|
|
string = new char[len+1];
|
|
|
|
Read(string, len);
|
|
|
|
string[len] = 0;
|
|
wx_string = string;
|
|
delete string;
|
|
|
|
return wx_string;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// wxDataOutputStream
|
|
// ---------------------------------------------------------------------------
|
|
|
|
wxDataOutputStream::wxDataOutputStream(wxOutputStream& s)
|
|
: wxFilterOutputStream(s)
|
|
{
|
|
}
|
|
|
|
wxDataOutputStream::~wxDataOutputStream()
|
|
{
|
|
}
|
|
|
|
void wxDataOutputStream::Write32(unsigned long i)
|
|
{
|
|
char buf[4];
|
|
|
|
buf[0] = i & 0xff;
|
|
buf[1] = (i >> 8) & 0xff;
|
|
buf[2] = (i >> 16) & 0xff;
|
|
buf[3] = (i >> 24) & 0xff;
|
|
Write(buf, 4);
|
|
}
|
|
|
|
void wxDataOutputStream::Write16(unsigned short i)
|
|
{
|
|
char buf[2];
|
|
|
|
buf[0] = i & 0xff;
|
|
buf[1] = (i >> 8) & 0xff;
|
|
Write(buf, 2);
|
|
}
|
|
|
|
void wxDataOutputStream::Write8(unsigned char i)
|
|
{
|
|
Write(&i, 1);
|
|
}
|
|
|
|
void wxDataOutputStream::WriteLine(const wxString& line)
|
|
{
|
|
#ifdef __WXMSW__
|
|
wxString tmp_string = line + "\r\n";
|
|
#else
|
|
wxString tmp_string = line + '\n';
|
|
#endif
|
|
|
|
Write((const char *) tmp_string, tmp_string.Length());
|
|
}
|
|
|
|
void wxDataOutputStream::WriteString(const wxString& string)
|
|
{
|
|
Write32(string.Length());
|
|
Write((const char *) string, string.Length());
|
|
}
|
|
|
|
// Must be at global scope for VC++ 5
|
|
extern "C" void ConvertToIeeeExtended(double num, unsigned char *bytes);
|
|
|
|
void wxDataOutputStream::WriteDouble(double d)
|
|
{
|
|
char buf[10];
|
|
|
|
#if wxUSE_APPLE_IEEE
|
|
ConvertToIeeeExtended(d, (unsigned char *)buf);
|
|
#else
|
|
# pragma warning "wxDataStream::WriteDouble() not using IeeeExtended - will not work!"
|
|
buf[0] = '\0';
|
|
#endif
|
|
Write(buf, 10);
|
|
}
|