Add wxDEPRECATED_MSG() and use it in a couple of places.
[wxWidgets.git] / include / wx / txtstrm.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/txtstrm.h
3 // Purpose: Text stream classes
4 // Author: Guilhem Lavaux
5 // Modified by:
6 // Created: 28/06/1998
7 // Copyright: (c) Guilhem Lavaux
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_TXTSTREAM_H_
12 #define _WX_TXTSTREAM_H_
13
14 #include "wx/stream.h"
15 #include "wx/convauto.h"
16
17 #if wxUSE_STREAMS
18
19 class WXDLLIMPEXP_FWD_BASE wxTextInputStream;
20 class WXDLLIMPEXP_FWD_BASE wxTextOutputStream;
21
22 typedef wxTextInputStream& (*__wxTextInputManip)(wxTextInputStream&);
23 typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&);
24
25 WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream );
26
27
28 #define wxEOT wxT('\4') // the End-Of-Text control code (used only inside wxTextInputStream)
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 #if wxUSE_UNICODE
39 wxTextInputStream(wxInputStream& s,
40 const wxString &sep=wxT(" \t"),
41 const wxMBConv& conv = wxConvAuto());
42 #else
43 wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t"));
44 #endif
45 ~wxTextInputStream();
46
47 const wxInputStream& GetInputStream() const { return m_input; }
48
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);
55 double ReadDouble();
56 wxString ReadLine();
57 wxString ReadWord();
58 wxChar GetChar() { wxChar c = NextChar(); return (wxChar)(c != wxEOT ? c : 0); }
59
60 wxString GetStringSeparators() const { return m_separators; }
61 void SetStringSeparators(const wxString &c) { m_separators = c; }
62
63 // Operators
64 wxTextInputStream& operator>>(wxString& word);
65 wxTextInputStream& operator>>(char& c);
66 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
67 wxTextInputStream& operator>>(wchar_t& wc);
68 #endif // wxUSE_UNICODE
69 wxTextInputStream& operator>>(wxInt16& i);
70 wxTextInputStream& operator>>(wxInt32& i);
71 wxTextInputStream& operator>>(wxUint16& i);
72 wxTextInputStream& operator>>(wxUint32& i);
73 wxTextInputStream& operator>>(double& i);
74 wxTextInputStream& operator>>(float& f);
75
76 wxTextInputStream& operator>>( __wxTextInputManip func) { return func(*this); }
77
78 #if WXWIN_COMPATIBILITY_2_6
79 wxDEPRECATED( wxString ReadString() ); // use ReadLine or ReadWord instead
80 #endif // WXWIN_COMPATIBILITY_2_6
81
82 protected:
83 wxInputStream &m_input;
84 wxString m_separators;
85 char m_lastBytes[10]; // stores the bytes that were read for the last character
86
87 #if wxUSE_UNICODE
88 wxMBConv *m_conv;
89 #endif
90
91 bool EatEOL(const wxChar &c);
92 void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
93 // returns EOT (\4) if there is a stream error, or end of file
94 wxChar NextChar(); // this should be used instead of GetC() because of Unicode issues
95 wxChar NextNonSeparators();
96
97 wxDECLARE_NO_COPY_CLASS(wxTextInputStream);
98 };
99
100 typedef enum
101 {
102 wxEOL_NATIVE,
103 wxEOL_UNIX,
104 wxEOL_MAC,
105 wxEOL_DOS
106 } wxEOL;
107
108 class WXDLLIMPEXP_BASE wxTextOutputStream
109 {
110 public:
111 #if wxUSE_UNICODE
112 wxTextOutputStream(wxOutputStream& s,
113 wxEOL mode = wxEOL_NATIVE,
114 const wxMBConv& conv = wxConvAuto());
115 #else
116 wxTextOutputStream(wxOutputStream& s, wxEOL mode = wxEOL_NATIVE);
117 #endif
118 virtual ~wxTextOutputStream();
119
120 const wxOutputStream& GetOutputStream() const { return m_output; }
121
122 void SetMode( wxEOL mode = wxEOL_NATIVE );
123 wxEOL GetMode() { return m_mode; }
124
125 void Write32(wxUint32 i);
126 void Write16(wxUint16 i);
127 void Write8(wxUint8 i);
128 virtual void WriteDouble(double d);
129 virtual void WriteString(const wxString& string);
130
131 wxTextOutputStream& PutChar(wxChar c);
132
133 void Flush();
134
135 wxTextOutputStream& operator<<(const wxString& string);
136 wxTextOutputStream& operator<<(char c);
137 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
138 wxTextOutputStream& operator<<(wchar_t wc);
139 #endif // wxUSE_UNICODE
140 wxTextOutputStream& operator<<(wxInt16 c);
141 wxTextOutputStream& operator<<(wxInt32 c);
142 wxTextOutputStream& operator<<(wxUint16 c);
143 wxTextOutputStream& operator<<(wxUint32 c);
144 wxTextOutputStream& operator<<(double f);
145 wxTextOutputStream& operator<<(float f);
146
147 wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); }
148
149 protected:
150 wxOutputStream &m_output;
151 wxEOL m_mode;
152
153 #if wxUSE_UNICODE
154 wxMBConv *m_conv;
155 #endif
156
157 wxDECLARE_NO_COPY_CLASS(wxTextOutputStream);
158 };
159
160 #endif
161 // wxUSE_STREAMS
162
163 #endif
164 // _WX_DATSTREAM_H_