]>
Commit | Line | Data |
---|---|---|
fae05df5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
40ff126a | 2 | // Name: wx/txtstrm.h |
fae05df5 GL |
3 | // Purpose: Text stream classes |
4 | // Author: Guilhem Lavaux | |
5 | // Modified by: | |
6 | // Created: 28/06/1998 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Guilhem Lavaux | |
cb719f2e | 9 | // Licence: wxWindows licence |
fae05df5 GL |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_TXTSTREAM_H_ | |
13 | #define _WX_TXTSTREAM_H_ | |
14 | ||
ed58dbea | 15 | #include "wx/stream.h" |
830f8f11 | 16 | #include "wx/convauto.h" |
fae05df5 GL |
17 | |
18 | #if wxUSE_STREAMS | |
19 | ||
b5dbe15d VS |
20 | class WXDLLIMPEXP_FWD_BASE wxTextInputStream; |
21 | class WXDLLIMPEXP_FWD_BASE wxTextOutputStream; | |
65045edd RR |
22 | |
23 | typedef wxTextInputStream& (*__wxTextInputManip)(wxTextInputStream&); | |
24 | typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&); | |
25 | ||
bddd7a8d | 26 | WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream ); |
65045edd | 27 | |
2b5f62a0 | 28 | |
2348a842 VZ |
29 | #define wxEOT wxT('\4') // the End-Of-Text control code (used only inside wxTextInputStream) |
30 | ||
31 | // If you're scanning through a file using wxTextInputStream, you should check for EOF _before_ | |
cb719f2e | 32 | // reading the next item (word / number), because otherwise the last item may get lost. |
2348a842 VZ |
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). | |
bddd7a8d | 36 | class WXDLLIMPEXP_BASE wxTextInputStream |
c7a9fa36 | 37 | { |
fae05df5 | 38 | public: |
2b5f62a0 | 39 | #if wxUSE_UNICODE |
830f8f11 VZ |
40 | wxTextInputStream(wxInputStream& s, |
41 | const wxString &sep=wxT(" \t"), | |
42 | const wxMBConv& conv = wxConvAuto()); | |
2b5f62a0 | 43 | #else |
830f8f11 | 44 | wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t")); |
2b5f62a0 | 45 | #endif |
c7a9fa36 RR |
46 | ~wxTextInputStream(); |
47 | ||
2348a842 VZ |
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); | |
c7a9fa36 | 54 | double ReadDouble(); |
c7a9fa36 RR |
55 | wxString ReadLine(); |
56 | wxString ReadWord(); | |
254a2129 | 57 | wxChar GetChar() { wxChar c = NextChar(); return (wxChar)(c != wxEOT ? c : 0); } |
c7a9fa36 RR |
58 | |
59 | wxString GetStringSeparators() const { return m_separators; } | |
60 | void SetStringSeparators(const wxString &c) { m_separators = c; } | |
61 | ||
62 | // Operators | |
63 | wxTextInputStream& operator>>(wxString& word); | |
f6bcfd97 | 64 | wxTextInputStream& operator>>(char& c); |
fdd99f15 VZ |
65 | #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE |
66 | wxTextInputStream& operator>>(wchar_t& wc); | |
67 | #endif // wxUSE_UNICODE | |
c7a9fa36 RR |
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); | |
28f5bdb4 | 74 | |
c7a9fa36 | 75 | wxTextInputStream& operator>>( __wxTextInputManip func) { return func(*this); } |
28f5bdb4 | 76 | |
40ff126a WS |
77 | #if WXWIN_COMPATIBILITY_2_6 |
78 | wxDEPRECATED( wxString ReadString() ); // use ReadLine or ReadWord instead | |
79 | #endif // WXWIN_COMPATIBILITY_2_6 | |
80 | ||
c7a9fa36 RR |
81 | protected: |
82 | wxInputStream &m_input; | |
83 | wxString m_separators; | |
2348a842 | 84 | char m_lastBytes[10]; // stores the bytes that were read for the last character |
cb719f2e | 85 | |
2b5f62a0 | 86 | #if wxUSE_UNICODE |
d36c9347 | 87 | wxMBConv *m_conv; |
2b5f62a0 | 88 | #endif |
191549ed | 89 | |
c7a9fa36 | 90 | bool EatEOL(const wxChar &c); |
2348a842 VZ |
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 | |
c7a9fa36 | 94 | wxChar NextNonSeparators(); |
fc7a2a60 VZ |
95 | |
96 | DECLARE_NO_COPY_CLASS(wxTextInputStream) | |
fae05df5 GL |
97 | }; |
98 | ||
2b5f62a0 VZ |
99 | typedef enum |
100 | { | |
c7a9fa36 RR |
101 | wxEOL_NATIVE, |
102 | wxEOL_UNIX, | |
103 | wxEOL_MAC, | |
28f5bdb4 | 104 | wxEOL_DOS |
c7a9fa36 | 105 | } wxEOL; |
fae05df5 | 106 | |
bddd7a8d | 107 | class WXDLLIMPEXP_BASE wxTextOutputStream |
c7a9fa36 RR |
108 | { |
109 | public: | |
2b5f62a0 | 110 | #if wxUSE_UNICODE |
830f8f11 VZ |
111 | wxTextOutputStream(wxOutputStream& s, |
112 | wxEOL mode = wxEOL_NATIVE, | |
113 | const wxMBConv& conv = wxConvAuto()); | |
2b5f62a0 | 114 | #else |
830f8f11 | 115 | wxTextOutputStream(wxOutputStream& s, wxEOL mode = wxEOL_NATIVE); |
2b5f62a0 | 116 | #endif |
c7a9fa36 RR |
117 | virtual ~wxTextOutputStream(); |
118 | ||
119 | void SetMode( wxEOL mode = wxEOL_NATIVE ); | |
120 | wxEOL GetMode() { return m_mode; } | |
121 | ||
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); | |
28f5bdb4 | 127 | |
ba854691 RN |
128 | wxTextOutputStream& PutChar(wxChar c); |
129 | ||
ca8cf4ff VZ |
130 | void Flush(); |
131 | ||
c7a9fa36 | 132 | wxTextOutputStream& operator<<(const wxString& string); |
f6bcfd97 | 133 | wxTextOutputStream& operator<<(char c); |
e4940feb | 134 | #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE |
3ca1bf5a | 135 | wxTextOutputStream& operator<<(wchar_t wc); |
e4940feb | 136 | #endif // wxUSE_UNICODE |
c7a9fa36 RR |
137 | wxTextOutputStream& operator<<(wxInt16 c); |
138 | wxTextOutputStream& operator<<(wxInt32 c); | |
139 | wxTextOutputStream& operator<<(wxUint16 c); | |
140 | wxTextOutputStream& operator<<(wxUint32 c); | |
141 | wxTextOutputStream& operator<<(double f); | |
142 | wxTextOutputStream& operator<<(float f); | |
28f5bdb4 | 143 | |
c7a9fa36 | 144 | wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); } |
28f5bdb4 | 145 | |
c7a9fa36 RR |
146 | protected: |
147 | wxOutputStream &m_output; | |
148 | wxEOL m_mode; | |
cb719f2e | 149 | |
2b5f62a0 | 150 | #if wxUSE_UNICODE |
d36c9347 | 151 | wxMBConv *m_conv; |
2b5f62a0 VZ |
152 | #endif |
153 | ||
fc7a2a60 | 154 | DECLARE_NO_COPY_CLASS(wxTextOutputStream) |
fae05df5 GL |
155 | }; |
156 | ||
157 | #endif | |
158 | // wxUSE_STREAMS | |
159 | ||
160 | #endif | |
161 | // _WX_DATSTREAM_H_ |