]>
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 char *tmp
= new char[len
+ 1];
95 m_input
->Read(tmp
, len
);
101 m_input
->Read(s
.GetWriteBuf(len
), len
);
108 wxDataInputStream
& wxDataInputStream::operator>>(wxString
& s
)
114 wxDataInputStream
& wxDataInputStream::operator>>(wxInt8
& c
)
120 wxDataInputStream
& wxDataInputStream::operator>>(wxInt16
& i
)
122 i
= (wxInt16
)Read16();
126 wxDataInputStream
& wxDataInputStream::operator>>(wxInt32
& i
)
128 i
= (wxInt32
)Read32();
132 wxDataInputStream
& wxDataInputStream::operator>>(wxUint8
& c
)
138 wxDataInputStream
& wxDataInputStream::operator>>(wxUint16
& i
)
144 wxDataInputStream
& wxDataInputStream::operator>>(wxUint32
& i
)
150 wxDataInputStream
& wxDataInputStream::operator>>(double& i
)
156 wxDataInputStream
& wxDataInputStream::operator>>(float& f
)
158 f
= (float)ReadDouble();
162 // ---------------------------------------------------------------------------
163 // wxDataOutputStream
164 // ---------------------------------------------------------------------------
166 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
167 : m_output(&s
), m_be_order(FALSE
)
171 wxDataOutputStream::~wxDataOutputStream()
175 void wxDataOutputStream::Write32(wxUint32 i
)
180 i32
= wxUINT32_SWAP_ON_LE(i
);
182 i32
= wxUINT32_SWAP_ON_BE(i
);
183 m_output
->Write(&i32
, 4);
186 void wxDataOutputStream::Write16(wxUint16 i
)
191 i16
= wxUINT16_SWAP_ON_LE(i
);
193 i16
= wxUINT16_SWAP_ON_BE(i
);
195 m_output
->Write(&i16
, 2);
198 void wxDataOutputStream::Write8(wxUint8 i
)
200 m_output
->Write(&i
, 1);
203 void wxDataOutputStream::WriteString(const wxString
& string
)
205 const wxWX2MBbuf buf
= string
.mb_str();
206 Write32(string
.Length());
207 m_output
->Write(buf
, string
.Len());
210 // Must be at global scope for VC++ 5
211 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
213 void wxDataOutputStream::WriteDouble(double d
)
218 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
221 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
225 m_output
->Write(buf
, 10);
228 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
230 Write32(wxStrlen(string
));
231 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
235 wxDataOutputStream
& wxDataOutputStream::operator<<(wxString
& string
)
241 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
247 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
249 Write16((wxUint16
)i
);
253 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
255 Write32((wxUint32
)i
);
259 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
265 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
271 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
277 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
283 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
285 WriteDouble((double)f
);