/src/wxwidgets/include/wx/txtstrm.h
Line | Count | Source |
1 | | ///////////////////////////////////////////////////////////////////////////// |
2 | | // Name: wx/txtstrm.h |
3 | | // Purpose: Text stream classes |
4 | | // Author: Guilhem Lavaux |
5 | | // Created: 28/06/1998 |
6 | | // Copyright: (c) Guilhem Lavaux |
7 | | // Licence: wxWindows licence |
8 | | ///////////////////////////////////////////////////////////////////////////// |
9 | | |
10 | | #ifndef _WX_TXTSTREAM_H_ |
11 | | #define _WX_TXTSTREAM_H_ |
12 | | |
13 | | #include "wx/stream.h" |
14 | | #include "wx/convauto.h" |
15 | | |
16 | | #if wxUSE_STREAMS |
17 | | |
18 | | class WXDLLIMPEXP_FWD_BASE wxTextInputStream; |
19 | | class WXDLLIMPEXP_FWD_BASE wxTextOutputStream; |
20 | | |
21 | | typedef wxTextInputStream& (*__wxTextInputManip)(wxTextInputStream&); |
22 | | typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&); |
23 | | |
24 | | WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream ); |
25 | | |
26 | | |
27 | | // Obsolete constant defined only for compatibility, not used. |
28 | | #define wxEOT wxT('\4') |
29 | | |
30 | | // If you're scanning through a file using wxTextInputStream, you should check for EOF _before_ |
31 | | // reading the next item (word / number), because otherwise the last item may get lost. |
32 | | // You should however be prepared to receive an empty item (empty string / zero number) at the |
33 | | // end of file, especially on Windows systems. This is unavoidable because most (but not all) files end |
34 | | // with whitespace (i.e. usually a newline). |
35 | | class WXDLLIMPEXP_BASE wxTextInputStream |
36 | | { |
37 | | public: |
38 | | wxTextInputStream(wxInputStream& s, |
39 | | const wxString &sep=wxT(" \t"), |
40 | | const wxMBConv& conv = wxConvAuto()); |
41 | | ~wxTextInputStream(); |
42 | | |
43 | 0 | const wxInputStream& GetInputStream() const { return m_input; } |
44 | | |
45 | | // base may be between 2 and 36, inclusive, or the special 0 (= C format) |
46 | | wxUint64 Read64(int base = 10); |
47 | | wxUint32 Read32(int base = 10); |
48 | | wxUint16 Read16(int base = 10); |
49 | | wxUint8 Read8(int base = 10); |
50 | | wxInt64 Read64S(int base = 10); |
51 | | wxInt32 Read32S(int base = 10); |
52 | | wxInt16 Read16S(int base = 10); |
53 | | wxInt8 Read8S(int base = 10); |
54 | | double ReadDouble(); |
55 | | wxString ReadLine(); |
56 | | wxString ReadWord(); |
57 | | wxChar GetChar(); |
58 | | |
59 | 0 | wxString GetStringSeparators() const { return m_separators; } |
60 | 0 | void SetStringSeparators(const wxString &c) { m_separators = c; } |
61 | | |
62 | | // Operators |
63 | | wxTextInputStream& operator>>(wxString& word); |
64 | | wxTextInputStream& operator>>(char& c); |
65 | | #if wxWCHAR_T_IS_REAL_TYPE |
66 | | wxTextInputStream& operator>>(wchar_t& wc); |
67 | | #endif |
68 | | wxTextInputStream& operator>>(wxInt16& i); |
69 | | wxTextInputStream& operator>>(wxInt32& i); |
70 | | wxTextInputStream& operator>>(wxInt64& i); |
71 | | wxTextInputStream& operator>>(wxUint16& i); |
72 | | wxTextInputStream& operator>>(wxUint32& i); |
73 | | wxTextInputStream& operator>>(wxUint64& i); |
74 | | wxTextInputStream& operator>>(double& i); |
75 | | wxTextInputStream& operator>>(float& f); |
76 | | |
77 | 0 | wxTextInputStream& operator>>( __wxTextInputManip func) { return func(*this); } |
78 | | |
79 | | protected: |
80 | | wxInputStream &m_input; |
81 | | wxString m_separators; |
82 | | |
83 | | // Data possibly (see m_validXXX) read from the stream but not decoded yet. |
84 | | // This is necessary because GetChar() may only return a single character |
85 | | // but we may get more than one character when decoding raw input bytes. |
86 | | char m_lastBytes[10]; |
87 | | |
88 | | // The bytes [0, m_validEnd) of m_lastBytes contain the bytes read by the |
89 | | // last GetChar() call (this interval may be empty if GetChar() hasn't been |
90 | | // called yet). The bytes [0, m_validBegin) have been already decoded and |
91 | | // returned to caller or stored in m_lastWChar in the particularly |
92 | | // egregious case of decoding a non-BMP character when using UTF-16 for |
93 | | // wchar_t. Finally, the bytes [m_validBegin, m_validEnd) remain to be |
94 | | // decoded and returned during the next call (again, this interval can, and |
95 | | // usually will, be empty too if m_validBegin == m_validEnd). |
96 | | size_t m_validBegin, |
97 | | m_validEnd; |
98 | | |
99 | | wxMBConv *m_conv; |
100 | | |
101 | | // The second half of a surrogate character when using UTF-16 for wchar_t: |
102 | | // we can't return it immediately from GetChar() when we read a Unicode |
103 | | // code point outside of the BMP, but we can't keep it in m_lastBytes |
104 | | // either because it can't separately decoded, so we have a separate 1 |
105 | | // wchar_t buffer just for this case. |
106 | | #if SIZEOF_WCHAR_T == 2 |
107 | | wchar_t m_lastWChar; |
108 | | #endif // SIZEOF_WCHAR_T == 2 |
109 | | |
110 | | bool EatEOL(const wxChar &c); |
111 | | void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues |
112 | | wxChar NextNonSeparators(); |
113 | | |
114 | | wxDECLARE_NO_COPY_CLASS(wxTextInputStream); |
115 | | }; |
116 | | |
117 | | enum wxEOL |
118 | | { |
119 | | wxEOL_NATIVE, |
120 | | wxEOL_UNIX, |
121 | | wxEOL_MAC, |
122 | | wxEOL_DOS |
123 | | }; |
124 | | |
125 | | class WXDLLIMPEXP_BASE wxTextOutputStream |
126 | | { |
127 | | public: |
128 | | wxTextOutputStream(wxOutputStream& s, |
129 | | wxEOL mode = wxEOL_NATIVE, |
130 | | const wxMBConv& conv = wxConvAuto()); |
131 | | virtual ~wxTextOutputStream(); |
132 | | |
133 | 0 | const wxOutputStream& GetOutputStream() const { return m_output; } |
134 | | |
135 | | void SetMode( wxEOL mode = wxEOL_NATIVE ); |
136 | 0 | wxEOL GetMode() { return m_mode; } |
137 | | |
138 | | template<typename T> |
139 | | void Write(const T& i) |
140 | 0 | { |
141 | 0 | wxString str; |
142 | 0 | str << i; |
143 | |
|
144 | 0 | WriteString(str); |
145 | 0 | } Unexecuted instantiation: void wxTextOutputStream::Write<short>(short const&) Unexecuted instantiation: void wxTextOutputStream::Write<int>(int const&) Unexecuted instantiation: void wxTextOutputStream::Write<long long>(long long const&) Unexecuted instantiation: void wxTextOutputStream::Write<unsigned short>(unsigned short const&) Unexecuted instantiation: void wxTextOutputStream::Write<unsigned int>(unsigned int const&) Unexecuted instantiation: void wxTextOutputStream::Write<unsigned long long>(unsigned long long const&) Unexecuted instantiation: void wxTextOutputStream::Write<double>(double const&) Unexecuted instantiation: void wxTextOutputStream::Write<float>(float const&) |
146 | | |
147 | | void Write64(wxUint64 i); |
148 | | void Write32(wxUint32 i); |
149 | | void Write16(wxUint16 i); |
150 | | void Write8(wxUint8 i); |
151 | | virtual void WriteDouble(double d); |
152 | | virtual void WriteString(const wxString& string); |
153 | | |
154 | | wxTextOutputStream& PutChar(wxChar c); |
155 | | |
156 | | void Flush(); |
157 | | |
158 | | wxTextOutputStream& operator<<(const wxString& string); |
159 | | wxTextOutputStream& operator<<(char c); |
160 | | #if wxWCHAR_T_IS_REAL_TYPE |
161 | | wxTextOutputStream& operator<<(wchar_t wc); |
162 | | #endif |
163 | | wxTextOutputStream& operator<<(wxInt16 c); |
164 | | wxTextOutputStream& operator<<(wxInt32 c); |
165 | | wxTextOutputStream& operator<<(wxInt64 c); |
166 | | wxTextOutputStream& operator<<(wxUint16 c); |
167 | | wxTextOutputStream& operator<<(wxUint32 c); |
168 | | wxTextOutputStream& operator<<(wxUint64 c); |
169 | | wxTextOutputStream& operator<<(double f); |
170 | | wxTextOutputStream& operator<<(float f); |
171 | | |
172 | 0 | wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); } |
173 | | |
174 | | protected: |
175 | | wxOutputStream &m_output; |
176 | | wxEOL m_mode; |
177 | | |
178 | | wxMBConv *m_conv; |
179 | | |
180 | | #if SIZEOF_WCHAR_T == 2 |
181 | | // The first half of a surrogate character if one was passed to PutChar() |
182 | | // and couldn't be output when it was called the last time. |
183 | | wchar_t m_lastWChar; |
184 | | #endif // SIZEOF_WCHAR_T == 2 |
185 | | |
186 | | wxDECLARE_NO_COPY_CLASS(wxTextOutputStream); |
187 | | }; |
188 | | |
189 | | #endif |
190 | | // wxUSE_STREAMS |
191 | | |
192 | | #endif |
193 | | // _WX_DATSTREAM_H_ |