]>
git.saurik.com Git - wxWidgets.git/blob - interface/txtstrm.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTextInputStream
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
53 @see wxTextInputStream::SetStringSeparators
55 class wxTextInputStream
60 Constructs a text stream associated to the given input stream.
63 The underlying input stream.
65 The initial string separator characters.
67 In Unicode build only: The encoding converter used to convert the bytes in
69 underlying input stream to characters.
71 wxTextInputStream(wxInputStream
& stream
,
72 const wxString
& sep
= " \t");
75 Destroys the wxTextInputStream object.
80 Reads a character, returns 0 if there are no more characters in the stream.
85 Reads a unsigned 16 bit integer from the stream.
86 See wxTextInputStream::Read8 for the
87 description of the @a base parameter.
89 wxUint16
Read16(int base
= 10);
92 Reads a signed 16 bit integer from the stream.
93 See wxTextInputStream::Read8 for the
94 description of the @a base parameter.
96 wxInt16
Read16S(int base
= 10);
99 Reads a 32 bit unsigned integer from the stream.
100 See wxTextInputStream::Read8 for the
101 description of the @a base parameter.
103 wxUint32
Read32(int base
= 10);
106 Reads a 32 bit signed integer from the stream.
107 See wxTextInputStream::Read8 for the
108 description of the @a base parameter.
110 wxInt32
Read32S(int base
= 10);
113 Reads a single unsigned byte from the stream, given in base @e base.
114 The value of @a base must be comprised between 2 and 36, inclusive, or
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.
122 wxUint8
Read8(int base
= 10);
125 Reads a single signed byte from the stream.
126 See wxTextInputStream::Read8 for the
127 description of the @a base parameter.
129 wxInt8
Read8S(int base
= 10);
132 Reads a double (IEEE encoded) from the stream.
137 Reads a line from the input stream and returns it (without the end of line
143 @note This method is deprecated, use ReadLine()
144 or ReadWord() instead.
147 wxString
ReadString();
150 Reads a word (a sequence of characters until the next separator) from the
153 @see SetStringSeparators()
158 Sets the characters which are used to define the word boundaries in
160 The default separators are the space and @c TAB characters.
162 void SetStringSeparators(const wxString
& sep
);
168 @class wxTextOutputStream
171 This class provides functions that write text datas using an output stream.
172 So, you can write @e text floats, integers.
174 You can also simulate the C++ cout class:
177 wxFFileOutputStream output( stderr );
178 wxTextOutputStream cout( output );
180 cout "This is a text line" endl;
185 The wxTextOutputStream writes text files (or streams) on DOS, Macintosh
186 and Unix in their native formats (concerning the line ending).
191 class wxTextOutputStream
196 Constructs a text stream object associated to the given output stream.
201 The end-of-line mode. One of wxEOL_NATIVE, wxEOL_DOS, wxEOL_MAC and
204 In Unicode build only: The object used to convert
205 Unicode text into ASCII characters written to the output stream.
207 wxTextOutputStream(wxOutputStream
& stream
,
208 wxEOL mode
= wxEOL_NATIVE
);
211 Destroys the wxTextOutputStream object.
213 ~wxTextOutputStream();
216 Returns the end-of-line mode. One of @b wxEOL_DOS, @b wxEOL_MAC and @b
222 Writes a character to the stream.
224 void PutChar(wxChar c
);
227 Set the end-of-line mode. One of @b wxEOL_NATIVE, @b wxEOL_DOS, @b wxEOL_MAC
230 void SetMode(wxEOL mode
= wxEOL_NATIVE
);
233 Writes the 16 bit integer @a i16 to the stream.
235 void Write16(wxUint16 i16
);
238 Writes the 32 bit integer @a i32 to the stream.
240 void Write32(wxUint32 i32
);
243 Writes the single byte @a i8 to the stream.
245 void Write8(wxUint8 i8
);
248 Writes the double @a f to the stream using the IEEE format.
250 virtual void WriteDouble(double f
);
253 Writes @a string as a line. Depending on the end-of-line mode the end of
254 line ('\n') characters in the string are converted to the correct
255 line ending terminator.
257 virtual void WriteString(const wxString
& string
);