]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/datstrm.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxDataInputStream and wxDataOutputStream
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 @class wxDataOutputStream
11 This class provides functions that write binary data types in a portable
14 Data can be written in either big-endian or little-endian format,
15 little-endian being the default on all architectures but BigEndianOrdered()
16 can be used to change this. The default format for the floating point types
17 is 80 bit "extended precision" unless @c wxUSE_APPLE_IEEE was turned off
18 during the library compilation, in which case extended precision is not
19 available at all. You can call UseBasicPrecisions() to change this and
20 use the standard IEEE 754 32 bit single precision format for floats and
21 standard 64 bit double precision format for doubles. This is recommended
22 for the new code for better interoperability with other software that
23 typically uses standard IEEE 754 formats for its data, the use of extended
24 precision by default is solely due to backwards compatibility.
26 If you want to write data to text files (or streams) use wxTextOutputStream
29 The "<<" operator is overloaded and you can use this class like a standard
30 C++ iostream. See wxDataInputStream for its usage and caveats.
35 @see wxDataInputStream
37 class wxDataOutputStream
41 Constructs a datastream object from an output stream.
42 Only write methods will be available.
44 Note that the @a conv parameter is only available in Unicode builds of wxWidgets.
49 Charset conversion object used to encoding Unicode strings
50 before writing them to the stream in Unicode mode (see
51 WriteString() for a detailed description). Note that you must not
52 destroy @a conv before you destroy this wxDataOutputStream
53 instance! It is recommended to use the default value (UTF-8).
55 wxDataOutputStream(wxOutputStream
& stream
,
56 const wxMBConv
& conv
= wxConvUTF8
);
59 Destroys the wxDataOutputStream object.
61 ~wxDataOutputStream();
64 If @a be_order is @true, all data will be written in big-endian order,
65 e.g. for reading on a Sparc or from Java-Streams (which always use
66 big-endian order), otherwise data will be written in little-endian
69 void BigEndianOrdered(bool be_order
);
72 Returns the current text conversion class used for
75 wxMBConv
*GetConv() const;
78 Sets the text conversion class used for writing strings.
80 void SetConv( const wxMBConv
&conv
);
83 Disables the use of extended precision format for floating point
86 This method disables the use of 80 bit extended precision format for
87 the @c float and @c double values written to the stream, which is used
88 by default (unless @c wxUSE_APPLE_IEEE was set to @c 0 when building
89 the library, in which case the extended format support is not available
90 at all and this function does nothing).
92 After calling it, @c float values will be written out in one of IEEE
93 754 "basic formats", i.e. 32 bit single precision format for floats and
94 64 bit double precision format for doubles.
98 void UseBasicPrecisions();
101 Explicitly request the use of extended precision for floating point
104 This function allows the application code to explicitly request the use
105 of 80 bit extended precision format for the floating point numbers.
106 This is the case by default but using this function explicitly ensures
107 that the compilation of code relying on producing the output stream
108 using extended precision would fail when using a version of wxWidgets
109 compiled with @c wxUSE_APPLE_IEEE==0 and so not supporting this format
114 void UseExtendedPrecision();
117 Writes the single byte @a i8 to the stream.
119 void Write8(wxUint8 i8
);
121 Writes an array of bytes to the stream. The number of bytes to write is
122 specified with the @a size variable.
124 void Write8(const wxUint8
* buffer
, size_t size
);
127 Writes the 16 bit unsigned integer @a i16 to the stream.
129 void Write16(wxUint16 i16
);
131 Writes an array of 16 bit unsigned integer to the stream. The number of
132 16 bit unsigned integer to write is specified with the @a size variable.
134 void Write16(const wxUint16
* buffer
, size_t size
);
137 Writes the 32 bit unsigned integer @a i32 to the stream.
139 void Write32(wxUint32 i32
);
141 Writes an array of 32 bit unsigned integer to the stream. The number of
142 32 bit unsigned integer to write is specified with the @a size variable.
144 void Write32(const wxUint32
* buffer
, size_t size
);
147 Writes the 64 bit unsigned integer @a i64 to the stream.
149 void Write64(wxUint64 i64
);
151 Writes an array of 64 bit unsigned integer to the stream. The number of
152 64 bit unsigned integer to write is specified with the @a size variable.
154 void Write64(const wxUint64
* buffer
, size_t size
);
157 Writes the float @a f to the stream.
159 If UseBasicPrecisions() had been called, the value is written out using
160 the standard IEEE 754 32 bit single precision format. Otherwise, this
161 method uses the same format as WriteDouble(), i.e. 80 bit extended
162 precision representation.
166 void WriteFloat(float f
);
169 Writes an array of float to the stream. The number of floats to write is
170 specified by the @a size variable.
174 void WriteFloat(const float* buffer
, size_t size
);
177 Writes the double @a d to the stream.
179 The output format is either 80 bit extended precision or, if
180 UseBasicPrecisions() had been called, standard IEEE 754 64 bit double
183 void WriteDouble(double d
);
186 Writes an array of double to the stream. The number of doubles to write is
187 specified by the @a size variable.
189 void WriteDouble(const double* buffer
, size_t size
);
192 Writes @a string to the stream. Actually, this method writes the size
193 of the string before writing @a string itself.
195 In ANSI build of wxWidgets, the string is written to the stream in
196 exactly same way it is represented in memory. In Unicode build,
197 however, the string is first converted to multibyte representation with
198 @e conv object passed to stream's constructor (consequently, ANSI
199 applications can read data written by Unicode application, as long as
200 they agree on encoding) and this representation is written to the
201 stream. UTF-8 is used by default.
203 void WriteString(const wxString
& string
);
209 @class wxDataInputStream
211 This class provides functions that read binary data types in a portable
214 Please see wxDataOutputStream for the discussion of the format expected by
215 this stream on input, notably for the floating point values.
217 If you want to read data from text files (or streams) use wxTextInputStream
220 The ">>" operator is overloaded and you can use this class like a standard
221 C++ iostream. Note, however, that the arguments are the fixed size types
222 wxUint32, wxInt32 etc and on a typical 32-bit computer, none of these match
223 to the "long" type (wxInt32 is defined as signed int on 32-bit
224 architectures) so that you cannot use long. To avoid problems (here and
225 elsewhere), make use of the wxInt32, wxUint32, etc types.
230 wxFileInputStream input( "mytext.dat" );
231 wxDataInputStream store( input );
236 store >> i1; // read a 8 bit integer.
237 store >> i1 >> f2; // read a 8 bit integer followed by float.
238 store >> line; // read a text line
244 @see wxDataOutputStream
246 class wxDataInputStream
250 Constructs a datastream object from an input stream.
251 Only read methods will be available.
253 Note that the @a conv parameter is only available in Unicode builds of wxWidgets.
258 Charset conversion object used to decode strings in Unicode
259 mode (see ReadString() for a detailed description). Note that you
260 must not destroy @a conv before you destroy this wxDataInputStream
263 wxDataInputStream(wxInputStream
& stream
,
264 const wxMBConv
& conv
= wxConvUTF8
);
267 Destroys the wxDataInputStream object.
269 ~wxDataInputStream();
272 If @a be_order is @true, all data will be read in big-endian order,
273 such as written by programs on a big endian architecture (e.g. Sparc)
274 or written by Java-Streams (which always use big-endian order).
276 void BigEndianOrdered(bool be_order
);
279 Returns the current text conversion class used for
282 wxMBConv
*GetConv() const;
285 Reads a single byte from the stream.
289 Reads bytes from the stream in a specified buffer. The number of bytes
290 to read is specified by the @a size variable.
292 void Read8(wxUint8
* buffer
, size_t size
);
295 Reads a 16 bit unsigned integer from the stream.
299 Reads 16 bit unsigned integers from the stream in a specified buffer.
300 The number of 16 bit unsigned integers to read is specified by the
303 void Read16(wxUint16
* buffer
, size_t size
);
306 Reads a 32 bit unsigned integer from the stream.
310 Reads 32 bit unsigned integers from the stream in a specified buffer.
311 The number of 32 bit unsigned integers to read is specified by the
314 void Read32(wxUint32
* buffer
, size_t size
);
317 Reads a 64 bit unsigned integer from the stream.
321 Reads 64 bit unsigned integers from the stream in a specified buffer.
322 The number of 64 bit unsigned integers to read is specified by the
325 void Read64(wxUint64
* buffer
, size_t size
);
328 Reads a float from the stream.
330 Notice that if UseBasicPrecisions() hadn't been called, this function
331 simply reads a double and truncates it to float as by default the same
332 (80 bit extended precision) representation is used for both float and
340 Reads float data from the stream in a specified buffer.
342 The number of floats to read is specified by the @a size variable.
346 void ReadFloat(float* buffer
, size_t size
);
349 Reads a double from the stream.
351 The expected format is either 80 bit extended precision or, if
352 UseBasicPrecisions() had been called, standard IEEE 754 64 bit double
358 Reads double data from the stream in a specified buffer.
360 The number of doubles to read is specified by the @a size variable.
362 void ReadDouble(double* buffer
, size_t size
);
365 Reads a string from a stream. Actually, this function first reads a
366 long integer specifying the length of the string (without the last null
367 character) and then reads the string.
369 In Unicode build of wxWidgets, the fuction first reads multibyte
370 (char*) string from the stream and then converts it to Unicode using
371 the @e conv object passed to constructor and returns the result as
372 wxString. You are responsible for using the same converter as when
375 @see wxDataOutputStream::WriteString()
377 wxString
ReadString();
380 Sets the text conversion class used for reading strings.
382 void SetConv( const wxMBConv
&conv
);
385 Disables the use of extended precision format for floating point
388 This method disables the use of 80 bit extended precision format for
389 the @c float and @c double values read from the stream, which is used
390 by default (unless @c wxUSE_APPLE_IEEE was set to @c 0 when building
391 the library, in which case the extended format support is not available
392 at all and this function does nothing).
394 After calling it, @c float values will be expected to appear in one of
395 IEEE 754 "basic formats", i.e. 32 bit single precision format for
396 floats and 64 bit double precision format for doubles in the input.
400 void UseBasicPrecisions();
403 Explicitly request the use of extended precision for floating point
406 This function allows the application code to explicitly request the use
407 of 80 bit extended precision format for the floating point numbers.
408 This is the case by default but using this function explicitly ensures
409 that the compilation of code relying on reading the input containing
410 numbers in extended precision format would fail when using a version of
411 wxWidgets compiled with @c wxUSE_APPLE_IEEE==0 and so not supporting
416 void UseExtendedPrecision();