]>
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"
28 wxTextInputStream::wxTextInputStream(wxInputStream
& s
)
33 wxTextInputStream::~wxTextInputStream()
37 wxUint32
wxTextInputStream::Read32()
39 /* I only implemented a simple integer parser */
44 while (isspace( c
= m_input
->GetC() ) )
48 if (! (c
== '-' || isdigit(c
)) ) {
56 } else if (c
== '+') {
64 i
= i
*10 + (c
- (int)'0');
68 if (c
!= '\n' && c
!= '\r')
76 wxUint16
wxTextInputStream::Read16()
78 return (wxUint16
)Read32();
81 wxUint8
wxTextInputStream::Read8()
83 return (wxUint8
)Read32();
86 double wxTextInputStream::ReadDouble()
88 /* I only implemented a simple float parser */
92 while (isspace( c
= m_input
->GetC() ) || c
== '\n' || c
== '\r')
96 if (! (c
== '-' || isdigit(c
)) ) {
104 } else if (c
== '+') {
112 f
= f
*10 + (c
- '0');
117 double f_multiplicator
= (double) 0.1;
122 f
+= (c
-'0')*f_multiplicator
;
123 f_multiplicator
/= 10;
128 double f_multiplicator
= 0.0;
135 f_multiplicator
= 0.1;
138 f_multiplicator
= 10.0;
145 f
*= f_multiplicator
;
146 } else if (c
!= '\n' && c
!= '\r')
156 wxString
wxTextInputStream::ReadString()
158 char c
, last_endl
= 0;
159 bool end_line
= FALSE
;
164 if (m_input
->LastError() != wxStream_NOERROR
)
175 if (last_endl
== '\r') {
187 wxTextInputStream
& wxTextInputStream::operator>>(wxString
& line
)
193 wxTextInputStream
& wxTextInputStream::operator>>(wxChar
& c
)
197 m_input->Read(&c, sizeof(wxChar));
202 wxTextInputStream
& wxTextInputStream::operator>>(wxInt16
& i
)
204 i
= (wxInt16
)Read16();
208 wxTextInputStream
& wxTextInputStream::operator>>(wxInt32
& i
)
210 i
= (wxInt32
)Read32();
214 wxTextInputStream
& wxTextInputStream::operator>>(wxUint16
& i
)
220 wxTextInputStream
& wxTextInputStream::operator>>(wxUint32
& i
)
226 wxTextInputStream
& wxTextInputStream::operator>>(double& i
)
232 wxTextInputStream
& wxTextInputStream::operator>>(float& f
)
234 f
= (float)ReadDouble();
238 wxTextOutputStream::wxTextOutputStream(wxOutputStream
& s
)
243 wxTextOutputStream::~wxTextOutputStream()
247 void wxTextOutputStream::Write32(wxUint32 i
)
251 str
.Printf(_T("%u"), i
);
255 void wxTextOutputStream::Write16(wxUint16 i
)
259 str
.Printf(_T("%u"), i
);
263 void wxTextOutputStream::Write8(wxUint8 i
)
267 str
.Printf(_T("%u"), i
);
271 void wxTextOutputStream::WriteDouble(double d
)
275 str
.Printf(_T("%f"), d
);
279 void wxTextOutputStream::WriteString(const wxString
& string
)
282 const wxWX2MBbuf buf
= string
.mb_str();
283 m_output
->Write(buf
, string
.Len());
285 m_output
->Write(string
, string
.Len());
289 wxTextOutputStream
& wxTextOutputStream::operator<<(const wxChar
*string
)
291 WriteString(wxString(string
));
295 wxTextOutputStream
& wxTextOutputStream::operator<<(const wxString
& string
)
301 wxTextOutputStream
& wxTextOutputStream::operator<<(wxChar c
)
304 tmp_str
.Printf(_T("%c"), c
);
305 WriteString(tmp_str
);
309 wxTextOutputStream
& wxTextOutputStream::operator<<(wxInt16 c
)
311 Write16((wxUint16
)c
);
315 wxTextOutputStream
& wxTextOutputStream::operator<<(wxInt32 c
)
317 Write32((wxUint32
)c
);
321 wxTextOutputStream
& wxTextOutputStream::operator<<(wxUint16 c
)
327 wxTextOutputStream
& wxTextOutputStream::operator<<(wxUint32 c
)
333 wxTextOutputStream
&wxTextOutputStream::operator<<(double f
)
339 wxTextOutputStream
& wxTextOutputStream::operator<<(float f
)
341 WriteDouble((double)f
);