]>
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 const wxWX2MBbuf buf
= string
.mb_str();
198 Write32(string
.Length());
199 m_output
->Write(buf
, string
.Len());
202 // Must be at global scope for VC++ 5
203 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
205 void wxDataOutputStream::WriteDouble(double d
)
210 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
212 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
215 m_output
->Write(buf
, 10);
218 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
220 Write32(wxStrlen(string
));
221 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
225 wxDataOutputStream
& wxDataOutputStream::operator<<(wxString
& string
)
231 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
237 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
239 Write16((wxUint16
)i
);
243 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
245 Write32((wxUint32
)i
);
249 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
255 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
261 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
267 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
273 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
275 WriteDouble((double)f
);