]> git.saurik.com Git - wxWidgets.git/blame - interface/txtstrm.h
several g++ 4 warning fixes
[wxWidgets.git] / interface / 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
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
e54c96f1 53 @see wxTextInputStream::SetStringSeparators
23324ae1 54*/
7c913512 55class wxTextInputStream
23324ae1
FM
56{
57public:
58 /**
59 )
23324ae1 60 Constructs a text stream associated to the given input stream.
3c4f71cc 61
7c913512 62 @param stream
4cc4bfaf 63 The underlying input stream.
7c913512 64 @param sep
4cc4bfaf 65 The initial string separator characters.
7c913512 66 @param conv
4cc4bfaf
FM
67 In Unicode build only: The encoding converter used to convert the bytes in
68 the
69 underlying input stream to characters.
23324ae1
FM
70 */
71 wxTextInputStream(wxInputStream& stream,
4cc4bfaf 72 const wxString& sep = " \t");
23324ae1
FM
73
74 /**
75 Destroys the wxTextInputStream object.
76 */
77 ~wxTextInputStream();
78
79 /**
80 Reads a character, returns 0 if there are no more characters in the stream.
81 */
82 wxChar GetChar();
83
84 /**
85 Reads a unsigned 16 bit integer from the stream.
23324ae1 86 See wxTextInputStream::Read8 for the
4cc4bfaf 87 description of the @a base parameter.
23324ae1
FM
88 */
89 wxUint16 Read16(int base = 10);
90
91 /**
92 Reads a signed 16 bit integer from the stream.
23324ae1 93 See wxTextInputStream::Read8 for the
4cc4bfaf 94 description of the @a base parameter.
23324ae1
FM
95 */
96 wxInt16 Read16S(int base = 10);
97
98 /**
99 Reads a 32 bit unsigned integer from the stream.
23324ae1 100 See wxTextInputStream::Read8 for the
4cc4bfaf 101 description of the @a base parameter.
23324ae1
FM
102 */
103 wxUint32 Read32(int base = 10);
104
105 /**
106 Reads a 32 bit signed integer from the stream.
23324ae1 107 See wxTextInputStream::Read8 for the
4cc4bfaf 108 description of the @a base parameter.
23324ae1
FM
109 */
110 wxInt32 Read32S(int base = 10);
111
112 /**
113 Reads a single unsigned byte from the stream, given in base @e base.
4cc4bfaf 114 The value of @a base must be comprised between 2 and 36, inclusive, or
23324ae1
FM
115 be a special value 0 which means that the usual rules of @c C numbers are
116 applied: if the number starts with @c 0x it is considered to be in base
117 16, if it starts with @c 0 - in base 8 and in base 10 otherwise. Note
118 that 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 not
120 familiar with C) results.
121 */
122 wxUint8 Read8(int base = 10);
123
124 /**
125 Reads a single signed byte from the stream.
23324ae1 126 See wxTextInputStream::Read8 for the
4cc4bfaf 127 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 /**
137 Reads a line from the input stream and returns it (without the end of line
138 character).
139 */
140 wxString ReadLine();
141
142 /**
7c913512 143 @b NB: This method is deprecated, use ReadLine()
23324ae1 144 or ReadWord() instead.
23324ae1
FM
145 Same as ReadLine().
146 */
147 wxString ReadString();
148
149 /**
150 Reads a word (a sequence of characters until the next separator) from the
151 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().
23324ae1
FM
160 The default separators are the space and @c TAB characters.
161 */
162 void SetStringSeparators(const wxString& sep);
163};
164
165
e54c96f1 166
23324ae1
FM
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 196 Constructs a text stream object associated to the given output stream.
3c4f71cc 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};
e54c96f1 259