]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/txtstrm.tex
corrected ancient event type constant in an example
[wxWidgets.git] / docs / latex / wx / txtstrm.tex
CommitLineData
a3c1786d
GL
1% ----------------------------------------------------------------------------
2% wxTextInputStream
3% ----------------------------------------------------------------------------
4\section{\class{wxTextInputStream}}\label{wxtextinputstream}
5
6This class provides functions that read text datas using an input stream.
605d715d 7So, you can read {\it text} floats, integers.
a3c1786d 8
7ff14117
RR
9The wxTextInputStream correctly reads text files (or streams) in DOS, Macintosh
10and Unix formats and reports a single newline char as a line ending.
11
b453e1b2
RR
12Operator >> is overloaded and you can use this class like a standard C++ iostream.
13Note, however, that the arguments are the fixed size types wxUint32, wxInt32 etc
14and on a typical 32-bit computer, none of these match to the "long" type (wxInt32
15is defined as int on 32-bit architectures) so that you cannot use long. To avoid
b2cf617c 16problems (here and elsewhere), make use of wxInt32, wxUint32 and similar types.
a3c1786d 17
2348a842
VZ
18If you're scanning through a file using wxTextInputStream, you should check for EOF {\bf before}
19reading the next item (word / number), because otherwise the last item may get lost.
20You should however be prepared to receive an empty item (empty string / zero number) at the
21end of file, especially on Windows systems. This is unavoidable because most (but not all) files end
22with whitespace (i.e. usually a newline).
23
a3c1786d 24For example:
b2cf617c 25
a3c1786d 26\begin{verbatim}
b453e1b2 27 wxFileInputStream input( "mytext.txt" );
a3c1786d
GL
28 wxTextInputStream text( input );
29 wxUint8 i1;
30 float f2;
31 wxString line;
32
33 text >> i1; // read a 8 bit integer.
3660fc40 34 text >> i1 >> f2; // read a 8 bit integer followed by float.
a3c1786d
GL
35 text >> line; // read a text line
36\end{verbatim}
37
38\wxheading{Include files}
39
40<wx/txtstrm.h>
41
42\latexignore{\rtfignore{\wxheading{Members}}}
43
0f353563 44
15d83f72 45\membersection{wxTextInputStream::wxTextInputStream}\label{wxtextinputstreamctor}
a3c1786d 46
5bb31e35 47\func{}{wxTextInputStream}{\param{wxInputStream\&}{ stream}, \param{const wxString\&}{ sep=" $\backslash$t"},
2348a842 48 \param{wxMBConv\&}{ conv = wxConvUTF8} }
a3c1786d 49
9a32d27d 50Constructs a text stream associated to the given input stream.
a3c1786d
GL
51
52\wxheading{Parameters}
53
2348a842
VZ
54\docparam{stream}{The underlying input stream.}
55
56\docparam{sep}{The initial string separator characters.}
57
58\docparam{conv}{{\it In Unicode build only:} The encoding converter used to convert the bytes in the
59 underlying input stream to characters.}
a3c1786d 60
0f353563 61
15d83f72 62\membersection{wxTextInputStream::\destruct{wxTextInputStream}}\label{wxtextinputstreamdtor}
a3c1786d
GL
63
64\func{}{\destruct{wxTextInputStream}}{\void}
65
66Destroys the wxTextInputStream object.
67
0f353563 68
2348a842
VZ
69\membersection{wxTextInputStream::Read8}\label{wxtextinputstreamread8}
70
71\func{wxUint8}{Read8}{\param{int}{ base = 10}}
72
73Reads a single unsigned byte from the stream, given in base {\it base}.
a3c1786d 74
2348a842
VZ
75The value of {\it base} must be comprised between $2$ and $36$, inclusive, or
76be a special value $0$ which means that the usual rules of {\tt C} numbers are
77applied: if the number starts with {\tt 0x} it is considered to be in base
78$16$, if it starts with {\tt 0} - in base $8$ and in base $10$ otherwise. Note
79that you may not want to specify the base $0$ if you are parsing the numbers
80which may have leading zeroes as they can yield unexpected (to the user not
81familiar with C) results.
a3c1786d 82
0f353563 83
15d83f72 84\membersection{wxTextInputStream::Read8S}\label{wxtextinputstreamread8s}
2348a842
VZ
85
86\func{wxInt8}{Read8S}{\param{int}{ base = 10}}
87
88Reads a single signed byte from the stream.
89
90See \helpref{wxTextInputStream::Read8}{wxtextinputstreamread8} for the
91description of the {\it base} parameter.
a3c1786d 92
0f353563 93
15d83f72 94\membersection{wxTextInputStream::Read16}\label{wxtextinputstreamread16}
a3c1786d 95
2348a842
VZ
96\func{wxUint16}{Read16}{\param{int}{ base = 10}}
97
98Reads a unsigned 16 bit integer from the stream.
a3c1786d 99
2348a842
VZ
100See \helpref{wxTextInputStream::Read8}{wxtextinputstreamread8} for the
101description of the {\it base} parameter.
102
0f353563 103
15d83f72 104\membersection{wxTextInputStream::Read16S}\label{wxtextinputstreamread16s}
2348a842
VZ
105
106\func{wxInt16}{Read16S}{\param{int}{ base = 10}}
107
108Reads a signed 16 bit integer from the stream.
109
110See \helpref{wxTextInputStream::Read8}{wxtextinputstreamread8} for the
111description of the {\it base} parameter.
a3c1786d 112
0f353563 113
15d83f72 114\membersection{wxTextInputStream::Read32}\label{wxtextinputstreamread32}
a3c1786d 115
2348a842
VZ
116\func{wxUint32}{Read32}{\param{int}{ base = 10}}
117
118Reads a 32 bit unsigned integer from the stream.
119
120See \helpref{wxTextInputStream::Read8}{wxtextinputstreamread8} for the
121description of the {\it base} parameter.
122
0f353563 123
15d83f72 124\membersection{wxTextInputStream::Read32S}\label{wxtextinputstreamread32s}
2348a842
VZ
125
126\func{wxInt32}{Read32S}{\param{int}{ base = 10}}
127
128Reads a 32 bit signed integer from the stream.
a3c1786d 129
2348a842
VZ
130See \helpref{wxTextInputStream::Read8}{wxtextinputstreamread8} for the
131description of the {\it base} parameter.
a3c1786d 132
0f353563 133
39a20489 134\membersection{wxTextInputStream::GetChar}\label{wxtextinputstreamgetchar}
bcda793a 135
0f353563 136\func{wxChar}{GetChar}{\void}
bcda793a
VZ
137
138Reads a character, returns $0$ if there are no more characters in the stream.
139
0f353563 140
15d83f72 141\membersection{wxTextInputStream::ReadDouble}\label{wxtextinputstreamreaddouble}
a3c1786d
GL
142
143\func{double}{ReadDouble}{\void}
144
145Reads a double (IEEE encoded) from the stream.
146
0f353563 147
f6bcfd97
BP
148\membersection{wxTextInputStream::ReadLine}\label{wxtextinputstreamreadline}
149
0f353563 150\func{wxString}{ReadLine}{\void}
f6bcfd97
BP
151
152Reads a line from the input stream and returns it (without the end of line
153character).
154
0f353563 155
15d83f72 156\membersection{wxTextInputStream::ReadString}\label{wxtextinputstreamreadstring}
a3c1786d 157
0f353563 158\func{wxString}{ReadString}{\void}
a3c1786d 159
f6bcfd97
BP
160{\bf NB:} This method is deprecated, use \helpref{ReadLine}{wxtextinputstreamreadline}
161or \helpref{ReadWord}{wxtextinputstreamreadword} instead.
162
163Same as \helpref{ReadLine}{wxtextinputstreamreadline}.
164
0f353563 165
f6bcfd97
BP
166\membersection{wxTextInputStream::ReadWord}\label{wxtextinputstreamreadword}
167
0f353563 168\func{wxString}{ReadWord}{\void}
f6bcfd97
BP
169
170Reads a word (a sequence of characters until the next separator) from the
171input stream.
172
173\wxheading{See also}
174
175\helpref{SetStringSeparators}{wxtextinputstreamsetstringseparators}
176
0f353563 177
f6bcfd97
BP
178\membersection{wxTextInputStream::SetStringSeparators}\label{wxtextinputstreamsetstringseparators}
179
180\func{void}{SetStringSeparators}{\param{const wxString\& }{sep}}
181
182Sets the characters which are used to define the word boundaries in
183\helpref{ReadWord}{wxtextinputstreamreadword}.
184
185The default separators are the space and {\tt TAB} characters.
a3c1786d
GL
186
187% ----------------------------------------------------------------------------
188% wxTextOutputStream
189% ----------------------------------------------------------------------------
190
191\section{\class{wxTextOutputStream}}\label{wxtextoutputstream}
192
193This class provides functions that write text datas using an output stream.
28c9c76e 194So, you can write {\it text} floats, integers.
a3c1786d 195
65045edd 196You can also simulate the C++ cout class:
b2cf617c 197
a3c1786d 198\begin{verbatim}
65045edd
RR
199 wxFFileOutputStream output( stderr );
200 wxTextOutputStream cout( output );
a3c1786d 201
65045edd
RR
202 cout << "This is a text line" << endl;
203 cout << 1234;
204 cout << 1.23456;
a3c1786d 205\end{verbatim}
3660fc40 206
7ff14117
RR
207The wxTextOutputStream writes text files (or streams) on DOS, Macintosh
208and Unix in their native formats (concerning the line ending).
209
0e10e38d
VZ
210\wxheading{Include files}
211
212<wx/txtstrm.h>
213
a3c1786d
GL
214\latexignore{\rtfignore{\wxheading{Members}}}
215
0f353563 216
15d83f72 217\membersection{wxTextOutputStream::wxTextOutputStream}\label{wxtextoutputstreamctor}
a3c1786d 218
9a32d27d 219\func{}{wxTextOutputStream}{\param{wxOutputStream\&}{ stream}, \param{wxEOL}{ mode = wxEOL\_NATIVE}, \param{wxMBConv\&}{ conv = wxConvUTF8}}
a3c1786d 220
9a32d27d 221Constructs a text stream object associated to the given output stream.
a3c1786d
GL
222
223\wxheading{Parameters}
224
225\docparam{stream}{The output stream.}
226
b2cf617c 227\docparam{mode}{The end-of-line mode. One of {\bf wxEOL\_NATIVE}, {\bf wxEOL\_DOS}, {\bf wxEOL\_MAC} and {\bf wxEOL\_UNIX}.}
28c9c76e 228
9a32d27d
VZ
229\docparam{conv}{{\it In Unicode build only:} The object used to convert
230Unicode text into ASCII characters written to the output stream.}
231
0f353563 232
15d83f72 233\membersection{wxTextOutputStream::\destruct{wxTextOutputStream}}\label{wxtextoutputstreamdtor}
a3c1786d
GL
234
235\func{}{\destruct{wxTextOutputStream}}{\void}
236
237Destroys the wxTextOutputStream object.
238
0f353563 239
15d83f72 240\membersection{wxTextOutputStream::GetMode}\label{wxtextoutputstreamgetmode}
28c9c76e 241
0f353563 242\func{wxEOL}{GetMode}{\void}
28c9c76e 243
b2cf617c 244Returns the end-of-line mode. One of {\bf wxEOL\_DOS}, {\bf wxEOL\_MAC} and {\bf wxEOL\_UNIX}.
28c9c76e 245
0f353563
VZ
246
247\membersection{wxTextOutputStream::PutChar}\label{wxtextoutputstreamputchar}
248
249\func{void}{PutChar}{{\param wxChar }{c}}
250
251Writes a character to the stream.
252
253
15d83f72 254\membersection{wxTextOutputStream::SetMode}\label{wxtextoutputstreamsetmode}
28c9c76e 255
0f353563 256\func{void}{SetMode}{{\param wxEOL}{ mode = wxEOL\_NATIVE}}
28c9c76e 257
b2cf617c 258Set the end-of-line mode. One of {\bf wxEOL\_NATIVE}, {\bf wxEOL\_DOS}, {\bf wxEOL\_MAC} and {\bf wxEOL\_UNIX}.
28c9c76e 259
0f353563 260
15d83f72 261\membersection{wxTextOutputStream::Write8}\label{wxtextoutputstreamwrite8}
a3c1786d 262
0f353563 263\func{void}{Write8}{{\param wxUint8 }{i8}}
a3c1786d
GL
264
265Writes the single byte {\it i8} to the stream.
266
18591f2f 267
15d83f72 268\membersection{wxTextOutputStream::Write16}\label{wxtextoutputstreamwrite16}
a3c1786d 269
0f353563 270\func{void}{Write16}{{\param wxUint16 }{i16}}
a3c1786d
GL
271
272Writes the 16 bit integer {\it i16} to the stream.
273
0f353563 274
15d83f72 275\membersection{wxTextOutputStream::Write32}\label{wxtextoutputstreamwrite32}
a3c1786d 276
0f353563 277\func{void}{Write32}{{\param wxUint32 }{i32}}
a3c1786d
GL
278
279Writes the 32 bit integer {\it i32} to the stream.
280
0f353563 281
15d83f72 282\membersection{wxTextOutputStream::WriteDouble}\label{wxtextoutputstreamwritedouble}
a3c1786d 283
0f353563 284\func{virtual void}{WriteDouble}{{\param double }{f}}
a3c1786d
GL
285
286Writes the double {\it f} to the stream using the IEEE format.
287
0f353563 288
15d83f72 289\membersection{wxTextOutputStream::WriteString}\label{wxtextoutputstreamwritestring}
a3c1786d 290
0f353563 291\func{virtual void}{WriteString}{{\param const wxString\& }{string}}
a3c1786d 292
75240db2
VZ
293Writes {\it string} as a line. Depending on the end-of-line mode the end of
294line ('$\backslash$n') characters in the string are converted to the correct
295line ending terminator.
296