]>
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 : 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
;
101 if (last_endl
== '\r') {
103 InputStreamBuffer()->WriteBack(c
);
113 wxString
wxDataInputStream::ReadString()
120 string
= new char[len
+1];
131 // ---------------------------------------------------------------------------
132 // wxDataOutputStream
133 // ---------------------------------------------------------------------------
135 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
136 : wxFilterOutputStream(s
)
140 wxDataOutputStream::~wxDataOutputStream()
144 void wxDataOutputStream::Write32(unsigned long i
)
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
)
160 buf
[1] = (i
>> 8) & 0xff;
164 void wxDataOutputStream::Write8(unsigned char i
)
169 void wxDataOutputStream::WriteLine(const wxString
& line
)
172 wxString tmp_string
= line
+ _T("\r\n");
174 wxString tmp_string
= line
+ _T('\n');
177 Write((const wxChar
*) tmp_string
, tmp_string
.Length()*sizeof(wxChar
));
180 void wxDataOutputStream::WriteString(const wxString
& string
)
182 Write32(string
.Length());
183 Write((const wxChar
*) string
, string
.Length()*sizeof(wxChar
));
186 // Must be at global scope for VC++ 5
187 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
189 void wxDataOutputStream::WriteDouble(double d
)
194 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
196 # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"