]>
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 string
= new char[len
+1];
96 m_input
->Read(string
, len
);
105 wxDataInputStream
& wxDataInputStream::operator>>(wxString
& s
)
111 wxDataInputStream
& wxDataInputStream::operator>>(wxInt8
& c
)
117 wxDataInputStream
& wxDataInputStream::operator>>(wxInt16
& i
)
119 i
= (wxInt16
)Read16();
123 wxDataInputStream
& wxDataInputStream::operator>>(wxInt32
& i
)
125 i
= (wxInt32
)Read32();
129 wxDataInputStream
& wxDataInputStream::operator>>(wxUint8
& c
)
135 wxDataInputStream
& wxDataInputStream::operator>>(wxUint16
& i
)
141 wxDataInputStream
& wxDataInputStream::operator>>(wxUint32
& i
)
147 wxDataInputStream
& wxDataInputStream::operator>>(double& i
)
153 wxDataInputStream
& wxDataInputStream::operator>>(float& f
)
155 f
= (float)ReadDouble();
159 // ---------------------------------------------------------------------------
160 // wxDataOutputStream
161 // ---------------------------------------------------------------------------
163 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
164 : m_output(&s
), m_be_order(FALSE
)
168 wxDataOutputStream::~wxDataOutputStream()
172 void wxDataOutputStream::Write32(wxUint32 i
)
177 i32
= wxUINT32_SWAP_ON_LE(i
);
179 i32
= wxUINT32_SWAP_ON_BE(i
);
180 m_output
->Write(&i32
, 4);
183 void wxDataOutputStream::Write16(wxUint16 i
)
188 i16
= wxUINT16_SWAP_ON_LE(i
);
190 i16
= wxUINT16_SWAP_ON_BE(i
);
192 m_output
->Write(&i16
, 2);
195 void wxDataOutputStream::Write8(wxUint8 i
)
197 m_output
->Write(&i
, 1);
200 void wxDataOutputStream::WriteString(const wxString
& string
)
202 const wxWX2MBbuf buf
= string
.mb_str();
203 Write32(string
.Length());
204 m_output
->Write(buf
, string
.Len());
207 // Must be at global scope for VC++ 5
208 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
210 void wxDataOutputStream::WriteDouble(double d
)
215 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
218 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
222 m_output
->Write(buf
, 10);
225 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
227 Write32(wxStrlen(string
));
228 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
232 wxDataOutputStream
& wxDataOutputStream::operator<<(wxString
& string
)
238 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
244 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
246 Write16((wxUint16
)i
);
250 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
252 Write32((wxUint32
)i
);
256 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
262 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
268 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
274 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
280 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
282 WriteDouble((double)f
);