]>
git.saurik.com Git - wxWidgets.git/blob - src/common/datstrm.cpp
d83f968795578e4d6d070a71fe207ef8d7ddd325
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 : wxFilterInputStream(s
)
36 wxDataInputStream::~wxDataInputStream()
40 unsigned long wxDataInputStream::Read32()
46 return (unsigned long)buf
[0] |
47 ((unsigned long)buf
[1] << 8) |
48 ((unsigned long)buf
[2] << 16) |
49 ((unsigned long)buf
[3] << 24);
52 unsigned short wxDataInputStream::Read16()
58 return (unsigned short)buf
[0] |
59 ((unsigned short)buf
[1] << 8);
62 unsigned char wxDataInputStream::Read8()
67 return (unsigned char)buf
;
70 // Must be at global scope for VC++ 5
71 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
73 double wxDataInputStream::ReadDouble()
79 return ConvertFromIeeeExtended((unsigned char *)buf
);
85 wxString
wxDataInputStream::ReadLine()
87 char c
, last_endl
= 0;
88 bool end_line
= FALSE
;
93 if (LastError() != wxStream_NOERROR
)
104 if (last_endl
== '\r') {
106 InputStreamBuffer()->WriteBack(c
);
116 wxString
wxDataInputStream::ReadString()
123 string
= new char[len
+1];
134 // ---------------------------------------------------------------------------
135 // wxDataOutputStream
136 // ---------------------------------------------------------------------------
138 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
139 : wxFilterOutputStream(s
)
143 wxDataOutputStream::~wxDataOutputStream()
147 void wxDataOutputStream::Write32(unsigned long i
)
152 buf
[1] = (i
>> 8) & 0xff;
153 buf
[2] = (i
>> 16) & 0xff;
154 buf
[3] = (i
>> 24) & 0xff;
158 void wxDataOutputStream::Write16(unsigned short i
)
163 buf
[1] = (i
>> 8) & 0xff;
167 void wxDataOutputStream::Write8(unsigned char i
)
172 void wxDataOutputStream::WriteLine(const wxString
& line
)
175 wxString tmp_string
= line
+ _T("\r\n");
177 wxString tmp_string
= line
+ _T('\n');
180 Write((const wxChar
*) tmp_string
, tmp_string
.Length()*sizeof(wxChar
));
183 void wxDataOutputStream::WriteString(const wxString
& string
)
185 Write32(string
.Length());
186 Write((const wxChar
*) string
, string
.Length()*sizeof(wxChar
));
189 // Must be at global scope for VC++ 5
190 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
192 void wxDataOutputStream::WriteDouble(double d
)
197 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
199 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"