Blame qtools/qiodevice.cpp

Packit Service 50c9f2
/****************************************************************************
Packit Service 50c9f2
** 
Packit Service 50c9f2
**
Packit Service 50c9f2
** Implementation of QIODevice class
Packit Service 50c9f2
**
Packit Service 50c9f2
** Created : 940913
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 "qiodevice.h"
Packit Service 50c9f2
Packit Service 50c9f2
// NOT REVISED
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \class QIODevice qiodevice.h
Packit Service 50c9f2
Packit Service 50c9f2
  \brief The QIODevice class is the base class of I/O devices.
Packit Service 50c9f2
Packit Service 50c9f2
  \ingroup io
Packit Service 50c9f2
Packit Service 50c9f2
  An I/O device represents a medium that one can read bytes from
Packit Service 50c9f2
  and/or write bytes to.  The QIODevice class is the abstract
Packit Service 50c9f2
  superclass of all such devices; classes like QFile, QBuffer and
Packit Service 50c9f2
  QSocket inherit QIODevice and implement virtual functions like
Packit Service 50c9f2
  write() appropriately.
Packit Service 50c9f2
Packit Service 50c9f2
  While applications sometimes use QIODevice directly, mostly it is
Packit Service 50c9f2
  better to go through QTextStream and QDataStream, which provide
Packit Service 50c9f2
  stream operations on any QIODevice subclass.  QTextStream provides
Packit Service 50c9f2
  text-oriented stream functionality (for human-readable ASCII files,
Packit Service 50c9f2
  for example), while QDataStream deals with binary data in a totally
Packit Service 50c9f2
  platform-independent manner.
Packit Service 50c9f2
Packit Service 50c9f2
  The public member functions in QIODevice roughly fall into two
Packit Service 50c9f2
  groups: The action functions and the state access functions.  The
Packit Service 50c9f2
  most important action functions are: 
    Packit Service 50c9f2
    Packit Service 50c9f2
      
  • open() opens a device for reading and/or writing, depending on
  • Packit Service 50c9f2
      the argument to open().
    Packit Service 50c9f2
    Packit Service 50c9f2
      
  • close() closes the device and tidies up.
  • Packit Service 50c9f2
    Packit Service 50c9f2
      
  • readBlock() reads a block of data from the device.
  • Packit Service 50c9f2
    Packit Service 50c9f2
      
  • writeBlock() writes a block of data to the device.
  • Packit Service 50c9f2
    Packit Service 50c9f2
      
  • readLine() reads a line (of text, usually) from the device.
  • Packit Service 50c9f2
    Packit Service 50c9f2
      
  • flush() ensures that all buffered data are written to the real device.
  • Packit Service 50c9f2
    Packit Service 50c9f2
      There are also some other, less used, action functions: 
      Packit Service 50c9f2
      Packit Service 50c9f2
        
    • getch() reads a single character.
    • Packit Service 50c9f2
      Packit Service 50c9f2
        
    • ungetch() forgets the last call to getch(), if possible.
    • Packit Service 50c9f2
      Packit Service 50c9f2
        
    • putch() writes a single character.
    • Packit Service 50c9f2
      Packit Service 50c9f2
        
    • size() returns the size of the device, if there is one.
    • Packit Service 50c9f2
      Packit Service 50c9f2
        
    • at() returns the current read/write pointer, if there is one
    • Packit Service 50c9f2
        for this device, or it moves the pointer.
      Packit Service 50c9f2
      Packit Service 50c9f2
        
    • atEnd() says whether there is more to read, if that is a
    • Packit Service 50c9f2
        meaningful question for this device.
      Packit Service 50c9f2
      Packit Service 50c9f2
        
    • reset() moves the read/write pointer to the start of the
    • Packit Service 50c9f2
        device, if that is possible for this device.
      Packit Service 50c9f2
      Packit Service 50c9f2
        The state access are all "get" functions.  The QIODevice subclass
      Packit Service 50c9f2
        calls setState() to update the state, and simple access functions
      Packit Service 50c9f2
        tell the user of the device what the device's state is.  Here are
      Packit Service 50c9f2
        the settings, and their associated access functions: 
        Packit Service 50c9f2
        Packit Service 50c9f2
          
      • Access type. Some devices are direct access (it is possible to
      • Packit Service 50c9f2
          read/write anywhere) while others are sequential.  QIODevice
        Packit Service 50c9f2
          provides the access functions isDirectAccess(), isSequentialAccess()
        Packit Service 50c9f2
          and isCombinedAccess() to tell users what a given I/O device
        Packit Service 50c9f2
          supports.
        Packit Service 50c9f2
        Packit Service 50c9f2
          
      • Buffering. Some devices are accessed in raw mode while others
      • Packit Service 50c9f2
          are buffered.  Buffering usually provides greater efficiency,
        Packit Service 50c9f2
          particularly for small read/write operations.  isBuffered() tells
        Packit Service 50c9f2
          the user whether a given device is buffered.  (This can often be set
        Packit Service 50c9f2
          by the application in the call to open().)
        Packit Service 50c9f2
        Packit Service 50c9f2
          
      • Synchronicity. Synchronous devices work there and then, for
      • Packit Service 50c9f2
          example files.  When you read from a file, the file delivers its
        Packit Service 50c9f2
          data right away.  Others, such as a socket connected to a HTTP
        Packit Service 50c9f2
          server, may not deliver the data until seconds after you ask to read
        Packit Service 50c9f2
          it.  isSynchronous() and isAsynchronous() tells the user how this
        Packit Service 50c9f2
          device operates.
        Packit Service 50c9f2
        Packit Service 50c9f2
          
      • CR/LF translation. For simplicity, applications often like to
      • Packit Service 50c9f2
          see just a single CR/LF style, and QIODevice subclasses can provide
        Packit Service 50c9f2
          that.  isTranslated() returns TRUE if this object translates CR/LF
        Packit Service 50c9f2
          to just LF.  (This can often be set by the application in the call
        Packit Service 50c9f2
          to open().)
        Packit Service 50c9f2
        Packit Service 50c9f2
          
      • Accessibility. Some files cannot be written, for example.
      • Packit Service 50c9f2
          isReadable(), isWritable and isReadWrite() tells the application
        Packit Service 50c9f2
          whether it can read from and write to a given device.  (This can
        Packit Service 50c9f2
          often be set by the application in the call to open().)
        Packit Service 50c9f2
        Packit Service 50c9f2
          
      • Finally, isOpen() returns TRUE if the device is open. This can
      • Packit Service 50c9f2
          quite obviously be set using open() :)
        Packit Service 50c9f2
        Packit Service 50c9f2
          
        Packit Service 50c9f2
        Packit Service 50c9f2
          QIODevice provides numerous pure virtual functions you need to
        Packit Service 50c9f2
          implement when subclassing it.  Here is a skeleton subclass with all
        Packit Service 50c9f2
          the members you are certain to need, and some it's likely that you
        Packit Service 50c9f2
          will need:
        Packit Service 50c9f2
        Packit Service 50c9f2
          \code
        Packit Service 50c9f2
            class YourDevice : public QIODevice
        Packit Service 50c9f2
            {
        Packit Service 50c9f2
            public:
        Packit Service 50c9f2
        	YourDevice();
        Packit Service 50c9f2
               ~YourDevice();
        Packit Service 50c9f2
        Packit Service 50c9f2
        	bool open( int mode );
        Packit Service 50c9f2
        	void close();
        Packit Service 50c9f2
        	void flush();
        Packit Service 50c9f2
        Packit Service 50c9f2
        	uint size() const;
        Packit Service 50c9f2
        	int  at() const;	// not a pure virtual function
        Packit Service 50c9f2
        	bool at( int );		// not a pure virtual function
        Packit Service 50c9f2
        	bool atEnd() const;	// not a pure virtual function
        Packit Service 50c9f2
        Packit Service 50c9f2
        	int readBlock( char *data, uint maxlen );
        Packit Service 50c9f2
        	int writeBlock( const char *data, uint len );
        Packit Service 50c9f2
        	int readLine( char *data, uint maxlen );
        Packit Service 50c9f2
        Packit Service 50c9f2
        	int getch();
        Packit Service 50c9f2
        	int putch( int );
        Packit Service 50c9f2
        	int ungetch( int );
        Packit Service 50c9f2
            };
        Packit Service 50c9f2
          \endcode
        Packit Service 50c9f2
        Packit Service 50c9f2
          The three non-pure virtual functions can be ignored if your device
        Packit Service 50c9f2
          is sequential (e.g. an RS-232 port).
        Packit Service 50c9f2
        Packit Service 50c9f2
          \sa QDataStream, QTextStream
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          Constructs an I/O device.
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        QIODevice::QIODevice()
        Packit Service 50c9f2
        {
        Packit Service 50c9f2
            ioMode = 0;					// initial mode
        Packit Service 50c9f2
            ioSt = IO_Ok;
        Packit Service 50c9f2
            ioIndex = 0;
        Packit Service 50c9f2
        }
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          Destructs the I/O device.
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        QIODevice::~QIODevice()
        Packit Service 50c9f2
        {
        Packit Service 50c9f2
        }
        Packit Service 50c9f2
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn int QIODevice::flags() const
        Packit Service 50c9f2
          Returns the current I/O device flags setting.
        Packit Service 50c9f2
        Packit Service 50c9f2
          Flags consists of mode flags and state flags.
        Packit Service 50c9f2
        Packit Service 50c9f2
          \sa mode(), state()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn int QIODevice::mode() const
        Packit Service 50c9f2
          Returns bits OR'ed together that specify the current operation mode.
        Packit Service 50c9f2
        Packit Service 50c9f2
          These are the flags that were given to the open() function.
        Packit Service 50c9f2
        Packit Service 50c9f2
          The flags are: \c IO_ReadOnly, \c IO_WriteOnly, \c IO_ReadWrite,
        Packit Service 50c9f2
          \c IO_Append, \c IO_Truncate and \c IO_Translate.
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn int QIODevice::state() const
        Packit Service 50c9f2
          Returns bits OR'ed together that specify the current state.
        Packit Service 50c9f2
        Packit Service 50c9f2
          The flags are: \c IO_Open.
        Packit Service 50c9f2
        Packit Service 50c9f2
          Subclasses may define more flags.
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isDirectAccess() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device is a direct access (not sequential) device,
        Packit Service 50c9f2
          otherwise FALSE.
        Packit Service 50c9f2
          \sa isSequentialAccess()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isSequentialAccess() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device is a sequential access (not direct) device,
        Packit Service 50c9f2
          otherwise FALSE.  Operations involving size() and at(int) are not valid
        Packit Service 50c9f2
          on sequential devices.
        Packit Service 50c9f2
          \sa isDirectAccess()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isCombinedAccess() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device is a combined access (both direct and
        Packit Service 50c9f2
          sequential) device,  otherwise FALSE.
        Packit Service 50c9f2
        Packit Service 50c9f2
          This access method is currently not in use.
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isBuffered() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device is a buffered (not raw) device, otherwise
        Packit Service 50c9f2
          FALSE.
        Packit Service 50c9f2
          \sa isRaw()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isRaw() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device is a raw (not buffered) device, otherwise
        Packit Service 50c9f2
          FALSE.
        Packit Service 50c9f2
          \sa isBuffered()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isSynchronous() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device is a synchronous device, otherwise
        Packit Service 50c9f2
          FALSE.
        Packit Service 50c9f2
          \sa isAsynchronous()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isAsynchronous() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device is a asynchronous device, otherwise
        Packit Service 50c9f2
          FALSE.
        Packit Service 50c9f2
        Packit Service 50c9f2
          This mode is currently not in use.
        Packit Service 50c9f2
        Packit Service 50c9f2
          \sa isSynchronous()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isTranslated() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device translates carriage-return and linefeed
        Packit Service 50c9f2
          characters.
        Packit Service 50c9f2
        Packit Service 50c9f2
          A QFile is translated if it is opened with the \c IO_Translate mode
        Packit Service 50c9f2
          flag.
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isReadable() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device was opened using \c IO_ReadOnly or
        Packit Service 50c9f2
          \c IO_ReadWrite mode.
        Packit Service 50c9f2
          \sa isWritable(), isReadWrite()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isWritable() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device was opened using \c IO_WriteOnly or
        Packit Service 50c9f2
          \c IO_ReadWrite mode.
        Packit Service 50c9f2
          \sa isReadable(), isReadWrite()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isReadWrite() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device was opened using \c IO_ReadWrite mode.
        Packit Service 50c9f2
          \sa isReadable(), isWritable()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isInactive() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device state is 0, i.e. the device is not open.
        Packit Service 50c9f2
          \sa isOpen()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn bool QIODevice::isOpen() const
        Packit Service 50c9f2
          Returns TRUE if the I/O device state has been opened, otherwise FALSE.
        Packit Service 50c9f2
          \sa isInactive()
        Packit Service 50c9f2
        */
        Packit Service 50c9f2
        Packit Service 50c9f2
        Packit Service 50c9f2
        /*!
        Packit Service 50c9f2
          \fn int QIODevice::status() const
        Packit Service 50c9f2
          Returns the I/O device status.
        Packit Service 50c9f2
        Packit Service 50c9f2
          The I/O device status returns an error code.	If open() returns FALSE
        Packit Service 50c9f2
          or readBlock() or writeBlock() return -1, this function can be called to
        Packit Service 50c9f2
          get the reason why the operation did not succeed.
        Packit Service 50c9f2
        Packit Service 50c9f2
          The status codes are:
        Packit Service 50c9f2
          
          Packit Service 50c9f2
            
        • \c IO_Ok The operation was successful.
        • Packit Service 50c9f2
            
        • \c IO_ReadError Could not read from the device.
        • Packit Service 50c9f2
            
        • \c IO_WriteError Could not write to the device.
        • Packit Service 50c9f2
            
        • \c IO_FatalError A fatal unrecoverable error occurred.
        • Packit Service 50c9f2
            
        • \c IO_OpenError Could not open the device.
        • Packit Service 50c9f2
            
        • \c IO_ConnectError Could not connect to the device.
        • Packit Service 50c9f2
            
        • \c IO_AbortError The operation was unexpectedly aborted.
        • Packit Service 50c9f2
            
        • \c IO_TimeOutError The operation timed out.
        • Packit Service 50c9f2
            
        • \c IO_OnCloseError An unspecified error happened on close.
        • Packit Service 50c9f2
            
          Packit Service 50c9f2
          Packit Service 50c9f2
            \sa resetStatus()
          Packit Service 50c9f2
          */
          Packit Service 50c9f2
          Packit Service 50c9f2
          /*!
          Packit Service 50c9f2
            \fn void QIODevice::resetStatus()
          Packit Service 50c9f2
          Packit Service 50c9f2
            Sets the I/O device status to \c IO_Ok.
          Packit Service 50c9f2
          Packit Service 50c9f2
            \sa status()
          Packit Service 50c9f2
          */
          Packit Service 50c9f2
          Packit Service 50c9f2
          Packit Service 50c9f2
          /*!
          Packit Service 50c9f2
            \fn void QIODevice::setFlags( int f )
          Packit Service 50c9f2
            \internal
          Packit Service 50c9f2
            Used by subclasses to set the device flags.
          Packit Service 50c9f2
          */
          Packit Service 50c9f2
          Packit Service 50c9f2
          /*!
          Packit Service 50c9f2
            \internal
          Packit Service 50c9f2
            Used by subclasses to set the device type.
          Packit Service 50c9f2
          */
          Packit Service 50c9f2
          Packit Service 50c9f2
          void QIODevice::setType( int t )
          Packit Service 50c9f2
          {
          Packit Service 50c9f2
          #if defined(CHECK_RANGE)
          Packit Service 50c9f2
              if ( (t & IO_TypeMask) != t )
          Packit Service 50c9f2
          	qWarning( "QIODevice::setType: Specified type out of range" );
          Packit Service 50c9f2
          #endif
          Packit Service 50c9f2
              ioMode &= ~IO_TypeMask;			// reset type bits
          Packit Service 50c9f2
              ioMode |= t;
          Packit Service 50c9f2
          }
          Packit Service 50c9f2
          Packit Service 50c9f2
          /*!
          Packit Service 50c9f2
            \internal
          Packit Service 50c9f2
            Used by subclasses to set the device mode.
          Packit Service 50c9f2
          */
          Packit Service 50c9f2
          Packit Service 50c9f2
          void QIODevice::setMode( int m )
          Packit Service 50c9f2
          {
          Packit Service 50c9f2
          #if defined(CHECK_RANGE)
          Packit Service 50c9f2
              if ( (m & IO_ModeMask) != m )
          Packit Service 50c9f2
          	qWarning( "QIODevice::setMode: Specified mode out of range" );
          Packit Service 50c9f2
          #endif
          Packit Service 50c9f2
              ioMode &= ~IO_ModeMask;			// reset mode bits
          Packit Service 50c9f2
              ioMode |= m;
          Packit Service 50c9f2
          }
          Packit Service 50c9f2
          Packit Service 50c9f2
          /*!
          Packit Service 50c9f2
            \internal
          Packit Service 50c9f2
            Used by subclasses to set the device state.
          Packit Service 50c9f2
          */
          Packit Service 50c9f2
          Packit Service 50c9f2
          void QIODevice::setState( int s )
          Packit Service 50c9f2
          {
          Packit Service 50c9f2
          #if defined(CHECK_RANGE)
          Packit Service 50c9f2
              if ( ((uint)s & IO_StateMask) != (uint)s )
          Packit Service 50c9f2
          	qWarning( "QIODevice::setState: Specified state out of range" );
          Packit Service 50c9f2
          #endif
          Packit Service 50c9f2
              ioMode &= ~IO_StateMask;			// reset state bits
          Packit Service 50c9f2
              ioMode |= (uint)s;
          Packit Service 50c9f2
          }
          Packit Service 50c9f2
          Packit Service 50c9f2
          /*!
          Packit Service 50c9f2
            \internal
          Packit Service 50c9f2
            Used by subclasses to set the device status (not state).
          Packit Service 50c9f2
          */
          Packit Service 50c9f2
          Packit Service 50c9f2
          void QIODevice::setStatus( int s )
          Packit Service 50c9f2
          {
          Packit Service 50c9f2
              ioSt = s;
          Packit Service 50c9f2
          }
          Packit Service 50c9f2
          Packit Service 50c9f2
          Packit Service 50c9f2
          /*!
          Packit Service 50c9f2
            \fn bool QIODevice::open( int mode )
          Packit Service 50c9f2
            Opens the I/O device using the specified \e mode.
          Packit Service 50c9f2
            Returns TRUE if successful, or FALSE if the device could not be opened.
          Packit Service 50c9f2
          Packit Service 50c9f2
            The mode parameter \e m must be a combination of the following flags.
          Packit Service 50c9f2
            
            Packit Service 50c9f2
              
          • \c IO_Raw specified raw (unbuffered) file access.
          • Packit Service 50c9f2
              
          • \c IO_ReadOnly opens a file in read-only mode.
          • Packit Service 50c9f2
              
          • \c IO_WriteOnly opens a file in write-only mode.
          • Packit Service 50c9f2
              
          • \c IO_ReadWrite opens a file in read/write mode.
          • Packit Service 50c9f2
              
          • \c IO_Append sets the file index to the end of the file.
          • Packit Service 50c9f2
              
          • \c IO_Truncate truncates the file.
          • Packit Service 50c9f2
              
          • \c IO_Translate enables carriage returns and linefeed translation
          • Packit Service 50c9f2
              for text files under MS-DOS, Window, OS/2 and Macintosh.  On Unix systems 
            Packit Service 50c9f2
              this flag has no effect. Use with caution as it will also transform every linefeed
            Packit Service 50c9f2
              written to the file into a CRLF pair. This is likely to corrupt your file when
            Packit Service 50c9f2
              writing binary data to it. Cannot be combined with \c IO_Raw.
            Packit Service 50c9f2
              
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function must be reimplemented by all subclasses.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa close()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn void QIODevice::close()
            Packit Service 50c9f2
              Closes the I/O device.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function must be reimplemented by all subclasses.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa open()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn void QIODevice::flush()
            Packit Service 50c9f2
            Packit Service 50c9f2
              Flushes an open I/O device.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function must be reimplemented by all subclasses.
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn uint QIODevice::size() const
            Packit Service 50c9f2
              Virtual function that returns the size of the I/O device.
            Packit Service 50c9f2
              \sa at()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              Virtual function that returns the current I/O device index.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This index is the data read/write head of the I/O device.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa size()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            int QIODevice::at() const
            Packit Service 50c9f2
            {
            Packit Service 50c9f2
                return ioIndex;
            Packit Service 50c9f2
            }
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              Virtual function that sets the I/O device index to \e pos.
            Packit Service 50c9f2
              \sa size()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            bool QIODevice::at( int pos )
            Packit Service 50c9f2
            {
            Packit Service 50c9f2
            #if defined(CHECK_RANGE)
            Packit Service 50c9f2
                if ( (uint)pos > size() ) {
            Packit Service 50c9f2
            	qWarning( "QIODevice::at: Index %d out of range", pos );
            Packit Service 50c9f2
            	return FALSE;
            Packit Service 50c9f2
                }
            Packit Service 50c9f2
            #endif
            Packit Service 50c9f2
                ioIndex = pos;
            Packit Service 50c9f2
                return TRUE;
            Packit Service 50c9f2
            }
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              Virtual function that returns TRUE if the I/O device index is at the
            Packit Service 50c9f2
              end of the input.
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            bool QIODevice::atEnd() const
            Packit Service 50c9f2
            {
            Packit Service 50c9f2
                if ( isSequentialAccess() || isTranslated() ) {
            Packit Service 50c9f2
            	QIODevice* that = (QIODevice*)this;
            Packit Service 50c9f2
            	int c = that->getch();
            Packit Service 50c9f2
            	bool result = c < 0;
            Packit Service 50c9f2
            	that->ungetch(c);
            Packit Service 50c9f2
            	return result;
            Packit Service 50c9f2
                } else {
            Packit Service 50c9f2
            	return at() == (int)size();
            Packit Service 50c9f2
                }
            Packit Service 50c9f2
            }
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn bool QIODevice::reset()
            Packit Service 50c9f2
              Sets the device index to 0.
            Packit Service 50c9f2
              \sa at()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn int QIODevice::readBlock( char *data, uint maxlen )
            Packit Service 50c9f2
              Reads at most \e maxlen bytes from the I/O device into \e data and
            Packit Service 50c9f2
              returns the number of bytes actually read.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function must be reimplemented by all subclasses.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa writeBlock()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              This convenience function returns all of the remaining data in the
            Packit Service 50c9f2
              device.  Note that this only works for direct access devices, such
            Packit Service 50c9f2
              as QFile.
            Packit Service 50c9f2
              
            Packit Service 50c9f2
              \sa isDirectAccess() 
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            QByteArray QIODevice::readAll()
            Packit Service 50c9f2
            {
            Packit Service 50c9f2
                int n = size()-at();
            Packit Service 50c9f2
                QByteArray ba(size()-at());
            Packit Service 50c9f2
                char* c = ba.data();
            Packit Service 50c9f2
                while ( n ) {
            Packit Service 50c9f2
            	int r = readBlock( c, n );
            Packit Service 50c9f2
            	if ( r < 0 )
            Packit Service 50c9f2
            	    return QByteArray();
            Packit Service 50c9f2
            	n -= r;
            Packit Service 50c9f2
            	c += r;
            Packit Service 50c9f2
                }
            Packit Service 50c9f2
                return ba;
            Packit Service 50c9f2
            }
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn int QIODevice::writeBlock( const char *data, uint len )
            Packit Service 50c9f2
              Writes \e len bytes from \e p to the I/O device and returns the number of
            Packit Service 50c9f2
              bytes actually written.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function must be reimplemented by all subclasses.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa readBlock()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              This convenience function is the same as calling
            Packit Service 50c9f2
              writeBlock( data.data(), data.size() ).
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            int QIODevice::writeBlock( const QByteArray& data )
            Packit Service 50c9f2
            {
            Packit Service 50c9f2
                return writeBlock( data.data(), data.size() );
            Packit Service 50c9f2
            }
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              Reads a line of text, up to \e maxlen bytes including a terminating
            Packit Service 50c9f2
              \0.  If there is a newline at the end if the line, it is not stripped.
            Packit Service 50c9f2
            Packit Service 50c9f2
              Returns the number of bytes read, or -1 in case of error.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function can be reimplemented much more efficiently by
            Packit Service 50c9f2
              the most subclasses.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa readBlock(), QTextStream::readLine()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            int QIODevice::readLine( char *data, uint maxlen )
            Packit Service 50c9f2
            {
            Packit Service 50c9f2
                if ( maxlen == 0 )				// application bug?
            Packit Service 50c9f2
            	return 0;
            Packit Service 50c9f2
                int pos = at();				// get current position
            Packit Service 50c9f2
                int s  = (int)size();			// size of I/O device
            Packit Service 50c9f2
                char *p = data;
            Packit Service 50c9f2
                if ( pos >= s )
            Packit Service 50c9f2
            	return 0;
            Packit Service 50c9f2
                while ( pos++ < s && --maxlen ) {		// read one byte at a time
            Packit Service 50c9f2
            	readBlock( p, 1 );
            Packit Service 50c9f2
            	if ( *p++ == '\n' )			// end of line
            Packit Service 50c9f2
            	    break;
            Packit Service 50c9f2
                }
            Packit Service 50c9f2
                *p++ = '\0';
            Packit Service 50c9f2
                return (int)((intptr_t)p - (intptr_t)data);
            Packit Service 50c9f2
            }
            Packit Service 50c9f2
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn int QIODevice::getch()
            Packit Service 50c9f2
            Packit Service 50c9f2
              Reads a single byte/character from the I/O device.
            Packit Service 50c9f2
            Packit Service 50c9f2
              Returns the byte/character read, or -1 if the end of the I/O device has been
            Packit Service 50c9f2
              reached.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function must be reimplemented by all subclasses.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa putch(), ungetch()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn int QIODevice::putch( int ch )
            Packit Service 50c9f2
            Packit Service 50c9f2
              Writes the character \e ch to the I/O device.
            Packit Service 50c9f2
            Packit Service 50c9f2
              Returns \e ch, or -1 if some error occurred.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function must be reimplemented by all subclasses.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa getch(), ungetch()
            Packit Service 50c9f2
            */
            Packit Service 50c9f2
            Packit Service 50c9f2
            /*!
            Packit Service 50c9f2
              \fn int QIODevice::ungetch( int ch )
            Packit Service 50c9f2
            Packit Service 50c9f2
              Puts the character \e ch back into the I/O device and decrements the
            Packit Service 50c9f2
              index if it is not zero.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This function is normally called to "undo" a getch() operation.
            Packit Service 50c9f2
            Packit Service 50c9f2
              Returns \e ch, or -1 if some error occurred.
            Packit Service 50c9f2
            Packit Service 50c9f2
              This virtual function must be reimplemented by all subclasses.
            Packit Service 50c9f2
            Packit Service 50c9f2
              \sa getch(), putch()
            Packit Service 50c9f2
            */