]>
Commit | Line | Data |
---|---|---|
fae05df5 GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: txtstrm.h | |
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 | ||
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
fae05df5 GL |
16 | #pragma interface "txtstrm.h" |
17 | #endif | |
18 | ||
ed58dbea | 19 | #include "wx/stream.h" |
fae05df5 GL |
20 | |
21 | #if wxUSE_STREAMS | |
22 | ||
bddd7a8d VZ |
23 | class WXDLLIMPEXP_BASE wxTextInputStream; |
24 | class WXDLLIMPEXP_BASE wxTextOutputStream; | |
65045edd RR |
25 | |
26 | typedef wxTextInputStream& (*__wxTextInputManip)(wxTextInputStream&); | |
27 | typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&); | |
28 | ||
bddd7a8d | 29 | WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream ); |
65045edd | 30 | |
2b5f62a0 | 31 | |
2348a842 VZ |
32 | #define wxEOT wxT('\4') // the End-Of-Text control code (used only inside wxTextInputStream) |
33 | ||
34 | // If you're scanning through a file using wxTextInputStream, you should check for EOF _before_ | |
cb719f2e | 35 | // reading the next item (word / number), because otherwise the last item may get lost. |
2348a842 VZ |
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). | |
bddd7a8d | 39 | class WXDLLIMPEXP_BASE wxTextInputStream |
c7a9fa36 | 40 | { |
fae05df5 | 41 | public: |
2b5f62a0 VZ |
42 | #if wxUSE_UNICODE |
43 | wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t"), wxMBConv& conv = wxConvUTF8 ); | |
44 | #else | |
c7a9fa36 | 45 | wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t") ); |
2b5f62a0 | 46 | #endif |
c7a9fa36 RR |
47 | ~wxTextInputStream(); |
48 | ||
2348a842 VZ |
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); | |
c7a9fa36 | 55 | double ReadDouble(); |
2348a842 | 56 | wxString ReadString(); // deprecated: use ReadLine or ReadWord instead |
c7a9fa36 RR |
57 | wxString ReadLine(); |
58 | wxString ReadWord(); | |
254a2129 | 59 | wxChar GetChar() { wxChar c = NextChar(); return (wxChar)(c != wxEOT ? c : 0); } |
c7a9fa36 RR |
60 | |
61 | wxString GetStringSeparators() const { return m_separators; } | |
62 | void SetStringSeparators(const wxString &c) { m_separators = c; } | |
63 | ||
64 | // Operators | |
65 | wxTextInputStream& operator>>(wxString& word); | |
f6bcfd97 | 66 | wxTextInputStream& operator>>(char& c); |
c7a9fa36 RR |
67 | wxTextInputStream& operator>>(wxInt16& i); |
68 | wxTextInputStream& operator>>(wxInt32& i); | |
69 | wxTextInputStream& operator>>(wxUint16& i); | |
70 | wxTextInputStream& operator>>(wxUint32& i); | |
71 | wxTextInputStream& operator>>(double& i); | |
72 | wxTextInputStream& operator>>(float& f); | |
28f5bdb4 | 73 | |
c7a9fa36 | 74 | wxTextInputStream& operator>>( __wxTextInputManip func) { return func(*this); } |
28f5bdb4 | 75 | |
c7a9fa36 RR |
76 | protected: |
77 | wxInputStream &m_input; | |
78 | wxString m_separators; | |
2348a842 | 79 | char m_lastBytes[10]; // stores the bytes that were read for the last character |
cb719f2e | 80 | |
2b5f62a0 VZ |
81 | #if wxUSE_UNICODE |
82 | wxMBConv &m_conv; | |
83 | #endif | |
191549ed | 84 | |
c7a9fa36 | 85 | bool EatEOL(const wxChar &c); |
2348a842 VZ |
86 | void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues |
87 | // returns EOT (\4) if there is a stream error, or end of file | |
88 | wxChar NextChar(); // this should be used instead of GetC() because of Unicode issues | |
c7a9fa36 | 89 | wxChar NextNonSeparators(); |
fc7a2a60 VZ |
90 | |
91 | DECLARE_NO_COPY_CLASS(wxTextInputStream) | |
fae05df5 GL |
92 | }; |
93 | ||
2b5f62a0 VZ |
94 | typedef enum |
95 | { | |
c7a9fa36 RR |
96 | wxEOL_NATIVE, |
97 | wxEOL_UNIX, | |
98 | wxEOL_MAC, | |
28f5bdb4 | 99 | wxEOL_DOS |
c7a9fa36 | 100 | } wxEOL; |
fae05df5 | 101 | |
bddd7a8d | 102 | class WXDLLIMPEXP_BASE wxTextOutputStream |
c7a9fa36 RR |
103 | { |
104 | public: | |
2b5f62a0 VZ |
105 | #if wxUSE_UNICODE |
106 | wxTextOutputStream( wxOutputStream& s, wxEOL mode = wxEOL_NATIVE, wxMBConv& conv = wxConvUTF8 ); | |
107 | #else | |
c7a9fa36 | 108 | wxTextOutputStream( wxOutputStream& s, wxEOL mode = wxEOL_NATIVE ); |
2b5f62a0 | 109 | #endif |
c7a9fa36 RR |
110 | virtual ~wxTextOutputStream(); |
111 | ||
112 | void SetMode( wxEOL mode = wxEOL_NATIVE ); | |
113 | wxEOL GetMode() { return m_mode; } | |
114 | ||
115 | void Write32(wxUint32 i); | |
116 | void Write16(wxUint16 i); | |
117 | void Write8(wxUint8 i); | |
118 | virtual void WriteDouble(double d); | |
119 | virtual void WriteString(const wxString& string); | |
28f5bdb4 | 120 | |
c7a9fa36 RR |
121 | wxTextOutputStream& operator<<(const wxChar *string); |
122 | wxTextOutputStream& operator<<(const wxString& string); | |
f6bcfd97 | 123 | wxTextOutputStream& operator<<(char c); |
e4940feb | 124 | #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE |
3ca1bf5a | 125 | wxTextOutputStream& operator<<(wchar_t wc); |
e4940feb | 126 | #endif // wxUSE_UNICODE |
c7a9fa36 RR |
127 | wxTextOutputStream& operator<<(wxInt16 c); |
128 | wxTextOutputStream& operator<<(wxInt32 c); | |
129 | wxTextOutputStream& operator<<(wxUint16 c); | |
130 | wxTextOutputStream& operator<<(wxUint32 c); | |
131 | wxTextOutputStream& operator<<(double f); | |
132 | wxTextOutputStream& operator<<(float f); | |
28f5bdb4 | 133 | |
c7a9fa36 | 134 | wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); } |
28f5bdb4 | 135 | |
c7a9fa36 RR |
136 | protected: |
137 | wxOutputStream &m_output; | |
138 | wxEOL m_mode; | |
cb719f2e | 139 | |
2b5f62a0 VZ |
140 | #if wxUSE_UNICODE |
141 | wxMBConv &m_conv; | |
142 | #endif | |
143 | ||
fc7a2a60 | 144 | DECLARE_NO_COPY_CLASS(wxTextOutputStream) |
fae05df5 GL |
145 | }; |
146 | ||
147 | #endif | |
148 | // wxUSE_STREAMS | |
149 | ||
150 | #endif | |
151 | // _WX_DATSTREAM_H_ |