]>
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"
27 #include "wx/datstrm.h"
29 wxDataStream::wxDataStream(istream
& s
)
35 wxDataStream::wxDataStream(ostream
& s
)
41 wxDataStream::wxDataStream(iostream
& s
)
47 wxDataStream::~wxDataStream()
51 unsigned long wxDataStream::Read32()
58 m_istream
->read(buf
, 4);
60 return (unsigned long)buf
[0] |
61 ((unsigned long)buf
[1] << 8) |
62 ((unsigned long)buf
[2] << 16) |
63 ((unsigned long)buf
[3] << 24);
66 unsigned short wxDataStream::Read16()
73 m_istream
->read(buf
, 2);
75 return (unsigned short)buf
[0] |
76 ((unsigned short)buf
[1] << 8);
79 unsigned char wxDataStream::Read8()
86 m_istream
->read(&buf
, 1);
87 return (unsigned char)buf
;
90 // Must be at global scope for VC++ 5
91 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
93 double wxDataStream::ReadDouble()
101 m_istream
->read(buf
, 10);
102 return ConvertFromIeeeExtended((unsigned char *)buf
);
108 wxString
wxDataStream::ReadLine()
115 m_istream
->getline(i_strg
, 255);
119 wxString
wxDataStream::ReadString()
129 string
= new char[len
+1];
131 m_istream
->read(string
, len
);
140 void wxDataStream::Write32(unsigned long i
)
148 buf
[1] = (i
>> 8) & 0xff;
149 buf
[2] = (i
>> 16) & 0xff;
150 buf
[3] = (i
>> 24) & 0xff;
151 m_ostream
->write(buf
, 4);
154 void wxDataStream::Write16(unsigned short i
)
162 buf
[1] = (i
>> 8) & 0xff;
163 m_ostream
->write(buf
, 2);
166 void wxDataStream::Write8(unsigned char i
)
171 m_ostream
->write(&i
, 1);
174 void wxDataStream::WriteLine(const wxString
& line
)
177 wxString tmp_string
= line
+ "\r\n";
179 wxString tmp_string
= line
+ '\n';
185 m_ostream
->write((const char *) tmp_string
, tmp_string
.Length());
188 void wxDataStream::WriteString(const wxString
& string
)
193 Write32(string
.Length());
194 m_ostream
->write((const char *) string
, string
.Length());
197 // Must be at global scope for VC++ 5
198 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
200 void wxDataStream::WriteDouble(double d
)
208 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
210 # pragma warning "wxDataStream::WriteDouble() not using IeeeExtended - will not work!"
213 m_ostream
->write(buf
, 10);