]>
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 wxUint32
wxDataInputStream::Read32()
44 m_input
->Read(&i32
, 4);
47 return wxUINT32_SWAP_ON_LE(i32
);
49 return wxUINT32_SWAP_ON_BE(i32
);
52 wxUint16
wxDataInputStream::Read16()
56 m_input
->Read(&i16
, 2);
59 return wxUINT16_SWAP_ON_LE(i16
);
61 return wxUINT16_SWAP_ON_BE(i16
);
64 wxUint8
wxDataInputStream::Read8()
68 m_input
->Read(&buf
, 1);
72 // Must be at global scope for VC++ 5
73 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
75 double wxDataInputStream::ReadDouble()
80 m_input
->Read(buf
, 10);
81 return ConvertFromIeeeExtended((unsigned char *)buf
);
87 wxString
wxDataInputStream::ReadString()
96 char *tmp
= new char[len
+ 1];
97 m_input
->Read(tmp
, len
);
103 m_input
->Read(s
.GetWriteBuf(len
), len
);
109 return wxEmptyString
;
112 wxDataInputStream
& wxDataInputStream::operator>>(wxString
& s
)
118 wxDataInputStream
& wxDataInputStream::operator>>(wxInt8
& c
)
124 wxDataInputStream
& wxDataInputStream::operator>>(wxInt16
& i
)
126 i
= (wxInt16
)Read16();
130 wxDataInputStream
& wxDataInputStream::operator>>(wxInt32
& i
)
132 i
= (wxInt32
)Read32();
136 wxDataInputStream
& wxDataInputStream::operator>>(wxUint8
& c
)
142 wxDataInputStream
& wxDataInputStream::operator>>(wxUint16
& i
)
148 wxDataInputStream
& wxDataInputStream::operator>>(wxUint32
& i
)
154 wxDataInputStream
& wxDataInputStream::operator>>(double& i
)
160 wxDataInputStream
& wxDataInputStream::operator>>(float& f
)
162 f
= (float)ReadDouble();
166 // ---------------------------------------------------------------------------
167 // wxDataOutputStream
168 // ---------------------------------------------------------------------------
170 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
171 : m_output(&s
), m_be_order(FALSE
)
175 wxDataOutputStream::~wxDataOutputStream()
179 void wxDataOutputStream::Write32(wxUint32 i
)
184 i32
= wxUINT32_SWAP_ON_LE(i
);
186 i32
= wxUINT32_SWAP_ON_BE(i
);
187 m_output
->Write(&i32
, 4);
190 void wxDataOutputStream::Write16(wxUint16 i
)
195 i16
= wxUINT16_SWAP_ON_LE(i
);
197 i16
= wxUINT16_SWAP_ON_BE(i
);
199 m_output
->Write(&i16
, 2);
202 void wxDataOutputStream::Write8(wxUint8 i
)
204 m_output
->Write(&i
, 1);
207 void wxDataOutputStream::WriteString(const wxString
& string
)
209 const wxWX2MBbuf buf
= string
.mb_str();
210 Write32(string
.Len());
211 if (string
.Len() > 0)
212 m_output
->Write(buf
, string
.Len());
215 // Must be at global scope for VC++ 5
216 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
218 void wxDataOutputStream::WriteDouble(double d
)
223 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
226 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
230 m_output
->Write(buf
, 10);
233 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
235 Write32(wxStrlen(string
));
236 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
240 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxString
& string
)
246 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
252 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
254 Write16((wxUint16
)i
);
258 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
260 Write32((wxUint32
)i
);
264 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
270 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
276 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
282 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
288 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
290 WriteDouble((double)f
);