1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Text stream classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TXTSTREAM_H_
13 #define _WX_TXTSTREAM_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "txtstrm.h"
19 #include "wx/stream.h"
23 class WXDLLIMPEXP_BASE wxTextInputStream
;
24 class WXDLLIMPEXP_BASE wxTextOutputStream
;
26 typedef wxTextInputStream
& (*__wxTextInputManip
)(wxTextInputStream
&);
27 typedef wxTextOutputStream
& (*__wxTextOutputManip
)(wxTextOutputStream
&);
29 WXDLLIMPEXP_BASE wxTextOutputStream
&endl( wxTextOutputStream
&stream
);
32 #define wxEOT wxT('\4') // the End-Of-Text control code (used only inside wxTextInputStream)
34 // If you're scanning through a file using wxTextInputStream, you should check for EOF _before_
35 // reading the next item (word / number), because otherwise the last item may get lost.
36 // You should however be prepared to receive an empty item (empty string / zero number) at the
37 // end of file, especially on Windows systems. This is unavoidable because most (but not all) files end
38 // with whitespace (i.e. usually a newline).
39 class WXDLLIMPEXP_BASE wxTextInputStream
43 wxTextInputStream(wxInputStream
& s
, const wxString
&sep
=wxT(" \t"), wxMBConv
& conv
= wxConvUTF8
);
45 wxTextInputStream(wxInputStream
& s
, const wxString
&sep
=wxT(" \t") );
49 wxUint32
Read32(int base
= 10); // base may be between 2 and 36, inclusive, or the special 0 (= C format)
50 wxUint16
Read16(int base
= 10);
51 wxUint8
Read8(int base
= 10);
52 wxInt32
Read32S(int base
= 10);
53 wxInt16
Read16S(int base
= 10);
54 wxInt8
Read8S(int base
= 10);
56 wxString
ReadString(); // deprecated: use ReadLine or ReadWord instead
59 wxChar
GetChar() { wxChar c
= NextChar(); return (wxChar
)(c
!= wxEOT
? c
: 0); }
61 wxString
GetStringSeparators() const { return m_separators
; }
62 void SetStringSeparators(const wxString
&c
) { m_separators
= c
; }
65 wxTextInputStream
& operator>>(wxString
& word
);
66 wxTextInputStream
& operator>>(char& c
);
67 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
68 wxTextInputStream
& operator>>(wchar_t& wc
);
69 #endif // wxUSE_UNICODE
70 wxTextInputStream
& operator>>(wxInt16
& i
);
71 wxTextInputStream
& operator>>(wxInt32
& i
);
72 wxTextInputStream
& operator>>(wxUint16
& i
);
73 wxTextInputStream
& operator>>(wxUint32
& i
);
74 wxTextInputStream
& operator>>(double& i
);
75 wxTextInputStream
& operator>>(float& f
);
77 wxTextInputStream
& operator>>( __wxTextInputManip func
) { return func(*this); }
80 wxInputStream
&m_input
;
81 wxString m_separators
;
82 char m_lastBytes
[10]; // stores the bytes that were read for the last character
88 bool EatEOL(const wxChar
&c
);
89 void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
90 // returns EOT (\4) if there is a stream error, or end of file
91 wxChar
NextChar(); // this should be used instead of GetC() because of Unicode issues
92 wxChar
NextNonSeparators();
94 DECLARE_NO_COPY_CLASS(wxTextInputStream
)
105 class WXDLLIMPEXP_BASE wxTextOutputStream
109 wxTextOutputStream( wxOutputStream
& s
, wxEOL mode
= wxEOL_NATIVE
, wxMBConv
& conv
= wxConvUTF8
);
111 wxTextOutputStream( wxOutputStream
& s
, wxEOL mode
= wxEOL_NATIVE
);
113 virtual ~wxTextOutputStream();
115 void SetMode( wxEOL mode
= wxEOL_NATIVE
);
116 wxEOL
GetMode() { return m_mode
; }
118 void Write32(wxUint32 i
);
119 void Write16(wxUint16 i
);
120 void Write8(wxUint8 i
);
121 virtual void WriteDouble(double d
);
122 virtual void WriteString(const wxString
& string
);
124 wxTextOutputStream
& operator<<(const wxChar
*string
);
125 wxTextOutputStream
& operator<<(const wxString
& string
);
126 wxTextOutputStream
& operator<<(char c
);
127 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
128 wxTextOutputStream
& operator<<(wchar_t wc
);
129 #endif // wxUSE_UNICODE
130 wxTextOutputStream
& operator<<(wxInt16 c
);
131 wxTextOutputStream
& operator<<(wxInt32 c
);
132 wxTextOutputStream
& operator<<(wxUint16 c
);
133 wxTextOutputStream
& operator<<(wxUint32 c
);
134 wxTextOutputStream
& operator<<(double f
);
135 wxTextOutputStream
& operator<<(float f
);
137 wxTextOutputStream
& operator<<( __wxTextOutputManip func
) { return func(*this); }
140 wxOutputStream
&m_output
;
147 DECLARE_NO_COPY_CLASS(wxTextOutputStream
)