#include <wx/datstrm.h>
This class provides functions that read binary data types in a portable way.
Please see wxDataOutputStream for the discussion of the format expected by this stream on input, notably for the floating point values.
If you want to read data from text files (or streams) use wxTextInputStream instead.
The ">>" operator is overloaded and you can use this class like a standard C++ iostream. Note, however, that the arguments are the fixed size types wxUint32, wxInt32 etc and on a typical 32-bit computer, none of these match to the "long" type (wxInt32 is defined as signed int on 32-bit architectures) so that you cannot use long. To avoid problems (here and elsewhere), make use of the wxInt32, wxUint32, etc types.
For example:
Public Member Functions | |
wxDataInputStream (wxInputStream &stream, const wxMBConv &conv=wxConvUTF8) | |
Constructs a datastream object from an input stream. More... | |
~wxDataInputStream () | |
Destroys the wxDataInputStream object. More... | |
void | BigEndianOrdered (bool be_order) |
If be_order is true, all data will be read in big-endian order, such as written by programs on a big endian architecture (e.g. More... | |
wxMBConv * | GetConv () const |
Returns the current text conversion class used for reading strings. More... | |
wxUint8 | Read8 () |
Reads a single byte from the stream. More... | |
void | Read8 (wxUint8 *buffer, size_t size) |
Reads bytes from the stream in a specified buffer. More... | |
wxUint16 | Read16 () |
Reads a 16 bit unsigned integer from the stream. More... | |
void | Read16 (wxUint16 *buffer, size_t size) |
Reads 16 bit unsigned integers from the stream in a specified buffer. More... | |
wxUint32 | Read32 () |
Reads a 32 bit unsigned integer from the stream. More... | |
void | Read32 (wxUint32 *buffer, size_t size) |
Reads 32 bit unsigned integers from the stream in a specified buffer. More... | |
wxUint64 | Read64 () |
Reads a 64 bit unsigned integer from the stream. More... | |
void | Read64 (wxUint64 *buffer, size_t size) |
Reads 64 bit unsigned integers from the stream in a specified buffer. More... | |
float | ReadFloat () |
Reads a float from the stream. More... | |
void | ReadFloat (float *buffer, size_t size) |
Reads float data from the stream in a specified buffer. More... | |
double | ReadDouble () |
Reads a double from the stream. More... | |
void | ReadDouble (double *buffer, size_t size) |
Reads double data from the stream in a specified buffer. More... | |
wxString | ReadString () |
Reads a string from a stream. More... | |
void | SetConv (const wxMBConv &conv) |
Sets the text conversion class used for reading strings. More... | |
void | UseBasicPrecisions () |
Disables the use of extended precision format for floating point numbers. More... | |
void | UseExtendedPrecision () |
Explicitly request the use of extended precision for floating point numbers. More... | |
wxDataInputStream::wxDataInputStream | ( | wxInputStream & | stream, |
const wxMBConv & | conv = wxConvUTF8 |
||
) |
Constructs a datastream object from an input stream.
Only read methods will be available.
Note that the conv parameter is only available in Unicode builds of wxWidgets.
stream | The input stream. |
conv | Charset conversion object used to decode strings in Unicode mode (see ReadString() for a detailed description). Note that you must not destroy conv before you destroy this wxDataInputStream instance! |
wxDataInputStream::~wxDataInputStream | ( | ) |
Destroys the wxDataInputStream object.
void wxDataInputStream::BigEndianOrdered | ( | bool | be_order | ) |
If be_order is true, all data will be read in big-endian order, such as written by programs on a big endian architecture (e.g.
Sparc) or written by Java-Streams (which always use big-endian order).
wxMBConv* wxDataInputStream::GetConv | ( | ) | const |
Returns the current text conversion class used for reading strings.
wxUint16 wxDataInputStream::Read16 | ( | ) |
Reads a 16 bit unsigned integer from the stream.
void wxDataInputStream::Read16 | ( | wxUint16 * | buffer, |
size_t | size | ||
) |
Reads 16 bit unsigned integers from the stream in a specified buffer.
The number of 16 bit unsigned integers to read is specified by the size variable.
wxUint32 wxDataInputStream::Read32 | ( | ) |
Reads a 32 bit unsigned integer from the stream.
void wxDataInputStream::Read32 | ( | wxUint32 * | buffer, |
size_t | size | ||
) |
Reads 32 bit unsigned integers from the stream in a specified buffer.
The number of 32 bit unsigned integers to read is specified by the size variable.
wxUint64 wxDataInputStream::Read64 | ( | ) |
Reads a 64 bit unsigned integer from the stream.
void wxDataInputStream::Read64 | ( | wxUint64 * | buffer, |
size_t | size | ||
) |
Reads 64 bit unsigned integers from the stream in a specified buffer.
The number of 64 bit unsigned integers to read is specified by the size variable.
wxUint8 wxDataInputStream::Read8 | ( | ) |
Reads a single byte from the stream.
void wxDataInputStream::Read8 | ( | wxUint8 * | buffer, |
size_t | size | ||
) |
Reads bytes from the stream in a specified buffer.
The number of bytes to read is specified by the size variable.
double wxDataInputStream::ReadDouble | ( | ) |
Reads a double from the stream.
The expected format is either 80 bit extended precision or, if UseBasicPrecisions() had been called, standard IEEE 754 64 bit double precision.
void wxDataInputStream::ReadDouble | ( | double * | buffer, |
size_t | size | ||
) |
Reads double data from the stream in a specified buffer.
The number of doubles to read is specified by the size variable.
float wxDataInputStream::ReadFloat | ( | ) |
Reads a float from the stream.
Notice that if UseBasicPrecisions() hadn't been called, this function simply reads a double and truncates it to float as by default the same (80 bit extended precision) representation is used for both float and double values.
void wxDataInputStream::ReadFloat | ( | float * | buffer, |
size_t | size | ||
) |
Reads float data from the stream in a specified buffer.
The number of floats to read is specified by the size variable.
wxString wxDataInputStream::ReadString | ( | ) |
Reads a string from a stream.
Actually, this function first reads a long integer specifying the length of the string (without the last null character) and then reads the string.
In Unicode build of wxWidgets, the function first reads multibyte (char*) string from the stream and then converts it to Unicode using the conv object passed to constructor and returns the result as wxString. You are responsible for using the same converter as when writing the stream.
void wxDataInputStream::SetConv | ( | const wxMBConv & | conv | ) |
Sets the text conversion class used for reading strings.
void wxDataInputStream::UseBasicPrecisions | ( | ) |
Disables the use of extended precision format for floating point numbers.
This method disables the use of 80 bit extended precision format for the float
and double
values read from the stream, which is used by default (unless wxUSE_APPLE_IEEE
was set to 0
when building the library, in which case the extended format support is not available at all and this function does nothing).
After calling it, float
values will be expected to appear in one of IEEE 754 "basic formats", i.e. 32 bit single precision format for floats and 64 bit double precision format for doubles in the input.
void wxDataInputStream::UseExtendedPrecision | ( | ) |
Explicitly request the use of extended precision for floating point numbers.
This function allows the application code to explicitly request the use of 80 bit extended precision format for the floating point numbers. This is the case by default but using this function explicitly ensures that the compilation of code relying on reading the input containing numbers in extended precision format would fail when using a version of wxWidgets compiled with wxUSE_APPLE_IEEE==0
and so not supporting this format at all.