]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/txtstrm.h
even more interface fixes
[wxWidgets.git] / interface / wx / txtstrm.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: txtstrm.h
e54c96f1 3// Purpose: interface of wxTextInputStream
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
7977b62a
BP
9
10
23324ae1
FM
11/**
12 @class wxTextInputStream
7c913512 13
7977b62a
BP
14 This class provides functions that reads text data using an input stream,
15 allowing you to read text, floats, and integers.
16
17 The wxTextInputStream correctly reads text files (or streams) in DOS,
18 Macintosh and Unix formats and reports a single newline char as a line
19 ending.
20
21 wxTextInputStream::operator>>() is overloaded and you can use this class
22 like a standard C++ iostream. Note, however, that the arguments are the
23 fixed size types wxUint32, wxInt32 etc and on a typical 32-bit computer,
24 none of these match to the "long" type (wxInt32 is defined as int on 32-bit
25 architectures) so that you cannot use long. To avoid problems (here and
26 elsewhere), make use of wxInt32, wxUint32 and similar types.
27
28 If you're scanning through a file using wxTextInputStream, you should check
29 for @c EOF @b before reading the next item (word / number), because
30 otherwise the last item may get lost. You should however be prepared to
31 receive an empty item (empty string / zero number) at the end of file,
32 especially on Windows systems. This is unavoidable because most (but not
33 all) files end with whitespace (i.e. usually a newline).
7c913512 34
23324ae1 35 For example:
7c913512 36
23324ae1
FM
37 @code
38 wxFileInputStream input( "mytext.txt" );
7977b62a
BP
39 wxTextInputStream text( input );
40 wxUint8 i1;
41 float f2;
42 wxString line;
43
44 text >> i1; // read a 8 bit integer.
45 text >> i1 >> f2; // read a 8 bit integer followed by float.
46 text >> line; // read a text line
23324ae1 47 @endcode
7c913512 48
23324ae1
FM
49 @library{wxbase}
50 @category{streams}
7c913512 51
7977b62a 52 @see wxTextOutputStream
23324ae1 53*/
7c913512 54class wxTextInputStream
23324ae1
FM
55{
56public:
57 /**
23324ae1 58 Constructs a text stream associated to the given input stream.
3c4f71cc 59
7c913512 60 @param stream
4cc4bfaf 61 The underlying input stream.
7c913512 62 @param sep
4cc4bfaf 63 The initial string separator characters.
7c913512 64 @param conv
7977b62a
BP
65 <b>In Unicode build only:</b> The encoding converter used to
66 convert the bytes in the underlying input stream to characters.
23324ae1
FM
67 */
68 wxTextInputStream(wxInputStream& stream,
7977b62a
BP
69 const wxString& sep = " \t",
70 const wxMBConv& conv = wxConvAuto());
23324ae1
FM
71
72 /**
7977b62a 73 Destructor.
23324ae1
FM
74 */
75 ~wxTextInputStream();
76
77 /**
7977b62a
BP
78 Reads a character, returns 0 if there are no more characters in the
79 stream.
23324ae1
FM
80 */
81 wxChar GetChar();
82
83 /**
84 Reads a unsigned 16 bit integer from the stream.
7977b62a
BP
85
86 See Read8() for the description of the @a base parameter.
23324ae1
FM
87 */
88 wxUint16 Read16(int base = 10);
89
90 /**
91 Reads a signed 16 bit integer from the stream.
7977b62a
BP
92
93 See Read8() for the description of the @a base parameter.
23324ae1
FM
94 */
95 wxInt16 Read16S(int base = 10);
96
97 /**
98 Reads a 32 bit unsigned integer from the stream.
7977b62a
BP
99
100 See Read8() for the description of the @a base parameter.
23324ae1
FM
101 */
102 wxUint32 Read32(int base = 10);
103
104 /**
105 Reads a 32 bit signed integer from the stream.
7977b62a
BP
106
107 See Read8() for the description of the @a base parameter.
23324ae1
FM
108 */
109 wxInt32 Read32S(int base = 10);
110
111 /**
7977b62a
BP
112 Reads a single unsigned byte from the stream, given in base @a base.
113
4cc4bfaf 114 The value of @a base must be comprised between 2 and 36, inclusive, or
7977b62a 115 be a special value 0 which means that the usual rules of C numbers are
23324ae1 116 applied: if the number starts with @c 0x it is considered to be in base
7977b62a
BP
117 16, if it starts with 0 - in base 8 and in base 10 otherwise. Note that
118 you may not want to specify the base 0 if you are parsing the numbers
119 which may have leading zeroes as they can yield unexpected (to the user
120 not familiar with C) results.
23324ae1
FM
121 */
122 wxUint8 Read8(int base = 10);
123
124 /**
125 Reads a single signed byte from the stream.
7977b62a
BP
126
127 See Read8() for the description of the @a base parameter.
23324ae1
FM
128 */
129 wxInt8 Read8S(int base = 10);
130
131 /**
132 Reads a double (IEEE encoded) from the stream.
133 */
134 double ReadDouble();
135
136 /**
7977b62a
BP
137 Reads a line from the input stream and returns it (without the end of
138 line character).
23324ae1
FM
139 */
140 wxString ReadLine();
141
142 /**
7977b62a
BP
143 @deprecated Use ReadLine() or ReadWord() instead.
144
23324ae1
FM
145 Same as ReadLine().
146 */
147 wxString ReadString();
148
149 /**
7977b62a
BP
150 Reads a word (a sequence of characters until the next separator) from
151 the input stream.
3c4f71cc 152
4cc4bfaf 153 @see SetStringSeparators()
23324ae1
FM
154 */
155 wxString ReadWord();
156
157 /**
7c913512 158 Sets the characters which are used to define the word boundaries in
23324ae1 159 ReadWord().
7977b62a
BP
160
161 The default separators are the @c space and @c TAB characters.
23324ae1
FM
162 */
163 void SetStringSeparators(const wxString& sep);
164};
165
166
7977b62a
BP
167/**
168 Specifies the end-of-line characters to use with wxTextOutputStream.
169*/
170typedef enum
171{
172 /**
173 Specifies wxTextOutputStream to use the native end-of-line characters.
174 */
175 wxEOL_NATIVE,
176
177 /**
178 Specifies wxTextOutputStream to use Unix end-of-line characters.
179 */
180 wxEOL_UNIX,
181
182 /**
183 Specifies wxTextOutputStream to use Mac end-of-line characters.
184 */
185 wxEOL_MAC,
186
187 /**
188 Specifies wxTextOutputStream to use DOS end-of-line characters.
189 */
190 wxEOL_DOS
191} wxEOL;
192
e54c96f1 193
23324ae1
FM
194/**
195 @class wxTextOutputStream
7c913512 196
ca8cf4ff 197 This class provides functions that write text data using an output stream,
7977b62a 198 allowing you to write text, floats, and integers.
7c913512 199
ca8cf4ff 200 You can also simulate the C++ @c std::cout class:
7c913512 201
23324ae1
FM
202 @code
203 wxFFileOutputStream output( stderr );
7977b62a 204 wxTextOutputStream cout( output );
7c913512 205
7977b62a
BP
206 cout << "This is a text line" << endl;
207 cout << 1234;
208 cout << 1.23456;
23324ae1 209 @endcode
7c913512 210
7977b62a
BP
211 The wxTextOutputStream writes text files (or streams) on DOS, Macintosh and
212 Unix in their native formats (concerning the line ending).
7c913512 213
23324ae1
FM
214 @library{wxbase}
215 @category{streams}
7977b62a
BP
216
217 @see wxTextInputStream
23324ae1 218*/
7c913512 219class wxTextOutputStream
23324ae1
FM
220{
221public:
222 /**
23324ae1 223 Constructs a text stream object associated to the given output stream.
3c4f71cc 224
7c913512 225 @param stream
4cc4bfaf 226 The output stream.
7c913512 227 @param mode
7977b62a
BP
228 The end-of-line mode. One of ::wxEOL_NATIVE, ::wxEOL_DOS,
229 ::wxEOL_MAC and ::wxEOL_UNIX.
7c913512 230 @param conv
7977b62a 231 <b>In Unicode build only:</b> The object used to convert
4cc4bfaf 232 Unicode text into ASCII characters written to the output stream.
23324ae1
FM
233 */
234 wxTextOutputStream(wxOutputStream& stream,
7977b62a
BP
235 wxEOL mode = wxEOL_NATIVE,
236 const wxMBConv& conv = wxConvAuto());
23324ae1
FM
237
238 /**
239 Destroys the wxTextOutputStream object.
ca8cf4ff
VZ
240
241 Also calls Flush().
23324ae1 242 */
adaaa686 243 virtual ~wxTextOutputStream();
23324ae1 244
ca8cf4ff
VZ
245 /**
246 Flushes the stream.
247
248 This method should be called when using stateful encodings (currently
249 the only example of such encoding in wxWidgets is wxMBConvUTF7) to
250 write the end of the encoded data to the stream.
251
252 @since 2.9.0
253 */
254 void Flush();
255
23324ae1 256 /**
7977b62a
BP
257 Returns the end-of-line mode. One of ::wxEOL_DOS, ::wxEOL_MAC and
258 ::wxEOL_UNIX.
23324ae1
FM
259 */
260 wxEOL GetMode();
261
262 /**
263 Writes a character to the stream.
264 */
265 void PutChar(wxChar c);
266
267 /**
7977b62a
BP
268 Set the end-of-line mode. One of ::wxEOL_NATIVE, ::wxEOL_DOS,
269 ::wxEOL_MAC and ::wxEOL_UNIX.
23324ae1
FM
270 */
271 void SetMode(wxEOL mode = wxEOL_NATIVE);
272
273 /**
4cc4bfaf 274 Writes the 16 bit integer @a i16 to the stream.
23324ae1
FM
275 */
276 void Write16(wxUint16 i16);
277
278 /**
4cc4bfaf 279 Writes the 32 bit integer @a i32 to the stream.
23324ae1
FM
280 */
281 void Write32(wxUint32 i32);
282
283 /**
4cc4bfaf 284 Writes the single byte @a i8 to the stream.
23324ae1
FM
285 */
286 void Write8(wxUint8 i8);
287
288 /**
4cc4bfaf 289 Writes the double @a f to the stream using the IEEE format.
23324ae1
FM
290 */
291 virtual void WriteDouble(double f);
292
293 /**
4cc4bfaf 294 Writes @a string as a line. Depending on the end-of-line mode the end of
7977b62a
BP
295 line ('\\n') characters in the string are converted to the correct line
296 ending terminator.
23324ae1
FM
297 */
298 virtual void WriteString(const wxString& string);
299};
e54c96f1 300