]>
git.saurik.com Git - wxWidgets.git/blob - src/common/datstrm.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Data stream classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "datstrm.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/datstrm.h"
27 // ---------------------------------------------------------------------------
29 // ---------------------------------------------------------------------------
31 wxDataInputStream::wxDataInputStream(wxInputStream
& s
)
36 wxDataInputStream::~wxDataInputStream()
40 wxUint32
wxDataInputStream::Read32()
44 m_input
->Read(buf
, 4);
46 return (wxUint32
)buf
[0] |
47 ((wxUint32
)buf
[1] << 8) |
48 ((wxUint32
)buf
[2] << 16) |
49 ((wxUint32
)buf
[3] << 24);
52 wxUint16
wxDataInputStream::Read16()
56 m_input
->Read(buf
, 2);
58 return (wxUint16
)buf
[0] |
59 ((wxUint16
)buf
[1] << 8);
62 wxUint8
wxDataInputStream::Read8()
66 m_input
->Read((char *)&buf
, 1);
70 // Must be at global scope for VC++ 5
71 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
73 double wxDataInputStream::ReadDouble()
78 m_input
->Read(buf
, 10);
79 return ConvertFromIeeeExtended((unsigned char *)buf
);
85 wxString
wxDataInputStream::ReadString()
92 string
= new char[len
+1];
94 m_input
->Read(string
, len
);
103 wxDataInputStream
& wxDataInputStream::operator>>(wxString
& s
)
109 wxDataInputStream
& wxDataInputStream::operator>>(wxInt8
& c
)
115 wxDataInputStream
& wxDataInputStream::operator>>(wxInt16
& i
)
117 i
= (wxInt16
)Read16();
121 wxDataInputStream
& wxDataInputStream::operator>>(wxInt32
& i
)
123 i
= (wxInt32
)Read32();
127 wxDataInputStream
& wxDataInputStream::operator>>(wxUint8
& c
)
133 wxDataInputStream
& wxDataInputStream::operator>>(wxUint16
& i
)
139 wxDataInputStream
& wxDataInputStream::operator>>(wxUint32
& i
)
145 wxDataInputStream
& wxDataInputStream::operator>>(double& i
)
151 wxDataInputStream
& wxDataInputStream::operator>>(float& f
)
153 f
= (float)ReadDouble();
157 // ---------------------------------------------------------------------------
158 // wxDataOutputStream
159 // ---------------------------------------------------------------------------
161 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
166 wxDataOutputStream::~wxDataOutputStream()
170 void wxDataOutputStream::Write32(wxUint32 i
)
175 buf
[1] = (i
>> 8) & 0xff;
176 buf
[2] = (i
>> 16) & 0xff;
177 buf
[3] = (i
>> 24) & 0xff;
178 m_output
->Write(buf
, 4);
181 void wxDataOutputStream::Write16(wxUint16 i
)
186 buf
[1] = (i
>> 8) & 0xff;
187 m_output
->Write(buf
, 2);
190 void wxDataOutputStream::Write8(wxUint8 i
)
192 m_output
->Write(&i
, 1);
195 void wxDataOutputStream::WriteString(const wxString
& string
)
197 Write32(string
.Length());
198 m_output
->Write((const wxChar
*) string
, string
.Length()*sizeof(wxChar
));
201 // Must be at global scope for VC++ 5
202 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
204 void wxDataOutputStream::WriteDouble(double d
)
209 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
211 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
214 m_output
->Write(buf
, 10);
217 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
219 Write32(wxStrlen(string
));
220 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
224 wxDataOutputStream
& wxDataOutputStream::operator<<(wxString
& string
)
230 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
236 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
238 Write16((wxUint16
)i
);
242 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
244 Write32((wxUint32
)i
);
248 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
254 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
260 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
266 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
272 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
274 WriteDouble((double)f
);