]>
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 // ---------------------------------------------------------------------------
32 wxDataInputStream::wxDataInputStream(wxInputStream
& s
, wxMBConv
& conv
)
33 : m_input(&s
), m_be_order(FALSE
), m_conv(conv
)
35 wxDataInputStream::wxDataInputStream(wxInputStream
& s
)
36 : m_input(&s
), m_be_order(FALSE
)
41 wxDataInputStream::~wxDataInputStream()
45 wxUint64
wxDataInputStream::Read64()
49 m_input
->Read(&i64
, 8);
52 return wxUINT64_SWAP_ON_LE(i64
);
54 return wxUINT64_SWAP_ON_BE(i64
);
57 wxUint32
wxDataInputStream::Read32()
61 m_input
->Read(&i32
, 4);
64 return wxUINT32_SWAP_ON_LE(i32
);
66 return wxUINT32_SWAP_ON_BE(i32
);
69 wxUint16
wxDataInputStream::Read16()
73 m_input
->Read(&i16
, 2);
76 return wxUINT16_SWAP_ON_LE(i16
);
78 return wxUINT16_SWAP_ON_BE(i16
);
81 wxUint8
wxDataInputStream::Read8()
85 m_input
->Read(&buf
, 1);
89 // Must be at global scope for VC++ 5
90 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
92 double wxDataInputStream::ReadDouble()
97 m_input
->Read(buf
, 10);
98 return ConvertFromIeeeExtended((unsigned char *)buf
);
104 wxString
wxDataInputStream::ReadString()
113 char *tmp
= new char[len
+ 1];
114 m_input
->Read(tmp
, len
);
116 wxString
ret( (const wxChar
*) m_conv
.cMB2WX(tmp
) );
120 m_input
->Read( ret
.GetWriteBuf(len
), len
);
126 return wxEmptyString
;
129 wxDataInputStream
& wxDataInputStream::operator>>(wxString
& s
)
135 wxDataInputStream
& wxDataInputStream::operator>>(wxInt8
& c
)
141 wxDataInputStream
& wxDataInputStream::operator>>(wxInt16
& i
)
143 i
= (wxInt16
)Read16();
147 wxDataInputStream
& wxDataInputStream::operator>>(wxInt32
& i
)
149 i
= (wxInt32
)Read32();
153 wxDataInputStream
& wxDataInputStream::operator>>(wxUint8
& c
)
159 wxDataInputStream
& wxDataInputStream::operator>>(wxUint16
& i
)
165 wxDataInputStream
& wxDataInputStream::operator>>(wxUint32
& i
)
171 wxDataInputStream
& wxDataInputStream::operator>>(wxUint64
& i
)
177 wxDataInputStream
& wxDataInputStream::operator>>(double& i
)
183 wxDataInputStream
& wxDataInputStream::operator>>(float& f
)
185 f
= (float)ReadDouble();
189 // ---------------------------------------------------------------------------
190 // wxDataOutputStream
191 // ---------------------------------------------------------------------------
194 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
, wxMBConv
& conv
)
195 : m_output(&s
), m_be_order(FALSE
), m_conv(conv
)
197 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
198 : m_output(&s
), m_be_order(FALSE
)
203 wxDataOutputStream::~wxDataOutputStream()
207 void wxDataOutputStream::Write64(wxUint64 i
)
212 i64
= wxUINT64_SWAP_ON_LE(i
);
214 i64
= wxUINT64_SWAP_ON_BE(i
);
215 m_output
->Write(&i64
, 8);
218 void wxDataOutputStream::Write32(wxUint32 i
)
223 i32
= wxUINT32_SWAP_ON_LE(i
);
225 i32
= wxUINT32_SWAP_ON_BE(i
);
226 m_output
->Write(&i32
, 4);
229 void wxDataOutputStream::Write16(wxUint16 i
)
234 i16
= wxUINT16_SWAP_ON_LE(i
);
236 i16
= wxUINT16_SWAP_ON_BE(i
);
238 m_output
->Write(&i16
, 2);
241 void wxDataOutputStream::Write8(wxUint8 i
)
243 m_output
->Write(&i
, 1);
246 void wxDataOutputStream::WriteString(const wxString
& string
)
249 const wxWX2MBbuf buf
= string
.mb_str(m_conv
);
251 const wxWX2MBbuf buf
= string
.mb_str();
253 size_t len
= strlen(buf
);
256 m_output
->Write(buf
, len
);
259 // Must be at global scope for VC++ 5
260 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
262 void wxDataOutputStream::WriteDouble(double d
)
267 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
270 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
274 m_output
->Write(buf
, 10);
277 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
279 Write32(wxStrlen(string
));
280 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
284 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxString
& string
)
290 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
296 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
298 Write16((wxUint16
)i
);
302 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
304 Write32((wxUint32
)i
);
308 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
314 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
320 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
326 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint64 i
)
332 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
338 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
340 WriteDouble((double)f
);