]>
git.saurik.com Git - wxWidgets.git/blob - src/common/txtstrm.cpp
1 /////////////////////////////////////////////////////////////////////////////////
3 // Purpose: Text stream classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "txtstrm.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/txtstrm.h"
27 wxTextInputStream::wxTextInputStream(wxInputStream
& s
)
32 wxTextInputStream::~wxTextInputStream()
36 wxUint32
wxTextInputStream::Read32()
38 /* I only implemented a simple integer parser */
43 while (isspace( c
= m_input
->GetC() ) )
47 if (! (c
== '-' || isdigit(c
)) ) {
55 } else if (c
== '+') {
63 i
= i
*10 + (c
- (int)'0');
67 if (c
!= '\n' && c
!= '\r')
75 wxUint16
wxTextInputStream::Read16()
77 return (wxUint16
)Read32();
80 wxUint8
wxTextInputStream::Read8()
82 return (wxUint8
)Read32();
85 double wxTextInputStream::ReadDouble()
87 /* I only implemented a simple float parser */
91 while (isspace( c
= m_input
->GetC() ) || c
== '\n' || c
== '\r')
95 if (! (c
== '-' || isdigit(c
)) ) {
103 } else if (c
== '+') {
111 f
= f
*10 + (c
- '0');
116 double f_multiplicator
= (double) 0.1;
121 f
+= (c
-'0')*f_multiplicator
;
122 f_multiplicator
/= 10;
127 double f_multiplicator
= 0.0;
134 f_multiplicator
= 0.1;
137 f_multiplicator
= 10.0;
144 f
*= f_multiplicator
;
145 } else if (c
!= '\n' && c
!= '\r')
155 wxString
wxTextInputStream::ReadString()
157 char c
, last_endl
= 0;
158 bool end_line
= FALSE
;
163 if (m_input
->LastError() != wxStream_NOERROR
)
174 if (last_endl
== '\r') {
186 wxTextInputStream
& wxTextInputStream::operator>>(wxString
& line
)
192 wxTextInputStream
& wxTextInputStream::operator>>(wxChar
& c
)
196 m_input->Read(&c, sizeof(wxChar));
201 wxTextInputStream
& wxTextInputStream::operator>>(wxInt16
& i
)
203 i
= (wxInt16
)Read16();
207 wxTextInputStream
& wxTextInputStream::operator>>(wxInt32
& i
)
209 i
= (wxInt32
)Read32();
213 wxTextInputStream
& wxTextInputStream::operator>>(wxUint16
& i
)
219 wxTextInputStream
& wxTextInputStream::operator>>(wxUint32
& i
)
225 wxTextInputStream
& wxTextInputStream::operator>>(double& i
)
231 wxTextInputStream
& wxTextInputStream::operator>>(float& f
)
233 f
= (float)ReadDouble();
237 wxTextOutputStream::wxTextOutputStream(wxOutputStream
& s
)
242 wxTextOutputStream::~wxTextOutputStream()
246 void wxTextOutputStream::Write32(wxUint32 i
)
250 str
.Printf(_T("%u"), i
);
254 void wxTextOutputStream::Write16(wxUint16 i
)
258 str
.Printf(_T("%u"), i
);
262 void wxTextOutputStream::Write8(wxUint8 i
)
266 str
.Printf(_T("%u"), i
);
270 void wxTextOutputStream::WriteDouble(double d
)
274 str
.Printf(_T("%f"), d
);
278 void wxTextOutputStream::WriteString(const wxString
& string
)
281 const wxWX2MBbuf buf
= string
.mb_str();
282 m_output
->Write(buf
, string
.Len());
284 m_output
->Write(string
, string
.Len());
288 wxTextOutputStream
& wxTextOutputStream::operator<<(const wxChar
*string
)
290 WriteString(wxString(string
));
294 wxTextOutputStream
& wxTextOutputStream::operator<<(const wxString
& string
)
300 wxTextOutputStream
& wxTextOutputStream::operator<<(wxChar c
)
303 tmp_str
.Printf("%c", c
);
304 WriteString(tmp_str
);
308 wxTextOutputStream
& wxTextOutputStream::operator<<(wxInt16 c
)
310 Write16((wxUint16
)c
);
314 wxTextOutputStream
& wxTextOutputStream::operator<<(wxInt32 c
)
316 Write32((wxUint32
)c
);
320 wxTextOutputStream
& wxTextOutputStream::operator<<(wxUint16 c
)
326 wxTextOutputStream
& wxTextOutputStream::operator<<(wxUint32 c
)
332 wxTextOutputStream
&wxTextOutputStream::operator<<(double f
)
338 wxTextOutputStream
& wxTextOutputStream::operator<<(float f
)
340 WriteDouble((double)f
);