QIODevice.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                                Base i/o device                                *
00004 *                                                                               *
00005 *********************************************************************************
00006 *        Copyright (C) 2003 by Niall Douglas.   All Rights Reserved.            *
00007 *       NOTE THAT I DO NOT PERMIT ANY OF MY CODE TO BE PROMOTED TO THE GPL      *
00008 *********************************************************************************
00009 * This code is free software; you can redistribute it and/or modify it under    *
00010 * the terms of the GNU Library General Public License v2.1 as published by the  *
00011 * Free Software Foundation EXCEPT that clause 3 does not apply ie; you may not  *
00012 * "upgrade" this code to the GPL without my prior written permission.           *
00013 * Please consult the file "License_Addendum2.txt" accompanying this file.       *
00014 *                                                                               *
00015 * This code is distributed in the hope that it will be useful,                  *
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                          *
00018 *********************************************************************************
00019 * $Id:                                                                          *
00020 ********************************************************************************/
00021 
00022 #ifndef QIODEVICE_H
00023 #define QIODEVICE_H
00024 
00025 #include "fxdefs.h"
00026 
00027 namespace FX {
00028 
00040 class FXACL;
00041 
00043 enum QIODeviceFlags
00044 {
00045     IO_ReadOnly=    0x0001,     
00046     IO_WriteOnly=   0x0002,     
00047     IO_ReadWrite=   0x0003,     
00048     IO_Append=      0x0004,     
00049     IO_Truncate=    0x0008,     
00050 
00055     IO_Translate=   0x0010,
00059     IO_ShredTruncate=0x080,
00060     IO_ModeMask=    0x00ff,     
00061 
00062     IO_Raw=         0x0100,     
00063     IO_QuietSocket= 0x0200,     
00064     IO_DontUnlink=  0x0400,     
00065     IO_NoAutoUTF=   0x0800,     
00066     IO_Open=        0x1000,     
00067     IO_StateMask=   0xf000      
00068 };
00069 
00127 class FXAPI QIODevice
00128 {
00129 public:
00130     typedef FXfval Offset;
00132     enum CRLFType
00133     {
00134         Default=0,          
00135         Unix=1,             
00136         MacOS=2,            
00137         MSDOS=3             
00138     };
00140     enum UnicodeType
00141     {
00142         NoTranslation=0,    
00143         UTF8=1,             
00144         UTF16=2,            
00145         UTF16LE=3,          
00146         UTF32=4,            
00147         UTF32LE=5           
00148     };
00149 private:
00150     FXuint mymode;
00151     CRLFType myCRLFType;
00152     UnicodeType myUnicodeType;
00153 protected:
00154     QIODevice(const QIODevice &o) : mymode(o.mymode), myCRLFType(Default), myUnicodeType(NoTranslation), ioIndex(o.ioIndex) { }
00155     QIODevice &operator=(const QIODevice &o) { mymode=o.mymode; myCRLFType=o.myCRLFType; myUnicodeType=o.myUnicodeType; ioIndex=o.ioIndex; return *this; }
00156     FXfval ioIndex;
00157 public:
00158     QIODevice() : mymode(0), myCRLFType(Default), myUnicodeType(NoTranslation), ioIndex(0) { }
00159     virtual ~QIODevice() { }
00160 
00162     FXuint flags() const { return mymode; }
00164     FXuint mode() const { return mymode & IO_ModeMask; }
00166     FXuint state() const { return mymode & IO_StateMask; }
00168     CRLFType crlfFormat() const { return myCRLFType; }
00170     void setCRLFFormat(CRLFType type) { myCRLFType=type; }
00172     UnicodeType unicodeTranslation() const { return myUnicodeType; }
00174     void setUnicodeTranslation(UnicodeType type) { myUnicodeType=type; }
00176     bool isBuffered() const { return IO_Raw!=(mymode & IO_Raw); }
00178     bool isRaw() const { return IO_Raw==(mymode & IO_Raw); }
00180     bool isTranslated() const { return IO_Translate==(mymode & IO_Translate); }
00182     bool isUTF16Translated() const { return isTranslated() && UTF16==(myUnicodeType & UTF16); }
00184     bool isUTF32Translated() const { return isTranslated() && UTF32==(myUnicodeType & UTF32); }
00186     bool isReadable() const { return IO_ReadOnly==(mymode & IO_ReadOnly); }
00188     bool isWriteable() const { return IO_WriteOnly==(mymode & IO_WriteOnly); }
00190     bool isWritable() const { return isWriteable(); }
00192     bool isReadWrite() const { return IO_ReadWrite==(mymode & IO_ReadWrite); }
00194     bool isClosed() const { return IO_Open!=(mymode & IO_Open); }
00196     bool isInactive() const { return isClosed(); }
00198     bool isOpen() const { return IO_Open==(mymode & IO_Open); }
00200     virtual bool isSynchronous() const { return false; }
00201 
00203     virtual bool open(FXuint mode)=0;
00205     virtual void close()=0;
00207     virtual void flush()=0;
00209     virtual FXfval size() const=0;
00214     virtual void truncate(FXfval size)=0;
00219     virtual FXfval at() const;
00224     virtual bool at(FXfval newpos);
00226     virtual bool atEnd() const;
00228     virtual const FXACL &permissions() const;
00230     virtual void setPermissions(const FXACL &);
00231 
00236     virtual FXuval readBlock(char *data, FXuval maxlen)=0;
00238     FXuval readBlock(FXuchar *data, FXuval maxlen) { return readBlock((char *) data, maxlen); }
00243     virtual FXuval writeBlock(const char *data, FXuval maxlen)=0;
00245     FXuval writeBlock(const FXuchar *data, FXuval maxlen) { return writeBlock((char *) data, maxlen); }
00247     virtual FXuval readLine(char *data, FXuval maxlen);
00250     virtual FXuval readBlockFrom(char *data, FXuval maxlen, FXfval pos)=0;
00252     FXuval readBlockFrom(FXuchar *data, FXuval maxlen, FXfval pos) { return readBlockFrom((char *) data, maxlen, pos); }
00255     virtual FXuval writeBlockTo(FXfval pos, const char *data, FXuval maxlen)=0;
00257     FXuval writeBlockTo(FXfval pos, const FXuchar *data, FXuval maxlen) { return writeBlockTo(pos, (char *) data, maxlen); }
00258 
00260     virtual int getch();
00262     virtual int putch(int c);
00264     virtual int ungetch(int c)=0;
00265 public:
00269     static UnicodeType determineUnicodeType(FXuchar *data, FXuval len) throw();
00276     static FXuval applyCRLF(FXuchar *FXRESTRICT output, const FXuchar *FXRESTRICT input, FXuval outputlen, FXuval &inputlen, CRLFType crlftype=Default, UnicodeType utftype=NoTranslation);
00285     static FXuval removeCRLF(FXuchar *FXRESTRICT output, const FXuchar *FXRESTRICT input, FXuval outputlen, FXuval &inputlen, UnicodeType utftype=NoTranslation);
00290     FXfval shredData(FXfval offset, FXfval len=(FXfval)-1);
00291 protected:
00293     void setFlags(int f) { mymode=f; }
00295     void setMode(int m) { mymode=(mymode & ~IO_ModeMask)|m; }
00297     void setState(int s) { mymode=(mymode & ~IO_StateMask)|s; }
00298     friend FXAPI FXStream &operator<<(FXStream &s, QIODevice &i);
00299     friend FXAPI FXStream &operator>>(FXStream &s, QIODevice &i);
00300 };
00301 
00305 FXAPI FXStream &operator<<(FXStream &s, QIODevice &i);
00310 FXAPI FXStream &operator>>(FXStream &s, QIODevice &i);
00311 
00312 
00313 } // namespace
00314 
00315 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:25 2009 for TnFOX by doxygen v1.4.7