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 #include "wx/stream.h"
16 #include "wx/convauto.h"
20 class WXDLLIMPEXP_BASE wxTextInputStream
;
21 class WXDLLIMPEXP_BASE wxTextOutputStream
;
23 typedef wxTextInputStream
& (*__wxTextInputManip
)(wxTextInputStream
&);
24 typedef wxTextOutputStream
& (*__wxTextOutputManip
)(wxTextOutputStream
&);
26 WXDLLIMPEXP_BASE wxTextOutputStream
&endl( wxTextOutputStream
&stream
);
29 #define wxEOT wxT('\4') // the End-Of-Text control code (used only inside wxTextInputStream)
31 // If you're scanning through a file using wxTextInputStream, you should check for EOF _before_
32 // reading the next item (word / number), because otherwise the last item may get lost.
33 // You should however be prepared to receive an empty item (empty string / zero number) at the
34 // end of file, especially on Windows systems. This is unavoidable because most (but not all) files end
35 // with whitespace (i.e. usually a newline).
36 class WXDLLIMPEXP_BASE wxTextInputStream
40 wxTextInputStream(wxInputStream
& s
,
41 const wxString
&sep
=wxT(" \t"),
42 const wxMBConv
& conv
= wxConvAuto());
44 wxTextInputStream(wxInputStream
& s
, const wxString
&sep
=wxT(" \t"));
48 wxUint32
Read32(int base
= 10); // base may be between 2 and 36, inclusive, or the special 0 (= C format)
49 wxUint16
Read16(int base
= 10);
50 wxUint8
Read8(int base
= 10);
51 wxInt32
Read32S(int base
= 10);
52 wxInt16
Read16S(int base
= 10);
53 wxInt8
Read8S(int base
= 10);
57 wxChar
GetChar() { wxChar c
= NextChar(); return (wxChar
)(c
!= wxEOT
? c
: 0); }
59 wxString
GetStringSeparators() const { return m_separators
; }
60 void SetStringSeparators(const wxString
&c
) { m_separators
= c
; }
63 wxTextInputStream
& operator>>(wxString
& word
);
64 wxTextInputStream
& operator>>(char& c
);
65 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
66 wxTextInputStream
& operator>>(wchar_t& wc
);
67 #endif // wxUSE_UNICODE
68 wxTextInputStream
& operator>>(wxInt16
& i
);
69 wxTextInputStream
& operator>>(wxInt32
& i
);
70 wxTextInputStream
& operator>>(wxUint16
& i
);
71 wxTextInputStream
& operator>>(wxUint32
& i
);
72 wxTextInputStream
& operator>>(double& i
);
73 wxTextInputStream
& operator>>(float& f
);
75 wxTextInputStream
& operator>>( __wxTextInputManip func
) { return func(*this); }
77 #if WXWIN_COMPATIBILITY_2_6
78 wxDEPRECATED( wxString
ReadString() ); // use ReadLine or ReadWord instead
79 #endif // WXWIN_COMPATIBILITY_2_6
82 wxInputStream
&m_input
;
83 wxString m_separators
;
84 char m_lastBytes
[10]; // stores the bytes that were read for the last character
90 bool EatEOL(const wxChar
&c
);
91 void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
92 // returns EOT (\4) if there is a stream error, or end of file
93 wxChar
NextChar(); // this should be used instead of GetC() because of Unicode issues
94 wxChar
NextNonSeparators();
96 DECLARE_NO_COPY_CLASS(wxTextInputStream
)
107 class WXDLLIMPEXP_BASE wxTextOutputStream
111 wxTextOutputStream(wxOutputStream
& s
,
112 wxEOL mode
= wxEOL_NATIVE
,
113 const wxMBConv
& conv
= wxConvAuto());
115 wxTextOutputStream(wxOutputStream
& s
, wxEOL mode
= wxEOL_NATIVE
);
117 virtual ~wxTextOutputStream();
119 void SetMode( wxEOL mode
= wxEOL_NATIVE
);
120 wxEOL
GetMode() { return m_mode
; }
122 void Write32(wxUint32 i
);
123 void Write16(wxUint16 i
);
124 void Write8(wxUint8 i
);
125 virtual void WriteDouble(double d
);
126 virtual void WriteString(const wxString
& string
);
128 wxTextOutputStream
& PutChar(wxChar c
);
130 wxTextOutputStream
& operator<<(const wxString
& string
);
131 wxTextOutputStream
& operator<<(char c
);
132 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
133 wxTextOutputStream
& operator<<(wchar_t wc
);
134 #endif // wxUSE_UNICODE
135 wxTextOutputStream
& operator<<(wxInt16 c
);
136 wxTextOutputStream
& operator<<(wxInt32 c
);
137 wxTextOutputStream
& operator<<(wxUint16 c
);
138 wxTextOutputStream
& operator<<(wxUint32 c
);
139 wxTextOutputStream
& operator<<(double f
);
140 wxTextOutputStream
& operator<<(float f
);
142 wxTextOutputStream
& operator<<( __wxTextOutputManip func
) { return func(*this); }
145 wxOutputStream
&m_output
;
152 DECLARE_NO_COPY_CLASS(wxTextOutputStream
)