]>
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
)
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
);
217 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
220 m_output
->Write(buf
, 10);
223 wxDataOutputStream
& wxDataOutputStream::operator<<(const wxChar
*string
)
225 Write32(wxStrlen(string
));
226 m_output
->Write((const char *)string
, wxStrlen(string
)*sizeof(wxChar
));
230 wxDataOutputStream
& wxDataOutputStream::operator<<(wxString
& string
)
236 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt8 c
)
242 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt16 i
)
244 Write16((wxUint16
)i
);
248 wxDataOutputStream
& wxDataOutputStream::operator<<(wxInt32 i
)
250 Write32((wxUint32
)i
);
254 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint8 c
)
260 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint16 i
)
266 wxDataOutputStream
& wxDataOutputStream::operator<<(wxUint32 i
)
272 wxDataOutputStream
& wxDataOutputStream::operator<<(double f
)
278 wxDataOutputStream
& wxDataOutputStream::operator<<(float f
)
280 WriteDouble((double)f
);