00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef QIODEVICE_H
00039 #define QIODEVICE_H
00040
00041 #ifndef QT_H
00042 #include "qglobal.h"
00043 #include "qcstring.h"
00044 #endif // QT_H
00045
00046
00047
00048
00049 #define IO_Direct 0x0100 // direct access device
00050 #define IO_Sequential 0x0200 // sequential access device
00051 #define IO_Combined 0x0300 // combined direct/sequential
00052 #define IO_TypeMask 0x0f00
00053
00054
00055
00056 #define IO_Raw 0x0040 // raw access (not buffered)
00057 #define IO_Async 0x0080 // asynchronous mode
00058
00059
00060
00061 #define IO_ReadOnly 0x0001 // readable device
00062 #define IO_WriteOnly 0x0002 // writable device
00063 #define IO_ReadWrite 0x0003 // read+write device
00064 #define IO_Append 0x0004 // append
00065 #define IO_Truncate 0x0008 // truncate device
00066 #define IO_Translate 0x0010 // translate CR+LF
00067 #define IO_ModeMask 0x00ff
00068
00069
00070
00071 #define IO_Open 0x1000 // device is open
00072 #define IO_StateMask 0xf000
00073
00074
00075
00076 #define IO_Ok 0
00077 #define IO_ReadError 1 // read error
00078 #define IO_WriteError 2 // write error
00079 #define IO_FatalError 3 // fatal unrecoverable error
00080 #define IO_ResourceError 4 // resource limitation
00081 #define IO_OpenError 5 // cannot open device
00082 #define IO_ConnectError 5 // cannot connect to device
00083 #define IO_AbortError 6 // abort error
00084 #define IO_TimeOutError 7 // time out
00085 #define IO_UnspecifiedError 8 // unspecified error
00086
00087
00088 class Q_EXPORT QIODevice
00089 {
00090 public:
00091 #if defined(QT_ABI_64BITOFFSET)
00092 typedef QtOffset Offset;
00093 #else
00094 typedef Q_ULONG Offset;
00095 #endif
00096
00097 QIODevice();
00098 virtual ~QIODevice();
00099
00100 int flags() const { return ioMode; }
00101 int mode() const { return ioMode & IO_ModeMask; }
00102 int state() const { return ioMode & IO_StateMask; }
00103
00104 bool isDirectAccess() const { return ((ioMode & IO_Direct) == IO_Direct); }
00105 bool isSequentialAccess() const { return ((ioMode & IO_Sequential) == IO_Sequential); }
00106 bool isCombinedAccess() const { return ((ioMode & IO_Combined) == IO_Combined); }
00107 bool isBuffered() const { return ((ioMode & IO_Raw) != IO_Raw); }
00108 bool isRaw() const { return ((ioMode & IO_Raw) == IO_Raw); }
00109 bool isSynchronous() const { return ((ioMode & IO_Async) != IO_Async); }
00110 bool isAsynchronous() const { return ((ioMode & IO_Async) == IO_Async); }
00111 bool isTranslated() const { return ((ioMode & IO_Translate) == IO_Translate); }
00112 bool isReadable() const { return ((ioMode & IO_ReadOnly) == IO_ReadOnly); }
00113 bool isWritable() const { return ((ioMode & IO_WriteOnly) == IO_WriteOnly); }
00114 bool isReadWrite() const { return ((ioMode & IO_ReadWrite) == IO_ReadWrite); }
00115 bool isInactive() const { return state() == 0; }
00116 bool isOpen() const { return state() == IO_Open; }
00117
00118 int status() const { return ioSt; }
00119 void resetStatus() { ioSt = IO_Ok; }
00120
00121 virtual bool open( int mode ) = 0;
00122 virtual void close() = 0;
00123 virtual void flush() = 0;
00124
00125 virtual Offset size() const = 0;
00126 virtual Offset at() const;
00127 virtual bool at( Offset );
00128 virtual bool atEnd() const;
00129 bool reset() { return at(0); }
00130
00131 virtual Q_LONG readBlock( char *data, Q_ULONG maxlen ) = 0;
00132 virtual Q_LONG writeBlock( const char *data, Q_ULONG len ) = 0;
00133 virtual Q_LONG readLine( char *data, Q_ULONG maxlen );
00134 Q_LONG writeBlock( const QByteArray& data );
00135 virtual QByteArray readAll();
00136
00137 virtual int getch() = 0;
00138 virtual int putch( int ) = 0;
00139 virtual int ungetch( int ) = 0;
00140
00141 protected:
00142 void setFlags( int f ) { ioMode = f; }
00143 void setType( int );
00144 void setMode( int );
00145 void setState( int );
00146 void setStatus( int );
00147 Offset ioIndex;
00148
00149 private:
00150 int ioMode;
00151 int ioSt;
00152
00153 private:
00154 #if defined(Q_DISABLE_COPY)
00155 QIODevice( const QIODevice & );
00156 QIODevice &operator=( const QIODevice & );
00157 #endif
00158 };
00159
00160
00161 #endif // QIODEVICE_H