]>
git.saurik.com Git - wxWidgets.git/blob - interface/txtstrm.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxTextInputStream class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxTextInputStream
13 This class provides functions that read text datas using an input stream.
14 So, you can read @e text floats, integers.
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.
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
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.
26 If you're scanning through a file using wxTextInputStream, you should check for
28 reading the next item (word / number), because otherwise the last item may get
30 You should however be prepared to receive an empty item (empty string / zero
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).
39 wxFileInputStream input( "mytext.txt" );
40 wxTextInputStream text( input );
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
54 wxTextInputStream::SetStringSeparators
56 class wxTextInputStream
62 Constructs a text stream associated to the given input stream.
65 The underlying input stream.
68 The initial string separator characters.
71 In Unicode build only: The encoding converter used to convert the bytes in the
72 underlying input stream to characters.
74 wxTextInputStream(wxInputStream
& stream
,
75 const wxString
& sep
=" \t");
78 Destroys the wxTextInputStream object.
83 Reads a character, returns 0 if there are no more characters in the stream.
88 Reads a unsigned 16 bit integer from the stream.
90 See wxTextInputStream::Read8 for the
91 description of the @e base parameter.
93 wxUint16
Read16(int base
= 10);
96 Reads a signed 16 bit integer from the stream.
98 See wxTextInputStream::Read8 for the
99 description of the @e base parameter.
101 wxInt16
Read16S(int base
= 10);
104 Reads a 32 bit unsigned integer from the stream.
106 See wxTextInputStream::Read8 for the
107 description of the @e base parameter.
109 wxUint32
Read32(int base
= 10);
112 Reads a 32 bit signed integer from the stream.
114 See wxTextInputStream::Read8 for the
115 description of the @e base parameter.
117 wxInt32
Read32S(int base
= 10);
120 Reads a single unsigned byte from the stream, given in base @e base.
122 The value of @e base must be comprised between 2 and 36, inclusive, or
123 be a special value 0 which means that the usual rules of @c C numbers are
124 applied: if the number starts with @c 0x it is considered to be in base
125 16, if it starts with @c 0 - in base 8 and in base 10 otherwise. Note
126 that you may not want to specify the base 0 if you are parsing the numbers
127 which may have leading zeroes as they can yield unexpected (to the user not
128 familiar with C) results.
130 wxUint8
Read8(int base
= 10);
133 Reads a single signed byte from the stream.
135 See wxTextInputStream::Read8 for the
136 description of the @e base parameter.
138 wxInt8
Read8S(int base
= 10);
141 Reads a double (IEEE encoded) from the stream.
146 Reads a line from the input stream and returns it (without the end of line
152 @b NB: This method is deprecated, use ReadLine()
153 or ReadWord() instead.
157 wxString
ReadString();
160 Reads a word (a sequence of characters until the next separator) from the
163 @sa SetStringSeparators()
168 Sets the characters which are used to define the word boundaries in
171 The default separators are the space and @c TAB characters.
173 void SetStringSeparators(const wxString
& sep
);
178 @class wxTextOutputStream
181 This class provides functions that write text datas using an output stream.
182 So, you can write @e text floats, integers.
184 You can also simulate the C++ cout class:
187 wxFFileOutputStream output( stderr );
188 wxTextOutputStream cout( output );
190 cout "This is a text line" endl;
195 The wxTextOutputStream writes text files (or streams) on DOS, Macintosh
196 and Unix in their native formats (concerning the line ending).
201 class wxTextOutputStream
207 Constructs a text stream object associated to the given output stream.
213 The end-of-line mode. One of wxEOL_NATIVE, wxEOL_DOS, wxEOL_MAC and wxEOL_UNIX.
216 In Unicode build only: The object used to convert
217 Unicode text into ASCII characters written to the output stream.
219 wxTextOutputStream(wxOutputStream
& stream
,
220 wxEOL mode
= wxEOL_NATIVE
);
223 Destroys the wxTextOutputStream object.
225 ~wxTextOutputStream();
228 Returns the end-of-line mode. One of @b wxEOL_DOS, @b wxEOL_MAC and @b
234 Writes a character to the stream.
236 void PutChar(wxChar c
);
239 Set the end-of-line mode. One of @b wxEOL_NATIVE, @b wxEOL_DOS, @b wxEOL_MAC
242 void SetMode(wxEOL mode
= wxEOL_NATIVE
);
245 Writes the 16 bit integer @e i16 to the stream.
247 void Write16(wxUint16 i16
);
250 Writes the 32 bit integer @e i32 to the stream.
252 void Write32(wxUint32 i32
);
255 Writes the single byte @e i8 to the stream.
257 void Write8(wxUint8 i8
);
260 Writes the double @e f to the stream using the IEEE format.
262 virtual void WriteDouble(double f
);
265 Writes @e string as a line. Depending on the end-of-line mode the end of
266 line ('\n') characters in the string are converted to the correct
267 line ending terminator.
269 virtual void WriteString(const wxString
& string
);