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