]> git.saurik.com Git - wxWidgets.git/blame - src/common/datstrm.cpp
attempts to fix wxStaticBitmap::SetBitmap() - still doesn't work
[wxWidgets.git] / src / common / datstrm.cpp
CommitLineData
cf447356
GL
1/////////////////////////////////////////////////////////////////////////////
2// Name: datstrm.cpp
3// Purpose: Data stream classes
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 28/06/98
7// RCS-ID: $Id$
8// Copyright: (c) Guilhem Lavaux
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "datstrm.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
ce4169a4 20 #pragma hdrstop
cf447356
GL
21#endif
22
ce4169a4
RR
23#if wxUSE_STREAMS
24
cf447356 25#include "wx/datstrm.h"
3cacae09 26
f4ada568
GL
27// ---------------------------------------------------------------------------
28// wxDataInputStream
29// ---------------------------------------------------------------------------
30
3d4c6a21
GL
31wxDataInputStream::wxDataInputStream(wxInputStream& s)
32 : wxFilterInputStream(s)
cf447356 33{
cf447356
GL
34}
35
3d4c6a21 36wxDataInputStream::~wxDataInputStream()
cf447356 37{
cf447356
GL
38}
39
7b8bd818 40wxUint32 wxDataInputStream::Read32()
cf447356
GL
41{
42 char buf[4];
43
3d4c6a21 44 Read(buf, 4);
cf447356 45
7b8bd818
GL
46 return (wxUint32)buf[0] |
47 ((wxUint32)buf[1] << 8) |
48 ((wxUint32)buf[2] << 16) |
49 ((wxUint32)buf[3] << 24);
cf447356
GL
50}
51
7b8bd818 52wxUint16 wxDataInputStream::Read16()
cf447356
GL
53{
54 char buf[2];
55
3d4c6a21 56 Read(buf, 2);
cf447356 57
7b8bd818
GL
58 return (wxUint16)buf[0] |
59 ((wxUint16)buf[1] << 8);
cf447356
GL
60}
61
7b8bd818 62wxUint8 wxDataInputStream::Read8()
cf447356 63{
7b8bd818 64 wxUint8 buf;
cf447356 65
7b8bd818
GL
66 Read((char *)&buf, 1);
67 return (wxUint8)buf;
cf447356
GL
68}
69
5260b1c5
JS
70// Must be at global scope for VC++ 5
71extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes);
72
3d4c6a21 73double wxDataInputStream::ReadDouble()
cf447356 74{
47d67540 75#if wxUSE_APPLE_IEEE
cf447356
GL
76 char buf[10];
77
3d4c6a21 78 Read(buf, 10);
cf447356
GL
79 return ConvertFromIeeeExtended((unsigned char *)buf);
80#else
81 return 0.0;
82#endif
83}
84
3d4c6a21 85wxString wxDataInputStream::ReadString()
eafc087e
GL
86{
87 wxString wx_string;
88 char *string;
89 unsigned long len;
90
eafc087e
GL
91 len = Read32();
92 string = new char[len+1];
93
3d4c6a21 94 Read(string, len);
eafc087e
GL
95
96 string[len] = 0;
97 wx_string = string;
98 delete string;
99
a3622daa 100 return wx_string;
eafc087e
GL
101}
102
f4ada568
GL
103// ---------------------------------------------------------------------------
104// wxDataOutputStream
105// ---------------------------------------------------------------------------
106
3d4c6a21
GL
107wxDataOutputStream::wxDataOutputStream(wxOutputStream& s)
108 : wxFilterOutputStream(s)
109{
110}
111
f0b07807
KB
112wxDataOutputStream::~wxDataOutputStream()
113{
114}
115
7b8bd818 116void wxDataOutputStream::Write32(wxUint32 i)
cf447356
GL
117{
118 char buf[4];
119
cf447356
GL
120 buf[0] = i & 0xff;
121 buf[1] = (i >> 8) & 0xff;
122 buf[2] = (i >> 16) & 0xff;
123 buf[3] = (i >> 24) & 0xff;
3d4c6a21 124 Write(buf, 4);
cf447356
GL
125}
126
7b8bd818 127void wxDataOutputStream::Write16(wxUint16 i)
cf447356
GL
128{
129 char buf[2];
130
cf447356
GL
131 buf[0] = i & 0xff;
132 buf[1] = (i >> 8) & 0xff;
3d4c6a21 133 Write(buf, 2);
cf447356
GL
134}
135
7b8bd818 136void wxDataOutputStream::Write8(wxUint8 i)
cf447356 137{
3d4c6a21 138 Write(&i, 1);
cf447356
GL
139}
140
3d4c6a21 141void wxDataOutputStream::WriteString(const wxString& string)
eafc087e 142{
debe6624 143 Write32(string.Length());
84fff0b3 144 Write((const wxChar *) string, string.Length()*sizeof(wxChar));
cf447356
GL
145}
146
5260b1c5
JS
147// Must be at global scope for VC++ 5
148extern "C" void ConvertToIeeeExtended(double num, unsigned char *bytes);
149
3d4c6a21 150void wxDataOutputStream::WriteDouble(double d)
cf447356 151{
cf447356
GL
152 char buf[10];
153
47d67540 154#if wxUSE_APPLE_IEEE
cf447356 155 ConvertToIeeeExtended(d, (unsigned char *)buf);
0e338ff9 156#else
631f1bfe 157# pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
0e338ff9
KB
158 buf[0] = '\0';
159#endif
3d4c6a21 160 Write(buf, 10);
cf447356 161}
ce4169a4
RR
162
163#endif
164 // wxUSE_STREAMS
b6bff301 165