]> git.saurik.com Git - wxWidgets.git/blob - include/wx/txtstrm.h
added wxWxCharBuffer which stands for buffer of wxChars
[wxWidgets.git] / include / wx / txtstrm.h
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TXTSTREAM_H_
13 #define _WX_TXTSTREAM_H_
14
15 #include "wx/stream.h"
16 #include "wx/convauto.h"
17
18 #if wxUSE_STREAMS
19
20 class WXDLLIMPEXP_BASE wxTextInputStream;
21 class WXDLLIMPEXP_BASE wxTextOutputStream;
22
23 typedef wxTextInputStream& (*__wxTextInputManip)(wxTextInputStream&);
24 typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&);
25
26 WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream );
27
28
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_
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
37 {
38 public:
39 #if wxUSE_UNICODE
40 wxTextInputStream(wxInputStream& s,
41 const wxString &sep=wxT(" \t"),
42 const wxMBConv& conv = wxConvAuto());
43 #else
44 wxTextInputStream(wxInputStream& s, const wxString &sep=wxT(" \t"));
45 #endif
46 ~wxTextInputStream();
47
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);
54 double ReadDouble();
55 wxString ReadString(); // deprecated: use ReadLine or ReadWord instead
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 protected:
79 wxInputStream &m_input;
80 wxString m_separators;
81 char m_lastBytes[10]; // stores the bytes that were read for the last character
82
83 #if wxUSE_UNICODE
84 wxMBConv *m_conv;
85 #endif
86
87 bool EatEOL(const wxChar &c);
88 void UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
89 // returns EOT (\4) if there is a stream error, or end of file
90 wxChar NextChar(); // this should be used instead of GetC() because of Unicode issues
91 wxChar NextNonSeparators();
92
93 DECLARE_NO_COPY_CLASS(wxTextInputStream)
94 };
95
96 typedef enum
97 {
98 wxEOL_NATIVE,
99 wxEOL_UNIX,
100 wxEOL_MAC,
101 wxEOL_DOS
102 } wxEOL;
103
104 class WXDLLIMPEXP_BASE wxTextOutputStream
105 {
106 public:
107 #if wxUSE_UNICODE
108 wxTextOutputStream(wxOutputStream& s,
109 wxEOL mode = wxEOL_NATIVE,
110 const wxMBConv& conv = wxConvAuto());
111 #else
112 wxTextOutputStream(wxOutputStream& s, wxEOL mode = wxEOL_NATIVE);
113 #endif
114 virtual ~wxTextOutputStream();
115
116 void SetMode( wxEOL mode = wxEOL_NATIVE );
117 wxEOL GetMode() { return m_mode; }
118
119 void Write32(wxUint32 i);
120 void Write16(wxUint16 i);
121 void Write8(wxUint8 i);
122 virtual void WriteDouble(double d);
123 virtual void WriteString(const wxString& string);
124
125 wxTextOutputStream& PutChar(wxChar c);
126
127 wxTextOutputStream& operator<<(const wxChar *string);
128 wxTextOutputStream& operator<<(const wxString& string);
129 wxTextOutputStream& operator<<(char c);
130 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
131 wxTextOutputStream& operator<<(wchar_t wc);
132 #endif // wxUSE_UNICODE
133 wxTextOutputStream& operator<<(wxInt16 c);
134 wxTextOutputStream& operator<<(wxInt32 c);
135 wxTextOutputStream& operator<<(wxUint16 c);
136 wxTextOutputStream& operator<<(wxUint32 c);
137 wxTextOutputStream& operator<<(double f);
138 wxTextOutputStream& operator<<(float f);
139
140 wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); }
141
142 protected:
143 wxOutputStream &m_output;
144 wxEOL m_mode;
145
146 #if wxUSE_UNICODE
147 wxMBConv *m_conv;
148 #endif
149
150 DECLARE_NO_COPY_CLASS(wxTextOutputStream)
151 };
152
153 #endif
154 // wxUSE_STREAMS
155
156 #endif
157 // _WX_DATSTREAM_H_