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 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_CLASS(wxDataInputStream
, wxFilterInputStream
)
31 IMPLEMENT_CLASS(wxDataOutputStream
, wxFilterOutputStream
)
34 wxDataInputStream
::wxDataInputStream(wxInputStream
& s
)
35 : wxFilterInputStream(s
)
39 wxDataInputStream
::~wxDataInputStream()
43 unsigned long wxDataInputStream
::Read32()
47 if (!m_parent_i_stream
)
52 return (unsigned long)buf
[0] |
53 ((unsigned long)buf
[1] << 8) |
54 ((unsigned long)buf
[2] << 16) |
55 ((unsigned long)buf
[3] << 24);
58 unsigned short wxDataInputStream
::Read16()
62 if (!m_parent_i_stream
)
67 return (unsigned short)buf
[0] |
68 ((unsigned short)buf
[1] << 8);
71 unsigned char wxDataInputStream
::Read8()
75 if (!m_parent_i_stream
)
79 return (unsigned char)buf
;
82 // Must be at global scope for VC++ 5
83 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
85 double wxDataInputStream
::ReadDouble()
90 if (!m_parent_i_stream
)
94 return ConvertFromIeeeExtended((unsigned char *)buf
);
100 wxString wxDataInputStream
::ReadLine()
104 if (!m_parent_i_stream
)
107 // TODO: Implement ReadLine
111 wxString wxDataInputStream
::ReadString()
117 if (!m_parent_i_stream
)
121 string
= new char[len
+1];
132 wxDataOutputStream
::wxDataOutputStream(wxOutputStream
& s
)
133 : wxFilterOutputStream(s
)
137 wxDataOutputStream
::~wxDataOutputStream()
141 void wxDataOutputStream
::Write32(unsigned long i
)
145 if (!m_parent_o_stream
)
149 buf
[1] = (i
>> 8) & 0xff;
150 buf
[2] = (i
>> 16) & 0xff;
151 buf
[3] = (i
>> 24) & 0xff;
155 void wxDataOutputStream
::Write16(unsigned short i
)
159 if (!m_parent_o_stream
)
163 buf
[1] = (i
>> 8) & 0xff;
167 void wxDataOutputStream
::Write8(unsigned char i
)
169 if (!m_parent_o_stream
)
175 void wxDataOutputStream
::WriteLine(const wxString
& line
)
178 wxString tmp_string
= line
+ "\r\n";
180 wxString tmp_string
= line
+ '\n';
183 if (!m_parent_o_stream
)
186 Write((const char *) tmp_string
, tmp_string
.Length());
189 void wxDataOutputStream
::WriteString(const wxString
& string
)
191 if (!m_parent_o_stream
)
194 Write32(string
.Length());
195 Write((const char *) string
, string
.Length());
198 // Must be at global scope for VC++ 5
199 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
201 void wxDataOutputStream
::WriteDouble(double d
)
205 if (!m_parent_o_stream
)
209 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
211 # pragma warning "wxDataStream::WriteDouble() not using IeeeExtended - will not work!"