Version: 3.1.0
wxDataInputStream Class Reference

#include <wx/datstrm.h>

Detailed Description

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:

wxFileInputStream input( "mytext.dat" );
wxDataInputStream store( input );
float f2;
wxString line;
store >> i1; // read a 8 bit integer.
store >> i1 >> f2; // read a 8 bit integer followed by float.
store >> line; // read a text line

Library:  wxBase
Category:  Streams
See Also
wxDataOutputStream

Public Member Functions

 wxDataInputStream (wxInputStream &stream, const wxMBConv &conv=wxConvUTF8)
 Constructs a datastream object from an input stream.
 
 ~wxDataInputStream ()
 Destroys the wxDataInputStream object.
 
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.
 
wxMBConvGetConv () const
 Returns the current text conversion class used for reading strings.
 
wxUint8 Read8 ()
 Reads a single byte from the stream.
 
void Read8 (wxUint8 *buffer, size_t size)
 Reads bytes from the stream in a specified buffer.
 
wxUint16 Read16 ()
 Reads a 16 bit unsigned integer from the stream.
 
void Read16 (wxUint16 *buffer, size_t size)
 Reads 16 bit unsigned integers from the stream in a specified buffer.
 
wxUint32 Read32 ()
 Reads a 32 bit unsigned integer from the stream.
 
void Read32 (wxUint32 *buffer, size_t size)
 Reads 32 bit unsigned integers from the stream in a specified buffer.
 
wxUint64 Read64 ()
 Reads a 64 bit unsigned integer from the stream.
 
void Read64 (wxUint64 *buffer, size_t size)
 Reads 64 bit unsigned integers from the stream in a specified buffer.
 
float ReadFloat ()
 Reads a float from the stream.
 
void ReadFloat (float *buffer, size_t size)
 Reads float data from the stream in a specified buffer.
 
double ReadDouble ()
 Reads a double from the stream.
 
void ReadDouble (double *buffer, size_t size)
 Reads double data from the stream in a specified buffer.
 
wxString ReadString ()
 Reads a string from a stream.
 
void SetConv (const wxMBConv &conv)
 Sets the text conversion class used for reading strings.
 
void UseBasicPrecisions ()
 Disables the use of extended precision format for floating point numbers.
 
void UseExtendedPrecision ()
 Explicitly request the use of extended precision for floating point numbers.
 

Constructor & Destructor Documentation

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.

Parameters
streamThe input stream.
convCharset 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.

Member Function Documentation

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.

Since
2.9.5
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.

Since
2.9.5
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.

See Also
wxDataOutputStream::WriteString()
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.

Since
2.9.5
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.

Since
2.9.5