]>
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 // ---------------------------------------------------------------------------
31 // ---------------------------------------------------------------------------
33 wxDataInputStream::wxDataInputStream(wxInputStream
& s
)
34 : wxFilterInputStream(s
)
38 wxDataInputStream::~wxDataInputStream()
42 unsigned long wxDataInputStream::Read32()
48 return (unsigned long)buf
[0] |
49 ((unsigned long)buf
[1] << 8) |
50 ((unsigned long)buf
[2] << 16) |
51 ((unsigned long)buf
[3] << 24);
54 unsigned short wxDataInputStream::Read16()
60 return (unsigned short)buf
[0] |
61 ((unsigned short)buf
[1] << 8);
64 unsigned char wxDataInputStream::Read8()
69 return (unsigned char)buf
;
72 // Must be at global scope for VC++ 5
73 extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes
);
75 double wxDataInputStream::ReadDouble()
81 return ConvertFromIeeeExtended((unsigned char *)buf
);
87 wxString
wxDataInputStream::ReadLine()
89 char c
, last_endl
= 0;
90 bool end_line
= FALSE
;
103 if (last_endl
== '\r') {
105 InputStreamBuffer()->WriteBack(c
);
115 wxString
wxDataInputStream::ReadString()
122 string
= new char[len
+1];
133 // ---------------------------------------------------------------------------
134 // wxDataOutputStream
135 // ---------------------------------------------------------------------------
137 wxDataOutputStream::wxDataOutputStream(wxOutputStream
& s
)
138 : wxFilterOutputStream(s
)
142 wxDataOutputStream::~wxDataOutputStream()
146 void wxDataOutputStream::Write32(unsigned long i
)
151 buf
[1] = (i
>> 8) & 0xff;
152 buf
[2] = (i
>> 16) & 0xff;
153 buf
[3] = (i
>> 24) & 0xff;
157 void wxDataOutputStream::Write16(unsigned short i
)
162 buf
[1] = (i
>> 8) & 0xff;
166 void wxDataOutputStream::Write8(unsigned char i
)
171 void wxDataOutputStream::WriteLine(const wxString
& line
)
174 wxString tmp_string
= line
+ "\r\n";
176 wxString tmp_string
= line
+ '\n';
179 Write((const char *) tmp_string
, tmp_string
.Length());
182 void wxDataOutputStream::WriteString(const wxString
& string
)
184 Write32(string
.Length());
185 Write((const char *) string
, string
.Length());
188 // Must be at global scope for VC++ 5
189 extern "C" void ConvertToIeeeExtended(double num
, unsigned char *bytes
);
191 void wxDataOutputStream::WriteDouble(double d
)
196 ConvertToIeeeExtended(d
, (unsigned char *)buf
);
198 # pragma warning "wxDataStream::WriteDouble() not using IeeeExtended - will not work!"
204 // ---------------------------------------------------------------------------
206 // ---------------------------------------------------------------------------
208 wxDataStream::wxDataStream(wxStream
& stream
)
209 : wxDataInputStream(stream
), wxDataOutputStream(stream
)