]>
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>>(wxInt8
& c
)
198 wxTextInputStream
& wxTextInputStream::operator>>(wxInt16
& i
)
200 i
= (wxInt16
)Read16();
204 wxTextInputStream
& wxTextInputStream::operator>>(wxInt32
& i
)
206 i
= (wxInt32
)Read32();
210 wxTextInputStream
& wxTextInputStream::operator>>(wxUint8
& c
)
216 wxTextInputStream
& wxTextInputStream::operator>>(wxUint16
& i
)
222 wxTextInputStream
& wxTextInputStream::operator>>(wxUint32
& i
)
228 wxTextInputStream
& wxTextInputStream::operator>>(double& i
)
234 wxTextInputStream
& wxTextInputStream::operator>>(float& f
)
236 f
= (float)ReadDouble();
240 wxTextOutputStream::wxTextOutputStream(wxOutputStream
& s
)
245 wxTextOutputStream::~wxTextOutputStream()
249 void wxTextOutputStream::Write32(wxUint32 i
)
253 str
.Printf(_T("%u"), i
);
257 void wxTextOutputStream::Write16(wxUint16 i
)
261 str
.Printf(_T("%u"), i
);
265 void wxTextOutputStream::Write8(wxUint8 i
)
269 str
.Printf(_T("%u"), i
);
273 void wxTextOutputStream::WriteDouble(double d
)
277 str
.Printf(_T("%f"), d
);
281 void wxTextOutputStream::WriteString(const wxString
& string
)
284 const wxWX2MBbuf buf
= string
.mb_str();
285 m_output
->Write(buf
, string
.Len());
287 m_output
->Write(string
, string
.Len());
291 wxTextOutputStream
& wxTextOutputStream::operator<<(const wxChar
*string
)
293 WriteString(wxString(string
));
297 wxTextOutputStream
& wxTextOutputStream::operator<<(const wxString
& string
)
303 wxTextOutputStream
& wxTextOutputStream::operator<<(wxInt8 c
)
309 wxTextOutputStream
& wxTextOutputStream::operator<<(wxInt16 c
)
311 Write16((wxUint16
)c
);
315 wxTextOutputStream
& wxTextOutputStream::operator<<(wxInt32 c
)
317 Write32((wxUint32
)c
);
321 wxTextOutputStream
& wxTextOutputStream::operator<<(wxUint8 c
)
327 wxTextOutputStream
& wxTextOutputStream::operator<<(wxUint16 c
)
333 wxTextOutputStream
& wxTextOutputStream::operator<<(wxUint32 c
)
339 wxTextOutputStream
&wxTextOutputStream::operator<<(double f
)
345 wxTextOutputStream
& wxTextOutputStream::operator<<(float f
)
347 WriteDouble((double)f
);