]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/datstrm.h
c4fc3d272ea4122abf99364e32c5d4f28d664a01
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxDataInputStream and wxDataOutputStream
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxDataOutputStream
12 This class provides functions that write binary data types in a portable
15 Data can be written in either big-endian or little-endian format,
16 little-endian being the default on all architectures but BigEndianOrdered()
17 can be used to change this. The default format for the floating point types
18 is 80 bit "extended precision" unless @c wxUSE_APPLE_IEEE was turned off
19 during the library compilation, in which case extended precision is not
20 available at all. You can call UseBasicPrecisions() to change this and
21 use the standard IEEE 754 32 bit single precision format for floats and
22 standard 64 bit double precision format for doubles. This is recommended
23 for the new code for better interoperability with other software that
24 typically uses standard IEEE 754 formats for its data, the use of extended
25 precision by default is solely due to backwards compatibility.
27 If you want to write data to text files (or streams) use wxTextOutputStream
30 The "<<" operator is overloaded and you can use this class like a standard
31 C++ iostream. See wxDataInputStream for its usage and caveats.
36 @see wxDataInputStream
38 class wxDataOutputStream
42 Constructs a datastream object from an output stream.
43 Only write methods will be available.
45 Note that the @a conv parameter is only available in Unicode builds of wxWidgets.
50 Charset conversion object used to encoding Unicode strings
51 before writing them to the stream in Unicode mode (see
52 WriteString() for a detailed description). Note that you must not
53 destroy @a conv before you destroy this wxDataOutputStream
54 instance! It is recommended to use the default value (UTF-8).
56 wxDataOutputStream(wxOutputStream
& stream
,
57 const wxMBConv
& conv
= wxConvUTF8
);
60 Destroys the wxDataOutputStream object.
62 ~wxDataOutputStream();
65 If @a be_order is @true, all data will be written in big-endian order,
66 e.g. for reading on a Sparc or from Java-Streams (which always use
67 big-endian order), otherwise data will be written in little-endian
70 void BigEndianOrdered(bool be_order
);
73 Returns the current text conversion class used for
76 wxMBConv
*GetConv() const;
79 Sets the text conversion class used for writing strings.
81 void SetConv( const wxMBConv
&conv
);
84 Disables the use of extended precision format for floating point
87 This method disables the use of 80 bit extended precision format for
88 the @c float and @c double values written to the stream, which is used
89 by default (unless @c wxUSE_APPLE_IEEE was set to @c 0 when building
90 the library, in which case the extended format support is not available
91 at all and this function does nothing).
93 After calling it, @c float values will be written out in one of IEEE
94 754 "basic formats", i.e. 32 bit single precision format for floats and
95 64 bit double precision format for doubles.
99 void UseBasicPrecisions();
102 Explicitly request the use of extended precision for floating point
105 This function allows the application code to explicitly request the use
106 of 80 bit extended precision format for the floating point numbers.
107 This is the case by default but using this function explicitly ensures
108 that the compilation of code relying on producing the output stream
109 using extended precision would fail when using a version of wxWidgets
110 compiled with @c wxUSE_APPLE_IEEE==0 and so not supporting this format
115 void UseExtendedPrecision();
118 Writes the single byte @a i8 to the stream.
120 void Write8(wxUint8 i8
);
122 Writes an array of bytes to the stream. The number of bytes to write is
123 specified with the @a size variable.
125 void Write8(const wxUint8
* buffer
, size_t size
);
128 Writes the 16 bit unsigned integer @a i16 to the stream.
130 void Write16(wxUint16 i16
);
132 Writes an array of 16 bit unsigned integer to the stream. The number of
133 16 bit unsigned integer to write is specified with the @a size variable.
135 void Write16(const wxUint16
* buffer
, size_t size
);
138 Writes the 32 bit unsigned integer @a i32 to the stream.
140 void Write32(wxUint32 i32
);
142 Writes an array of 32 bit unsigned integer to the stream. The number of
143 32 bit unsigned integer to write is specified with the @a size variable.
145 void Write32(const wxUint32
* buffer
, size_t size
);
148 Writes the 64 bit unsigned integer @a i64 to the stream.
150 void Write64(wxUint64 i64
);
152 Writes an array of 64 bit unsigned integer to the stream. The number of
153 64 bit unsigned integer to write is specified with the @a size variable.
155 void Write64(const wxUint64
* buffer
, size_t size
);
158 Writes the float @a f to the stream.
160 If UseBasicPrecisions() had been called, the value is written out using
161 the standard IEEE 754 32 bit single precision format. Otherwise, this
162 method uses the same format as WriteDouble(), i.e. 80 bit extended
163 precision representation.
167 void WriteFloat(float f
);
170 Writes an array of float to the stream. The number of floats to write is
171 specified by the @a size variable.
175 void WriteFloat(const float* buffer
, size_t size
);
178 Writes the double @a d to the stream.
180 The output format is either 80 bit extended precision or, if
181 UseBasicPrecisions() had been called, standard IEEE 754 64 bit double
184 void WriteDouble(double d
);
187 Writes an array of double to the stream. The number of doubles to write is
188 specified by the @a size variable.
190 void WriteDouble(const double* buffer
, size_t size
);
193 Writes @a string to the stream. Actually, this method writes the size
194 of the string before writing @a string itself.
196 In ANSI build of wxWidgets, the string is written to the stream in
197 exactly same way it is represented in memory. In Unicode build,
198 however, the string is first converted to multibyte representation with
199 @e conv object passed to stream's constructor (consequently, ANSI
200 applications can read data written by Unicode application, as long as
201 they agree on encoding) and this representation is written to the
202 stream. UTF-8 is used by default.
204 void WriteString(const wxString
& string
);
210 @class wxDataInputStream
212 This class provides functions that read binary data types in a portable
215 Please see wxDataOutputStream for the discussion of the format expected by
216 this stream on input, notably for the floating point values.
218 If you want to read data from text files (or streams) use wxTextInputStream
221 The ">>" operator is overloaded and you can use this class like a standard
222 C++ iostream. Note, however, that the arguments are the fixed size types
223 wxUint32, wxInt32 etc and on a typical 32-bit computer, none of these match
224 to the "long" type (wxInt32 is defined as signed int on 32-bit
225 architectures) so that you cannot use long. To avoid problems (here and
226 elsewhere), make use of the wxInt32, wxUint32, etc types.
231 wxFileInputStream input( "mytext.dat" );
232 wxDataInputStream store( input );
237 store >> i1; // read a 8 bit integer.
238 store >> i1 >> f2; // read a 8 bit integer followed by float.
239 store >> line; // read a text line
245 @see wxDataOutputStream
247 class wxDataInputStream
251 Constructs a datastream object from an input stream.
252 Only read methods will be available.
254 Note that the @a conv parameter is only available in Unicode builds of wxWidgets.
259 Charset conversion object used to decode strings in Unicode
260 mode (see ReadString() for a detailed description). Note that you
261 must not destroy @a conv before you destroy this wxDataInputStream
264 wxDataInputStream(wxInputStream
& stream
,
265 const wxMBConv
& conv
= wxConvUTF8
);
268 Destroys the wxDataInputStream object.
270 ~wxDataInputStream();
273 If @a be_order is @true, all data will be read in big-endian order,
274 such as written by programs on a big endian architecture (e.g. Sparc)
275 or written by Java-Streams (which always use big-endian order).
277 void BigEndianOrdered(bool be_order
);
280 Returns the current text conversion class used for
283 wxMBConv
*GetConv() const;
286 Reads a single byte from the stream.
290 Reads bytes from the stream in a specified buffer. The number of bytes
291 to read is specified by the @a size variable.
293 void Read8(wxUint8
* buffer
, size_t size
);
296 Reads a 16 bit unsigned integer from the stream.
300 Reads 16 bit unsigned integers from the stream in a specified buffer.
301 The number of 16 bit unsigned integers to read is specified by the
304 void Read16(wxUint16
* buffer
, size_t size
);
307 Reads a 32 bit unsigned integer from the stream.
311 Reads 32 bit unsigned integers from the stream in a specified buffer.
312 The number of 32 bit unsigned integers to read is specified by the
315 void Read32(wxUint32
* buffer
, size_t size
);
318 Reads a 64 bit unsigned integer from the stream.
322 Reads 64 bit unsigned integers from the stream in a specified buffer.
323 The number of 64 bit unsigned integers to read is specified by the
326 void Read64(wxUint64
* buffer
, size_t size
);
329 Reads a float from the stream.
331 Notice that if UseBasicPrecisions() hadn't been called, this function
332 simply reads a double and truncates it to float as by default the same
333 (80 bit extended precision) representation is used for both float and
341 Reads float data from the stream in a specified buffer.
343 The number of floats to read is specified by the @a size variable.
347 void ReadFloat(float* buffer
, size_t size
);
350 Reads a double from the stream.
352 The expected format is either 80 bit extended precision or, if
353 UseBasicPrecisions() had been called, standard IEEE 754 64 bit double
359 Reads double data from the stream in a specified buffer.
361 The number of doubles to read is specified by the @a size variable.
363 void ReadDouble(double* buffer
, size_t size
);
366 Reads a string from a stream. Actually, this function first reads a
367 long integer specifying the length of the string (without the last null
368 character) and then reads the string.
370 In Unicode build of wxWidgets, the fuction first reads multibyte
371 (char*) string from the stream and then converts it to Unicode using
372 the @e conv object passed to constructor and returns the result as
373 wxString. You are responsible for using the same converter as when
376 @see wxDataOutputStream::WriteString()
378 wxString
ReadString();
381 Sets the text conversion class used for reading strings.
383 void SetConv( const wxMBConv
&conv
);
386 Disables the use of extended precision format for floating point
389 This method disables the use of 80 bit extended precision format for
390 the @c float and @c double values read from the stream, which is used
391 by default (unless @c wxUSE_APPLE_IEEE was set to @c 0 when building
392 the library, in which case the extended format support is not available
393 at all and this function does nothing).
395 After calling it, @c float values will be expected to appear in one of
396 IEEE 754 "basic formats", i.e. 32 bit single precision format for
397 floats and 64 bit double precision format for doubles in the input.
401 void UseBasicPrecisions();
404 Explicitly request the use of extended precision for floating point
407 This function allows the application code to explicitly request the use
408 of 80 bit extended precision format for the floating point numbers.
409 This is the case by default but using this function explicitly ensures
410 that the compilation of code relying on reading the input containing
411 numbers in extended precision format would fail when using a version of
412 wxWidgets compiled with @c wxUSE_APPLE_IEEE==0 and so not supporting
417 void UseExtendedPrecision();