Blame qtools/qdatastream.cpp

Packit Service 50c9f2
/****************************************************************************
Packit Service 50c9f2
** 
Packit Service 50c9f2
**
Packit Service 50c9f2
** Implementation of QDataStream class
Packit Service 50c9f2
**
Packit Service 50c9f2
** Created : 930831
Packit Service 50c9f2
**
Packit Service 50c9f2
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is part of the tools module of the Qt GUI Toolkit.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed under the terms of the Q Public License
Packit Service 50c9f2
** as defined by Trolltech AS of Norway and appearing in the file
Packit Service 50c9f2
** LICENSE.QPL included in the packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed and/or modified under the terms of the
Packit Service 50c9f2
** GNU General Public License version 2 as published by the Free Software
Packit Service 50c9f2
** Foundation and appearing in the file LICENSE.GPL included in the
Packit Service 50c9f2
** packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit Service 50c9f2
** licenses may use this file in accordance with the Qt Commercial License
Packit Service 50c9f2
** Agreement provided with the Software.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit Service 50c9f2
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 50c9f2
**
Packit Service 50c9f2
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit Service 50c9f2
**   information about Qt Commercial License Agreements.
Packit Service 50c9f2
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit Service 50c9f2
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Contact info@trolltech.com if any conditions of this licensing are
Packit Service 50c9f2
** not clear to you.
Packit Service 50c9f2
**
Packit Service 50c9f2
**********************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
#include "qdatastream.h"
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QT_NO_DATASTREAM
Packit Service 50c9f2
#include "qbuffer.h"
Packit Service 50c9f2
#include <stdio.h>
Packit Service 50c9f2
#include <ctype.h>
Packit Service 50c9f2
#include <stdlib.h>
Packit Service 50c9f2
Packit Service 50c9f2
// REVISED: warwick
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \class QDataStream qdatastream.h
Packit Service 50c9f2
Packit Service 50c9f2
  \brief The QDataStream class provides serialization of
Packit Service 50c9f2
  binary data to a QIODevice.
Packit Service 50c9f2
Packit Service 50c9f2
  \ingroup io
Packit Service 50c9f2
Packit Service 50c9f2
  A data stream is a binary stream of encoded information which is 100%
Packit Service 50c9f2
  independent of the host computer operation system, CPU or byte order.	 A
Packit Service 50c9f2
  stream that is written by a PC under DOS/Windows can be read by a
Packit Service 50c9f2
  Sun SPARC running Solaris.
Packit Service 50c9f2
Packit Service 50c9f2
  The QDataStream class implements serialization of primitive types, like
Packit Service 50c9f2
  \c char, \c short, \c int, \c char* etc.  Serialization of more complex
Packit Service 50c9f2
  data is accomplished by breaking up the data into primitive units.
Packit Service 50c9f2
Packit Service 50c9f2
  The programmer can select which byte order to use when serializing data.
Packit Service 50c9f2
  The default setting is big endian (MSB first). Changing it to little
Packit Service 50c9f2
  endian breaks the portability (unless the reader also changes to little
Packit Service 50c9f2
  endian).  We recommend keeping this setting unless you have
Packit Service 50c9f2
  special requirements.
Packit Service 50c9f2
Packit Service 50c9f2
  A data stream cooperates closely with a QIODevice. A QIODevice
Packit Service 50c9f2
  represents an input/output medium one can read data from and write data
Packit Service 50c9f2
  to.  The QFile class is an example of an IO device.
Packit Service 50c9f2
Packit Service 50c9f2
  Example (write data to a stream):
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QFile f( "file.dta" );
Packit Service 50c9f2
    f.open( IO_WriteOnly );			// open file for writing
Packit Service 50c9f2
    QDataStream s( &f );			// serialize using f
Packit Service 50c9f2
    s << "the answer is";			// serialize string
Packit Service 50c9f2
    s << (Q_INT32)42;				// serialize integer
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  Example (read data from a stream):
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QFile f( "file.dta" );
Packit Service 50c9f2
    f.open( IO_ReadOnly );			// open file for reading
Packit Service 50c9f2
    QDataStream s( &f );			// serialize using f
Packit Service 50c9f2
    char   *str;
Packit Service 50c9f2
    Q_INT32 a;
Packit Service 50c9f2
    s >> str >> a;				// "the answer is" and 42
Packit Service 50c9f2
    delete str;					// delete string
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  In the last example, if you read into a QString instead of a \c char*
Packit Service 50c9f2
  you do not have to delete it.
Packit Service 50c9f2
Packit Service 50c9f2
  Normally, each item written to the stream is written in a fixed binary
Packit Service 50c9f2
  format.
Packit Service 50c9f2
  For example, a \c char* is written as a 32-bit integer equal to the
Packit Service 50c9f2
  length of the string including the NUL byte, followed by all the
Packit Service 50c9f2
  characters of the string including the NUL byte. Similarly when
Packit Service 50c9f2
  reading a string, 4 bytes are read to create the 32-bit length value,
Packit Service 50c9f2
  then that many characters for the string including the NUL. For a complete
Packit Service 50c9f2
  description of all Qt types supporting data streaming see \link
Packit Service 50c9f2
  datastreamformat.html Format of the QDataStream operators \endlink .
Packit Service 50c9f2
Packit Service 50c9f2
  If you want a "parsing" input stream, see QTextStream. If you just want the
Packit Service 50c9f2
  data to be human-readable to aid in debugging, you can set the data
Packit Service 50c9f2
  stream into printable data mode with setPrintableData(). The data is
Packit Service 50c9f2
  then written slower, in a human readable bloated form that is sufficient
Packit Service 50c9f2
  for debugging.
Packit Service 50c9f2
Packit Service 50c9f2
  If you are producing a new binary data format, such as a file format
Packit Service 50c9f2
  for documents created by your application, you could use a QDataStream
Packit Service 50c9f2
  to write the data in a portable format. Typically, you would write
Packit Service 50c9f2
  a brief header containing a magic string and a version number to give
Packit Service 50c9f2
  yourself room for future expansion. For example:
Packit Service 50c9f2
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    // Open the file.
Packit Service 50c9f2
    QFile f( "file.xxx" );
Packit Service 50c9f2
    f.open( IO_WriteOnly );
Packit Service 50c9f2
    QDataStream s( &f );
Packit Service 50c9f2
Packit Service 50c9f2
    // Write a header with a "magic number" and a version
Packit Service 50c9f2
    s << 0xa0b0c0d0;
Packit Service 50c9f2
    s << 123;
Packit Service 50c9f2
Packit Service 50c9f2
    // Write the data
Packit Service 50c9f2
    s << [lots of interesting data]
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  Then read it in with:
Packit Service 50c9f2
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    // Open the file.
Packit Service 50c9f2
    QFile f( "file.xxx" );
Packit Service 50c9f2
    f.open( IO_ReadOnly );
Packit Service 50c9f2
    QDataStream s( &f );
Packit Service 50c9f2
Packit Service 50c9f2
    // Read and check the header
Packit Service 50c9f2
    Q_UINT32 magic;
Packit Service 50c9f2
    s >> magic;
Packit Service 50c9f2
    if ( magic != 0xa0b0c0d0 )
Packit Service 50c9f2
	return XXX_BAD_FILE_FORMAT;
Packit Service 50c9f2
Packit Service 50c9f2
    // Read the version
Packit Service 50c9f2
    Q_INT32 version;
Packit Service 50c9f2
    s >> version;
Packit Service 50c9f2
    if ( version < 100 )
Packit Service 50c9f2
	return XXX_BAD_FILE_TOO_OLD;
Packit Service 50c9f2
    if ( version > 123 )
Packit Service 50c9f2
	return XXX_BAD_FILE_TOO_NEW;
Packit Service 50c9f2
    if ( version <= 110 )
Packit Service 50c9f2
	s.setVersion(1);
Packit Service 50c9f2
Packit Service 50c9f2
    // Read the data
Packit Service 50c9f2
    s >> [lots of interesting data];
Packit Service 50c9f2
    if ( version > 120 )
Packit Service 50c9f2
	s >> [data new in XXX version 1.2];
Packit Service 50c9f2
    s >> [other interesting data];
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QTextStream QVariant
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QDataStream member functions
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
#if defined(CHECK_STATE)
Packit Service 50c9f2
#undef  CHECK_STREAM_PRECOND
Packit Service 50c9f2
#define CHECK_STREAM_PRECOND  if ( !dev ) {				\
Packit Service 50c9f2
				qWarning( "QDataStream: No device" );	\
Packit Service 50c9f2
				return *this; }
Packit Service 50c9f2
#else
Packit Service 50c9f2
#define CHECK_STREAM_PRECOND
Packit Service 50c9f2
#endif
Packit Service 50c9f2
Packit Service 50c9f2
static int  systemWordSize = 0;
Packit Service 50c9f2
static bool systemBigEndian;
Packit Service 50c9f2
Packit Service 50c9f2
static const int DefaultStreamVersion = 3;
Packit Service 50c9f2
// 3 is default in Qt 2.1
Packit Service 50c9f2
// 2 is the Qt 2.0.x format
Packit Service 50c9f2
// 1 is the Qt 1.x format
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a data stream that has no IO device.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa setDevice()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream::QDataStream()
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( systemWordSize == 0 )			// get system features
Packit Service 50c9f2
	qSysInfo( &systemWordSize, &systemBigEndian );
Packit Service 50c9f2
    dev	      = 0;				// no device set
Packit Service 50c9f2
    owndev    = FALSE;
Packit Service 50c9f2
    byteorder = BigEndian;			// default byte order
Packit Service 50c9f2
    printable = FALSE;
Packit Service 50c9f2
    ver	      = DefaultStreamVersion;
Packit Service 50c9f2
    noswap    = systemBigEndian;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a data stream that uses the IO device \a d.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa setDevice(), device()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream::QDataStream( QIODevice *d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( systemWordSize == 0 )			// get system features
Packit Service 50c9f2
	qSysInfo( &systemWordSize, &systemBigEndian );
Packit Service 50c9f2
    dev	      = d;				// set device
Packit Service 50c9f2
    owndev    = FALSE;
Packit Service 50c9f2
    byteorder = BigEndian;			// default byte order
Packit Service 50c9f2
    printable = FALSE;
Packit Service 50c9f2
    ver	      = DefaultStreamVersion;
Packit Service 50c9f2
    noswap    = systemBigEndian;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a data stream that operates on a byte array through an
Packit Service 50c9f2
  internal QBuffer device.
Packit Service 50c9f2
Packit Service 50c9f2
  Example:
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    static char bindata[] = { 231, 1, 44, ... };
Packit Service 50c9f2
    QByteArray	a;
Packit Service 50c9f2
    a.setRawData( bindata, sizeof(bindata) );	// a points to bindata
Packit Service 50c9f2
    QDataStream s( a, IO_ReadOnly );		// open on a's data
Packit Service 50c9f2
    s >> [something];				// read raw bindata
Packit Service 50c9f2
    a.resetRawData( bindata, sizeof(bindata) ); // finished
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  The QArray::setRawData() function is not for the inexperienced.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream::QDataStream( QByteArray a, int mode )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( systemWordSize == 0 )			// get system features
Packit Service 50c9f2
	qSysInfo( &systemWordSize, &systemBigEndian );
Packit Service 50c9f2
    dev	      = new QBuffer( a );		// create device
Packit Service 50c9f2
    ((QBuffer *)dev)->open( mode );		// open device
Packit Service 50c9f2
    owndev    = TRUE;
Packit Service 50c9f2
    byteorder = BigEndian;			// default byte order
Packit Service 50c9f2
    printable = FALSE;
Packit Service 50c9f2
    ver	      = DefaultStreamVersion;
Packit Service 50c9f2
    noswap    = systemBigEndian;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Destructs the data stream.
Packit Service 50c9f2
Packit Service 50c9f2
  The destructor will not affect the current IO device, unless it
Packit Service 50c9f2
  is an internal IO device processing a QByteArray passed in the constructor.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream::~QDataStream()
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( owndev )
Packit Service 50c9f2
	delete dev;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QIODevice *QDataStream::device() const
Packit Service 50c9f2
  Returns the IO device currently set.
Packit Service 50c9f2
  \sa setDevice(), unsetDevice()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  void QDataStream::setDevice(QIODevice *d )
Packit Service 50c9f2
  Sets the IO device to \a d.
Packit Service 50c9f2
  \sa device(), unsetDevice()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QDataStream::setDevice(QIODevice *d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( owndev ) {
Packit Service 50c9f2
	delete dev;
Packit Service 50c9f2
	owndev = FALSE;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    dev = d;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Unsets the IO device.	 This is the same as calling setDevice( 0 ).
Packit Service 50c9f2
  \sa device(), setDevice()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QDataStream::unsetDevice()
Packit Service 50c9f2
{
Packit Service 50c9f2
    setDevice( 0 );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDataStream::atEnd() const
Packit Service 50c9f2
  Returns TRUE if the IO device has reached the end position (end of
Packit Service 50c9f2
  stream or file) or if there is no IO device set.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns FALSE if the current position of the read/write head of the IO
Packit Service 50c9f2
  device is somewhere before the end position.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QIODevice::atEnd()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!\fn bool QDataStream::eof() const
Packit Service 50c9f2
Packit Service 50c9f2
  \obsolete
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if the IO device has reached the end position (end of
Packit Service 50c9f2
  stream or file) or if there is no IO device set.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns FALSE if the current position of the read/write head of the IO
Packit Service 50c9f2
  device is somewhere before the end position.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QIODevice::atEnd()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn int QDataStream::byteOrder() const
Packit Service 50c9f2
  Returns the current byte order setting - either \c BigEndian or
Packit Service 50c9f2
  \c LittleEndian.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa setByteOrder()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets the serialization byte order to \a bo.
Packit Service 50c9f2
Packit Service 50c9f2
  The \a bo parameter can be \c QDataStream::BigEndian or
Packit Service 50c9f2
  \c QDataStream::LittleEndian.
Packit Service 50c9f2
Packit Service 50c9f2
  The default setting is big endian.  We recommend leaving this setting unless
Packit Service 50c9f2
  you have special requirements.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa byteOrder()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QDataStream::setByteOrder( int bo )
Packit Service 50c9f2
{
Packit Service 50c9f2
    byteorder = bo;
Packit Service 50c9f2
    if ( systemBigEndian )
Packit Service 50c9f2
	noswap = byteorder == BigEndian;
Packit Service 50c9f2
    else
Packit Service 50c9f2
	noswap = byteorder == LittleEndian;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QDataStream::isPrintableData() const
Packit Service 50c9f2
  Returns TRUE if the printable data flag has been set.
Packit Service 50c9f2
  \sa setPrintableData()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn void QDataStream::setPrintableData( bool enable )
Packit Service 50c9f2
  Sets or clears the printable data flag.
Packit Service 50c9f2
Packit Service 50c9f2
  If this flag is set, the write functions will generate output that
Packit Service 50c9f2
  consists of printable characters (7 bit ASCII).
Packit Service 50c9f2
Packit Service 50c9f2
  We recommend enabling printable data only for debugging purposes
Packit Service 50c9f2
  (it is slower and creates larger output).
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn int QDataStream::version() const
Packit Service 50c9f2
  Returns the version number of the data serialization format.
Packit Service 50c9f2
  In Qt 2.1, this number is by default 3.
Packit Service 50c9f2
  \sa setVersion()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn void QDataStream::setVersion( int v )
Packit Service 50c9f2
  Sets the version number of the data serialization format.
Packit Service 50c9f2
Packit Service 50c9f2
  In order to accommodate for new functionality, the datastream
Packit Service 50c9f2
  serialization format of some Qt classes has changed in some versions of
Packit Service 50c9f2
  Qt. If you want to read data that was created by an earlier version of
Packit Service 50c9f2
  Qt, or write data that can be read by a program that was compiled with
Packit Service 50c9f2
  an earlier version of Qt, use this function to modify the serialization
Packit Service 50c9f2
  format of QDataStream.
Packit Service 50c9f2
Packit Service 50c9f2
  For Qt 1.x compatibility, use \a v == 1.
Packit Service 50c9f2
Packit Service 50c9f2
  For Qt 2.0.x compatibility, use \a v == 2 (Not required for reading in
Packit Service 50c9f2
  Qt 2.1).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa version()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QDataStream read functions
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
static Q_INT32 read_int_ascii( QDataStream *s )
Packit Service 50c9f2
{
Packit Service 50c9f2
    register int n = 0;
Packit Service 50c9f2
    char buf[40];
Packit Service 50c9f2
    while ( TRUE ) {
Packit Service 50c9f2
	buf[n] = s->device()->getch();
Packit Service 50c9f2
	if ( buf[n] == '\n' || n > 38 )		// $-terminator
Packit Service 50c9f2
	    break;
Packit Service 50c9f2
	n++;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    buf[n] = '\0';
Packit Service 50c9f2
    return (Q_INT32)atol( buf );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator>>( Q_UINT8 &i )
Packit Service 50c9f2
  Reads an unsigned byte from the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a signed byte from the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator>>( Q_INT8 &i )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	i = (Q_INT8)dev->getch();
Packit Service 50c9f2
	if ( i == '\\' ) {			// read octal code
Packit Service 50c9f2
	    char buf[4];
Packit Service 50c9f2
	    dev->readBlock( buf, 3 );
Packit Service 50c9f2
	    i = (buf[2] & 0x07)+((buf[1] & 0x07) << 3)+((buf[0] & 0x07) << 6);
Packit Service 50c9f2
	}
Packit Service 50c9f2
    } else {					// data or text
Packit Service 50c9f2
	i = (Q_INT8)dev->getch();
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator>>( Q_UINT16 &i )
Packit Service 50c9f2
  Reads an unsigned 16-bit integer from the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a signed 16-bit integer from the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator>>( Q_INT16 &i )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	i = (Q_INT16)read_int_ascii( this );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->readBlock( (char *)&i, sizeof(Q_INT16) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&i);
Packit Service 50c9f2
	char b[2];
Packit Service 50c9f2
	dev->readBlock( b, 2 );
Packit Service 50c9f2
	*p++ = b[1];
Packit Service 50c9f2
	*p   = b[0];
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator>>( Q_UINT32 &i )
Packit Service 50c9f2
  Reads an unsigned 32-bit integer from the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a signed 32-bit integer from the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator>>( Q_INT32 &i )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	i = read_int_ascii( this );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->readBlock( (char *)&i, sizeof(Q_INT32) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&i);
Packit Service 50c9f2
	char b[4];
Packit Service 50c9f2
	dev->readBlock( b, 4 );
Packit Service 50c9f2
	*p++ = b[3];
Packit Service 50c9f2
	*p++ = b[2];
Packit Service 50c9f2
	*p++ = b[1];
Packit Service 50c9f2
	*p   = b[0];
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator>>( Q_UINT64 &i )
Packit Service 50c9f2
  Reads an unsigned 64-bit integer from the stream and returns a reference to
Packit Service 50c9f2
  the stream, or uses the Q_UINT32 operator if 64 bit is not available.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a signed 64-bit integer from the stream and returns a reference to
Packit Service 50c9f2
  the stream, or uses the Q_UINT32 operator if 64 bit is not available.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator>>( Q_INT64 &i )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	i = read_int_ascii( this );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->readBlock( (char *)&i, sizeof(Q_INT64) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&i);
Packit Service 50c9f2
	char b[sizeof(Q_INT64)];
Packit Service 50c9f2
	dev->readBlock( b, sizeof(Q_INT64) );
Packit Service 50c9f2
	if ( sizeof(Q_INT64) == 8 ) {
Packit Service 50c9f2
	    *p++ = b[7];
Packit Service 50c9f2
	    *p++ = b[6];
Packit Service 50c9f2
	    *p++ = b[5];
Packit Service 50c9f2
	    *p++ = b[4];
Packit Service 50c9f2
	}
Packit Service 50c9f2
	*p++ = b[3];
Packit Service 50c9f2
	*p++ = b[2];
Packit Service 50c9f2
	*p++ = b[1];
Packit Service 50c9f2
	*p   = b[0];
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
static double read_double_ascii( QDataStream *s )
Packit Service 50c9f2
{
Packit Service 50c9f2
    register int n = 0;
Packit Service 50c9f2
    char buf[80];
Packit Service 50c9f2
    while ( TRUE ) {
Packit Service 50c9f2
	buf[n] = s->device()->getch();
Packit Service 50c9f2
	if ( buf[n] == '\n' || n > 78 )		// $-terminator
Packit Service 50c9f2
	    break;
Packit Service 50c9f2
	n++;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    buf[n] = '\0';
Packit Service 50c9f2
    return atof( buf );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a 32-bit floating point number from the stream using the standard
Packit Service 50c9f2
  IEEE754 format. Returns a reference to the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator>>( float &f )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	f = (float)read_double_ascii( this );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->readBlock( (char *)&f, sizeof(float) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&f);
Packit Service 50c9f2
	char b[4];
Packit Service 50c9f2
	dev->readBlock( b, 4 );
Packit Service 50c9f2
	*p++ = b[3];
Packit Service 50c9f2
	*p++ = b[2];
Packit Service 50c9f2
	*p++ = b[1];
Packit Service 50c9f2
	*p   = b[0];
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a 64-bit floating point number from the stream using the standard
Packit Service 50c9f2
  IEEE754 format. Returns a reference to the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator>>( double &f )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	f = read_double_ascii( this );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->readBlock( (char *)&f, sizeof(double) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&f);
Packit Service 50c9f2
	char b[8];
Packit Service 50c9f2
	dev->readBlock( b, 8 );
Packit Service 50c9f2
	*p++ = b[7];
Packit Service 50c9f2
	*p++ = b[6];
Packit Service 50c9f2
	*p++ = b[5];
Packit Service 50c9f2
	*p++ = b[4];
Packit Service 50c9f2
	*p++ = b[3];
Packit Service 50c9f2
	*p++ = b[2];
Packit Service 50c9f2
	*p++ = b[1];
Packit Service 50c9f2
	*p   = b[0];
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads the '\0'-terminated string \a s from the stream and returns
Packit Service 50c9f2
  a reference to the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  Space for the string is allocated using \c new - the caller must
Packit Service 50c9f2
  eventually call delete[] on the value.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator>>( char *&s )
Packit Service 50c9f2
{
Packit Service 50c9f2
    uint len = 0;
Packit Service 50c9f2
    return readBytes( s, len );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads the buffer \a s from the stream and returns a reference to the
Packit Service 50c9f2
  stream.
Packit Service 50c9f2
Packit Service 50c9f2
  The buffer \a s is allocated using \c new. Destroy it with the \c delete[]
Packit Service 50c9f2
  operator.  If the length is zero or \a s cannot be allocated, \a s is
Packit Service 50c9f2
  set to 0.
Packit Service 50c9f2
Packit Service 50c9f2
  The \a l parameter will be set to the length of the buffer.
Packit Service 50c9f2
Packit Service 50c9f2
  The serialization format is an Q_UINT32 length specifier first, then the
Packit Service 50c9f2
  data (\a l bytes).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa readRawBytes(), writeBytes()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::readBytes( char *&s, uint &l )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    Q_UINT32 len;
Packit Service 50c9f2
    *this >> len;				// first read length spec
Packit Service 50c9f2
    l = (uint)len;
Packit Service 50c9f2
    if ( len == 0 || eof() ) {
Packit Service 50c9f2
	s = 0;
Packit Service 50c9f2
	return *this;
Packit Service 50c9f2
    } else {
Packit Service 50c9f2
	s = new char[len];			// create char array
Packit Service 50c9f2
	CHECK_PTR( s );
Packit Service 50c9f2
	if ( !s )				// no memory
Packit Service 50c9f2
	    return *this;
Packit Service 50c9f2
	return readRawBytes( s, (uint)len );
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads \a len bytes from the stream into \a s and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  The buffer \a s must be preallocated.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa readBytes(), QIODevice::readBlock(), writeRawBytes()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::readRawBytes( char *s, uint len )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	register Q_INT8 *p = (Q_INT8*)s;
Packit Service 50c9f2
	while ( len-- )
Packit Service 50c9f2
	    *this >> *p++;
Packit Service 50c9f2
    } else {					// read data char array
Packit Service 50c9f2
	dev->readBlock( s, len );
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QDataStream write functions
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator<<( Q_UINT8 i )
Packit Service 50c9f2
  Writes an unsigned byte to the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes a signed byte to the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator<<( Q_INT8 i )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable && (i == '\\' || !isprint(i)) ) {
Packit Service 50c9f2
	char buf[6];				// write octal code
Packit Service 50c9f2
	buf[0] = '\\';
Packit Service 50c9f2
	buf[1] = '0' + ((i >> 6) & 0x07);
Packit Service 50c9f2
	buf[2] = '0' + ((i >> 3) & 0x07);
Packit Service 50c9f2
	buf[3] = '0' + (i & 0x07);
Packit Service 50c9f2
	buf[4] = '\0';
Packit Service 50c9f2
	dev->writeBlock( buf, 4 );
Packit Service 50c9f2
    } else {
Packit Service 50c9f2
	dev->putch( i );
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator<<( Q_UINT16 i )
Packit Service 50c9f2
  Writes an unsigned 16-bit integer to the stream and returns a reference
Packit Service 50c9f2
  to the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes a signed 16-bit integer to the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator<<( Q_INT16 i )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	char buf[16];
Packit Service 50c9f2
	sprintf( buf, "%d\n", i );
Packit Service 50c9f2
	dev->writeBlock( buf, strlen(buf) );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->writeBlock( (char *)&i, sizeof(Q_INT16) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&i);
Packit Service 50c9f2
	char b[2];
Packit Service 50c9f2
	b[1] = *p++;
Packit Service 50c9f2
	b[0] = *p;
Packit Service 50c9f2
	dev->writeBlock( b, 2 );
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator<<( Q_UINT32 i )
Packit Service 50c9f2
  Writes an unsigned 32-bit integer to the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes a signed 32-bit integer to the stream and returns a reference to
Packit Service 50c9f2
  the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator<<( Q_INT32 i )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	char buf[16];
Packit Service 50c9f2
	sprintf( buf, "%d\n", i );
Packit Service 50c9f2
	dev->writeBlock( buf, strlen(buf) );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->writeBlock( (char *)&i, sizeof(Q_INT32) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&i);
Packit Service 50c9f2
	char b[4];
Packit Service 50c9f2
	b[3] = *p++;
Packit Service 50c9f2
	b[2] = *p++;
Packit Service 50c9f2
	b[1] = *p++;
Packit Service 50c9f2
	b[0] = *p;
Packit Service 50c9f2
	dev->writeBlock( b, 4 );
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator<<( Q_UINT64 i )
Packit Service 50c9f2
  Writes an unsigned 64-bit integer to the stream and returns a reference to
Packit Service 50c9f2
  the stream, or uses the Q_UINT32-operator if 64 bit is not available.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes a signed 64-bit integer to the stream and returns a reference to
Packit Service 50c9f2
  the stream, or calls the Q_INT32-operator if 64 bit is not available.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator<<( Q_INT64 i )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	char buf[20];
Packit Service 50c9f2
	sprintf( buf, "%ld\n", i );
Packit Service 50c9f2
	dev->writeBlock( buf, strlen(buf) );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->writeBlock( (char *)&i, sizeof(Q_INT64) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&i);
Packit Service 50c9f2
	char b[sizeof(Q_INT64)];
Packit Service 50c9f2
	if ( sizeof(Q_INT64) == 8 ) {
Packit Service 50c9f2
	    b[7] = *p++;
Packit Service 50c9f2
	    b[6] = *p++;
Packit Service 50c9f2
	    b[5] = *p++;
Packit Service 50c9f2
	    b[4] = *p++;
Packit Service 50c9f2
	}
Packit Service 50c9f2
	b[3] = *p++;
Packit Service 50c9f2
	b[2] = *p++;
Packit Service 50c9f2
	b[1] = *p++;
Packit Service 50c9f2
	b[0] = *p;
Packit Service 50c9f2
	dev->writeBlock( b, sizeof(Q_INT64) );
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator<<( uint i )
Packit Service 50c9f2
  Writes an unsigned integer to the stream as a 32-bit unsigned integer
Packit Service 50c9f2
  (Q_UINT32).
Packit Service 50c9f2
  Returns a reference to the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QDataStream &QDataStream::operator<<( int i )
Packit Service 50c9f2
  Writes a signed integer to the stream as a 32-bit signed integer (Q_INT32).
Packit Service 50c9f2
  Returns a reference to the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes a 32-bit floating point number to the stream using the standard
Packit Service 50c9f2
  IEEE754 format.  Returns a reference to the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator<<( float f )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	char buf[32];
Packit Service 50c9f2
	sprintf( buf, "%g\n", (double)f );
Packit Service 50c9f2
	dev->writeBlock( buf, strlen(buf) );
Packit Service 50c9f2
    } else {
Packit Service 50c9f2
	float g = f;				// fixes float-on-stack problem
Packit Service 50c9f2
	if ( noswap ) {				// no conversion needed
Packit Service 50c9f2
	    dev->writeBlock( (char *)&g, sizeof(float) );
Packit Service 50c9f2
	} else {				// swap bytes
Packit Service 50c9f2
	    register uchar *p = (uchar *)(&g);
Packit Service 50c9f2
	    char b[4];
Packit Service 50c9f2
	    b[3] = *p++;
Packit Service 50c9f2
	    b[2] = *p++;
Packit Service 50c9f2
	    b[1] = *p++;
Packit Service 50c9f2
	    b[0] = *p;
Packit Service 50c9f2
	    dev->writeBlock( b, 4 );
Packit Service 50c9f2
	}
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes a 64-bit floating point number to the stream using the standard
Packit Service 50c9f2
  IEEE754 format.  Returns a reference to the stream.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator<<( double f )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// printable data
Packit Service 50c9f2
	char buf[32];
Packit Service 50c9f2
	sprintf( buf, "%g\n", f );
Packit Service 50c9f2
	dev->writeBlock( buf, strlen(buf) );
Packit Service 50c9f2
    } else if ( noswap ) {			// no conversion needed
Packit Service 50c9f2
	dev->writeBlock( (char *)&f, sizeof(double) );
Packit Service 50c9f2
    } else {					// swap bytes
Packit Service 50c9f2
	register uchar *p = (uchar *)(&f);
Packit Service 50c9f2
	char b[8];
Packit Service 50c9f2
	b[7] = *p++;
Packit Service 50c9f2
	b[6] = *p++;
Packit Service 50c9f2
	b[5] = *p++;
Packit Service 50c9f2
	b[4] = *p++;
Packit Service 50c9f2
	b[3] = *p++;
Packit Service 50c9f2
	b[2] = *p++;
Packit Service 50c9f2
	b[1] = *p++;
Packit Service 50c9f2
	b[0] = *p;
Packit Service 50c9f2
	dev->writeBlock( b, 8 );
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes the '\0'-terminated string \a s to the stream and returns
Packit Service 50c9f2
  a reference to the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  The string is serialized using writeBytes().
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::operator<<( const char *s )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( !s ) {
Packit Service 50c9f2
	*this << (Q_UINT32)0;
Packit Service 50c9f2
	return *this;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    uint len = qstrlen( s ) + 1;			// also write null terminator
Packit Service 50c9f2
    *this << (Q_UINT32)len;			// write length specifier
Packit Service 50c9f2
    return writeRawBytes( s, len );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes the length specifier \a len and the buffer \a s to the stream and
Packit Service 50c9f2
  returns a reference to the stream.
Packit Service 50c9f2
Packit Service 50c9f2
  The \a len is serialized as an Q_UINT32, followed by \a len bytes from
Packit Service 50c9f2
  \a s.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa writeRawBytes(), readBytes()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::writeBytes(const char *s, uint len)
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    *this << (Q_UINT32)len;			// write length specifier
Packit Service 50c9f2
    if ( len )
Packit Service 50c9f2
	writeRawBytes( s, len );
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes \a len bytes from \a s to the stream and returns a reference to the
Packit Service 50c9f2
  stream.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa writeBytes(), QIODevice::writeBlock(), readRawBytes()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QDataStream &QDataStream::writeRawBytes( const char *s, uint len )
Packit Service 50c9f2
{
Packit Service 50c9f2
    CHECK_STREAM_PRECOND
Packit Service 50c9f2
    if ( printable ) {				// write printable
Packit Service 50c9f2
	register char *p = (char *)s;
Packit Service 50c9f2
	while ( len-- )
Packit Service 50c9f2
	    *this << *p++;
Packit Service 50c9f2
    } else {					// write data char array
Packit Service 50c9f2
	dev->writeBlock( s, len );
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return *this;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
#endif // QT_NO_DATASTREAM