⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qiodevice.cpp

📁 doxygen(一个自动从源代码生成文档的工具)的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** $Id: qt/src/tools/qiodevice.cpp   2.2.3   edited 2000-09-05 $**** Implementation of QIODevice class**** Created : 940913**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of the tools module of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qiodevice.h"// NOT REVISED/*!  \class QIODevice qiodevice.h  \brief The QIODevice class is the base class of I/O devices.  \ingroup io  An I/O device represents a medium that one can read bytes from  and/or write bytes to.  The QIODevice class is the abstract  superclass of all such devices; classes like QFile, QBuffer and  QSocket inherit QIODevice and implement virtual functions like  write() appropriately.  While applications sometimes use QIODevice directly, mostly it is  better to go through QTextStream and QDataStream, which provide  stream operations on any QIODevice subclass.  QTextStream provides  text-oriented stream functionality (for human-readable ASCII files,  for example), while QDataStream deals with binary data in a totally  platform-independent manner.  The public member functions in QIODevice roughly fall into two  groups: The action functions and the state access functions.  The  most important action functions are: <ul>  <li> open() opens a device for reading and/or writing, depending on  the argument to open().  <li> close() closes the device and tidies up.  <li> readBlock() reads a block of data from the device.  <li> writeBlock() writes a block of data to the device.  <li> readLine() reads a line (of text, usually) from the device.  <li> flush() ensures that all buffered data are written to the real device.  </ul>There are also some other, less used, action functions: <ul>  <li> getch() reads a single character.  <li> ungetch() forgets the last call to getch(), if possible.  <li> putch() writes a single character.  <li> size() returns the size of the device, if there is one.  <li> at() returns the current read/write pointer, if there is one  for this device, or it moves the pointer.  <li> atEnd() says whether there is more to read, if that is a  meaningful question for this device.  <li> reset() moves the read/write pointer to the start of the  device, if that is possible for this device.  </ul>The state access are all "get" functions.  The QIODevice subclass  calls setState() to update the state, and simple access functions  tell the user of the device what the device's state is.  Here are  the settings, and their associated access functions: <ul>  <li> Access type.  Some devices are direct access (it is possible to  read/write anywhere) while others are sequential.  QIODevice  provides the access functions isDirectAccess(), isSequentialAccess()  and isCombinedAccess() to tell users what a given I/O device  supports.  <li> Buffering.  Some devices are accessed in raw mode while others  are buffered.  Buffering usually provides greater efficiency,  particularly for small read/write operations.  isBuffered() tells  the user whether a given device is buffered.  (This can often be set  by the application in the call to open().)  <li> Synchronicity.  Synchronous devices work there and then, for  example files.  When you read from a file, the file delivers its  data right away.  Others, such as a socket connected to a HTTP  server, may not deliver the data until seconds after you ask to read  it.  isSynchronous() and isAsynchronous() tells the user how this  device operates.  <li> CR/LF translation.  For simplicity, applications often like to  see just a single CR/LF style, and QIODevice subclasses can provide  that.  isTranslated() returns TRUE if this object translates CR/LF  to just LF.  (This can often be set by the application in the call  to open().)  <li> Accessibility.  Some files cannot be written, for example.  isReadable(), isWritable and isReadWrite() tells the application  whether it can read from and write to a given device.  (This can  often be set by the application in the call to open().)  <li> Finally, isOpen() returns TRUE if the device is open.  This can  quite obviously be set using open() :)  </ul>  QIODevice provides numerous pure virtual functions you need to  implement when subclassing it.  Here is a skeleton subclass with all  the members you are certain to need, and some it's likely that you  will need:  \code    class YourDevice : public QIODevice    {    public:	YourDevice();       ~YourDevice();	bool open( int mode );	void close();	void flush();	uint size() const;	int  at() const;	// not a pure virtual function	bool at( int );		// not a pure virtual function	bool atEnd() const;	// not a pure virtual function	int readBlock( char *data, uint maxlen );	int writeBlock( const char *data, uint len );	int readLine( char *data, uint maxlen );	int getch();	int putch( int );	int ungetch( int );    };  \endcode  The three non-pure virtual functions can be ignored if your device  is sequential (e.g. an RS-232 port).  \sa QDataStream, QTextStream*//*!  Constructs an I/O device.*/QIODevice::QIODevice(){    ioMode = 0;					// initial mode    ioSt = IO_Ok;    ioIndex = 0;}/*!  Destructs the I/O device.*/QIODevice::~QIODevice(){}/*!  \fn int QIODevice::flags() const  Returns the current I/O device flags setting.  Flags consists of mode flags and state flags.  \sa mode(), state()*//*!  \fn int QIODevice::mode() const  Returns bits OR'ed together that specify the current operation mode.  These are the flags that were given to the open() function.  The flags are: \c IO_ReadOnly, \c IO_WriteOnly, \c IO_ReadWrite,  \c IO_Append, \c IO_Truncate and \c IO_Translate.*//*!  \fn int QIODevice::state() const  Returns bits OR'ed together that specify the current state.  The flags are: \c IO_Open.  Subclasses may define more flags.*//*!  \fn bool QIODevice::isDirectAccess() const  Returns TRUE if the I/O device is a direct access (not sequential) device,  otherwise FALSE.  \sa isSequentialAccess()*//*!  \fn bool QIODevice::isSequentialAccess() const  Returns TRUE if the I/O device is a sequential access (not direct) device,  otherwise FALSE.  Operations involving size() and at(int) are not valid  on sequential devices.  \sa isDirectAccess()*//*!  \fn bool QIODevice::isCombinedAccess() const  Returns TRUE if the I/O device is a combined access (both direct and  sequential) device,  otherwise FALSE.  This access method is currently not in use.*//*!  \fn bool QIODevice::isBuffered() const  Returns TRUE if the I/O device is a buffered (not raw) device, otherwise  FALSE.  \sa isRaw()*//*!  \fn bool QIODevice::isRaw() const  Returns TRUE if the I/O device is a raw (not buffered) device, otherwise  FALSE.  \sa isBuffered()*//*!  \fn bool QIODevice::isSynchronous() const  Returns TRUE if the I/O device is a synchronous device, otherwise  FALSE.  \sa isAsynchronous()*//*!  \fn bool QIODevice::isAsynchronous() const  Returns TRUE if the I/O device is a asynchronous device, otherwise  FALSE.  This mode is currently not in use.  \sa isSynchronous()*//*!  \fn bool QIODevice::isTranslated() const  Returns TRUE if the I/O device translates carriage-return and linefeed  characters.  A QFile is translated if it is opened with the \c IO_Translate mode  flag.*//*!  \fn bool QIODevice::isReadable() const  Returns TRUE if the I/O device was opened using \c IO_ReadOnly or  \c IO_ReadWrite mode.  \sa isWritable(), isReadWrite()*//*!  \fn bool QIODevice::isWritable() const  Returns TRUE if the I/O device was opened using \c IO_WriteOnly or  \c IO_ReadWrite mode.  \sa isReadable(), isReadWrite()*//*!  \fn bool QIODevice::isReadWrite() const  Returns TRUE if the I/O device was opened using \c IO_ReadWrite mode.  \sa isReadable(), isWritable()*//*!  \fn bool QIODevice::isInactive() const  Returns TRUE if the I/O device state is 0, i.e. the device is not open.  \sa isOpen()*//*!  \fn bool QIODevice::isOpen() const  Returns TRUE if the I/O device state has been opened, otherwise FALSE.  \sa isInactive()*//*!  \fn int QIODevice::status() const

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -