]>
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"
29 #include "wx/datstrm.h"
31 // ---------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------
35 wxDataInputStream::wxDataInputStream(wxInputStream
& s
)
36 : wxFilterInputStream(s
)
40 wxDataInputStream::~wxDataInputStream()
44 unsigned long wxDataInputStream::Read32()
50 return (unsigned long)buf
[0] |
51 ((unsigned long)buf
[1] << 8) |
52 ((unsigned long)buf
[2] << 16) |
53 ((unsigned long)buf
[3] << 24);
56 unsigned short wxDataInputStream::Read16()
62 return (unsigned short)buf
[0] |
63 ((unsigned short)buf
[1] << 8);
66 unsigned char wxDataInputStream::Read8()
71 return (unsigned char)buf
;
74 // Must be at global scope for VC++ 5
75 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
77 double wxDataInputStream::ReadDouble()
83 return ConvertFromIeeeExtended((unsigned char *)buf
);
89 wxString
wxDataInputStream::ReadLine()
91 char c
, last_endl
= 0;
92 bool end_line
= FALSE
;
105 if (last_endl
== '\r') {
107 InputStreamBuffer()->WriteBack(c
);
117 wxString
wxDataInputStream::ReadString()
124 string
= new char[len
+1];
135 // ---------------------------------------------------------------------------
136 // wxDataOutputStream
137 // ---------------------------------------------------------------------------
139 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
140 : wxFilterOutputStream(s
)
144 wxDataOutputStream::~wxDataOutputStream()
148 void wxDataOutputStream::Write32(unsigned long i
)
153 buf
[1] = (i
>> 8) & 0xff;
154 buf
[2] = (i
>> 16) & 0xff;
155 buf
[3] = (i
>> 24) & 0xff;
159 void wxDataOutputStream::Write16(unsigned short i
)
164 buf
[1] = (i
>> 8) & 0xff;
168 void wxDataOutputStream::Write8(unsigned char i
)
173 void wxDataOutputStream::WriteLine(const wxString
& line
)
176 wxString tmp_string
= line
+ _T("\r\n");
178 wxString tmp_string
= line
+ _T('\n');
181 Write((const wxChar
*) tmp_string
, tmp_string
.Length()*sizeof(wxChar
));
184 void wxDataOutputStream::WriteString(const wxString
& string
)
186 Write32(string
.Length());
187 Write((const wxChar
*) string
, string
.Length()*sizeof(wxChar
));
190 // Must be at global scope for VC++ 5
191 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
193 void wxDataOutputStream::WriteDouble(double d
)
198 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
200 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"