]>
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()
94 m_input
->Read(s
.GetWriteBuf(len
), len
);
100 wxDataInputStream
& wxDataInputStream::operator>>(wxString
& s
)
106 wxDataInputStream
& wxDataInputStream::operator>>(wxInt8
& c
)
112 wxDataInputStream
& wxDataInputStream::operator>>(wxInt16
& i
)
114 i
= (wxInt16
)Read16();
118 wxDataInputStream
& wxDataInputStream::operator>>(wxInt32
& i
)
120 i
= (wxInt32
)Read32();
124 wxDataInputStream
& wxDataInputStream::operator>>(wxUint8
& c
)
130 wxDataInputStream
& wxDataInputStream::operator>>(wxUint16
& i
)
136 wxDataInputStream
& wxDataInputStream::operator>>(wxUint32
& i
)
142 wxDataInputStream
& wxDataInputStream::operator>>(double& i
)
148 wxDataInputStream
& wxDataInputStream::operator>>(float& f
)
150 f
= (float)ReadDouble();
154 // ---------------------------------------------------------------------------
155 // wxDataOutputStream
156 // ---------------------------------------------------------------------------
158 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
159 : m_output(&s
), m_be_order(FALSE
)
163 wxDataOutputStream::~wxDataOutputStream()
167 void wxDataOutputStream::Write32(wxUint32 i
)
172 i32
= wxUINT32_SWAP_ON_LE(i
);
174 i32
= wxUINT32_SWAP_ON_BE(i
);
175 m_output
->Write(&i32
, 4);
178 void wxDataOutputStream::Write16(wxUint16 i
)
183 i16
= wxUINT16_SWAP_ON_LE(i
);
185 i16
= wxUINT16_SWAP_ON_BE(i
);
187 m_output
->Write(&i16
, 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
);
213 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
217 m_output
->Write(buf
, 10);
220 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
222 Write32(wxStrlen(string
));
223 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
227 wxDataOutputStream
& wxDataOutputStream::operator<<(wxString
& string
)
233 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
239 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
241 Write16((wxUint16
)i
);
245 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
247 Write32((wxUint32
)i
);
251 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
257 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
263 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
269 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
275 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
277 WriteDouble((double)f
);