]>
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
)
32 : m_input(&s
), m_be_order(FALSE
)
36 wxDataInputStream::~wxDataInputStream()
40 wxUint64
wxDataInputStream::Read64()
44 m_input
->Read(&i64
, 8);
47 return wxUINT64_SWAP_ON_LE(i64
);
49 return wxUINT64_SWAP_ON_BE(i64
);
52 wxUint32
wxDataInputStream::Read32()
56 m_input
->Read(&i32
, 4);
59 return wxUINT32_SWAP_ON_LE(i32
);
61 return wxUINT32_SWAP_ON_BE(i32
);
64 wxUint16
wxDataInputStream::Read16()
68 m_input
->Read(&i16
, 2);
71 return wxUINT16_SWAP_ON_LE(i16
);
73 return wxUINT16_SWAP_ON_BE(i16
);
76 wxUint8
wxDataInputStream::Read8()
80 m_input
->Read(&buf
, 1);
84 // Must be at global scope for VC++ 5
85 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
87 double wxDataInputStream::ReadDouble()
92 m_input
->Read(buf
, 10);
93 return ConvertFromIeeeExtended((unsigned char *)buf
);
99 wxString
wxDataInputStream::ReadString()
108 char *tmp
= new char[len
+ 1];
109 m_input
->Read(tmp
, len
);
115 m_input
->Read(s
.GetWriteBuf(len
), len
);
121 return wxEmptyString
;
124 wxDataInputStream
& wxDataInputStream::operator>>(wxString
& s
)
130 wxDataInputStream
& wxDataInputStream::operator>>(wxInt8
& c
)
136 wxDataInputStream
& wxDataInputStream::operator>>(wxInt16
& i
)
138 i
= (wxInt16
)Read16();
142 wxDataInputStream
& wxDataInputStream::operator>>(wxInt32
& i
)
144 i
= (wxInt32
)Read32();
148 wxDataInputStream
& wxDataInputStream::operator>>(wxUint8
& c
)
154 wxDataInputStream
& wxDataInputStream::operator>>(wxUint16
& i
)
160 wxDataInputStream
& wxDataInputStream::operator>>(wxUint32
& i
)
166 wxDataInputStream
& wxDataInputStream::operator>>(wxUint64
& i
)
172 wxDataInputStream
& wxDataInputStream::operator>>(double& i
)
178 wxDataInputStream
& wxDataInputStream::operator>>(float& f
)
180 f
= (float)ReadDouble();
184 // ---------------------------------------------------------------------------
185 // wxDataOutputStream
186 // ---------------------------------------------------------------------------
188 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
189 : m_output(&s
), m_be_order(FALSE
)
193 wxDataOutputStream::~wxDataOutputStream()
197 void wxDataOutputStream::Write64(wxUint64 i
)
202 i64
= wxUINT64_SWAP_ON_LE(i
);
204 i64
= wxUINT64_SWAP_ON_BE(i
);
205 m_output
->Write(&i64
, 8);
208 void wxDataOutputStream::Write32(wxUint32 i
)
213 i32
= wxUINT32_SWAP_ON_LE(i
);
215 i32
= wxUINT32_SWAP_ON_BE(i
);
216 m_output
->Write(&i32
, 4);
219 void wxDataOutputStream::Write16(wxUint16 i
)
224 i16
= wxUINT16_SWAP_ON_LE(i
);
226 i16
= wxUINT16_SWAP_ON_BE(i
);
228 m_output
->Write(&i16
, 2);
231 void wxDataOutputStream::Write8(wxUint8 i
)
233 m_output
->Write(&i
, 1);
236 void wxDataOutputStream::WriteString(const wxString
& string
)
238 const wxWX2MBbuf buf
= string
.mb_str();
239 Write32(string
.Len());
240 if (string
.Len() > 0)
241 m_output
->Write(buf
, string
.Len());
244 // Must be at global scope for VC++ 5
245 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
247 void wxDataOutputStream::WriteDouble(double d
)
252 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
255 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
259 m_output
->Write(buf
, 10);
262 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
264 Write32(wxStrlen(string
));
265 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
269 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxString
& string
)
275 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
281 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
283 Write16((wxUint16
)i
);
287 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
289 Write32((wxUint32
)i
);
293 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
299 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
305 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
311 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint64 i
)
317 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
323 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
325 WriteDouble((double)f
);