home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qiodevice.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  6KB  |  169 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qiodevice.h   3.0.0   edited Aug 8 16:22 $
  3. **
  4. ** Definition of QIODevice class
  5. **
  6. ** Created : 940913
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the tools module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QIODEVICE_H
  39. #define QIODEVICE_H
  40.  
  41. #ifndef QT_H
  42. #ifdef QT_LARGE_FILE_SUPPORT
  43. // ### Should be included first. This is a problem in the current
  44. // ### "qplatformdefs.h" strategy which is OK for source files but
  45. // ### not for header files. Do we need defines back in qmake.conf?
  46. #define _FILE_OFFSET_BITS 64
  47. #include "qplatformdefs.h"
  48. #endif
  49. #include "qglobal.h"
  50. #include "qcstring.h"
  51. #endif // QT_H
  52.  
  53.  
  54. // IO device access types
  55.  
  56. #define IO_Direct        0x0100        // direct access device
  57. #define IO_Sequential        0x0200        // sequential access device
  58. #define IO_Combined        0x0300        // combined direct/sequential
  59. #define IO_TypeMask        0x0f00
  60.  
  61. // IO handling modes
  62.  
  63. #define IO_Raw            0x0040        // raw access (not buffered)
  64. #define IO_Async        0x0080        // asynchronous mode
  65.  
  66. // IO device open modes
  67.  
  68. #define IO_ReadOnly        0x0001        // readable device
  69. #define IO_WriteOnly        0x0002        // writable device
  70. #define IO_ReadWrite        0x0003        // read+write device
  71. #define IO_Append        0x0004        // append
  72. #define IO_Truncate        0x0008        // truncate device
  73. #define IO_Translate        0x0010        // translate CR+LF
  74. #define IO_ModeMask        0x00ff
  75.  
  76. // IO device state
  77.  
  78. #define IO_Open            0x1000        // device is open
  79. #define IO_StateMask        0xf000
  80.  
  81.  
  82. // IO device status
  83.  
  84. #define IO_Ok            0
  85. #define IO_ReadError        1        // read error
  86. #define IO_WriteError        2        // write error
  87. #define IO_FatalError        3        // fatal unrecoverable error
  88. #define IO_ResourceError    4        // resource limitation
  89. #define IO_OpenError        5        // cannot open device
  90. #define IO_ConnectError        5        // cannot connect to device
  91. #define IO_AbortError        6        // abort error
  92. #define IO_TimeOutError        7        // time out
  93. #define IO_UnspecifiedError    8        // unspecified error
  94.  
  95. class Q_EXPORT QIODevice            // IO device class
  96. {
  97. public:
  98. #ifdef QT_LARGE_FILE_SUPPORT
  99.     typedef off_t Offset;
  100. #else
  101.     typedef Q_ULONG Offset;
  102. #endif
  103.  
  104.     QIODevice();
  105.     virtual ~QIODevice();
  106.  
  107.     int         flags()  const { return ioMode; }
  108.     int         mode()      const { return ioMode & IO_ModeMask; }
  109.     int         state()  const { return ioMode & IO_StateMask; }
  110.  
  111.     bool     isDirectAccess()     const { return ((ioMode & IO_Direct)     == IO_Direct); }
  112.     bool     isSequentialAccess() const { return ((ioMode & IO_Sequential) == IO_Sequential); }
  113.     bool     isCombinedAccess()   const { return ((ioMode & IO_Combined)   == IO_Combined); }
  114.     bool     isBuffered()          const { return ((ioMode & IO_Raw)        != IO_Raw); }
  115.     bool     isRaw()          const { return ((ioMode & IO_Raw)        == IO_Raw); }
  116.     bool     isSynchronous()      const { return ((ioMode & IO_Async)      != IO_Async); }
  117.     bool     isAsynchronous()     const { return ((ioMode & IO_Async)      == IO_Async); }
  118.     bool     isTranslated()          const { return ((ioMode & IO_Translate)  == IO_Translate); }
  119.     bool     isReadable()          const { return ((ioMode & IO_ReadOnly)   == IO_ReadOnly); }
  120.     bool     isWritable()          const { return ((ioMode & IO_WriteOnly)  == IO_WriteOnly); }
  121.     bool     isReadWrite()          const { return ((ioMode & IO_ReadWrite)  == IO_ReadWrite); }
  122.     bool     isInactive()          const { return state() == 0; }
  123.     bool     isOpen()          const { return state() == IO_Open; }
  124.  
  125.     int         status() const { return ioSt; }
  126.     void     resetStatus()    { ioSt = IO_Ok; }
  127.  
  128.     virtual bool open( int mode ) = 0;
  129.     virtual void close() = 0;
  130.     virtual void flush() = 0;
  131.  
  132.     virtual Offset size()  const = 0;
  133.     virtual Offset at()  const;
  134.     virtual bool at( Offset );
  135.     virtual bool atEnd()  const;
  136.     bool     reset() { return at(0); }
  137.  
  138.     virtual Q_LONG readBlock( char *data, Q_ULONG maxlen ) = 0;
  139.     virtual Q_LONG writeBlock( const char *data, Q_ULONG len ) = 0;
  140.     virtual Q_LONG readLine( char *data, Q_ULONG maxlen );
  141.     Q_LONG writeBlock( const QByteArray& data );
  142.     virtual QByteArray readAll();
  143.  
  144.     virtual int     getch() = 0;
  145.     virtual int     putch( int ) = 0;
  146.     virtual int     ungetch( int ) = 0;
  147.  
  148. protected:
  149.     void     setFlags( int f ) { ioMode = f; }
  150.     void     setType( int );
  151.     void     setMode( int );
  152.     void     setState( int );
  153.     void     setStatus( int );
  154.     Offset     ioIndex;
  155.  
  156. private:
  157.     int         ioMode;
  158.     int         ioSt;
  159.  
  160. private:    // Disabled copy constructor and operator=
  161. #if defined(Q_DISABLE_COPY)
  162.     QIODevice( const QIODevice & );
  163.     QIODevice &operator=( const QIODevice & );
  164. #endif
  165. };
  166.  
  167.  
  168. #endif // QIODEVICE_H
  169.