lib
KoStoreDevice.h
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000 David Faure <faure@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef koStoreDevice_h 00021 #define koStoreDevice_h 00022 00023 #include <KoStore.h> 00024 00030 class KoStoreDevice : public QIODevice 00031 { 00032 public: 00034 KoStoreDevice( KoStore * store ) : m_store(store) { 00035 setType( IO_Direct ); 00036 } 00037 ~KoStoreDevice() {} 00038 00039 bool open( int m ) { 00040 if ( m & IO_ReadOnly ) 00041 return ( m_store->mode() == KoStore::Read ); 00042 if ( m & IO_WriteOnly ) 00043 return ( m_store->mode() == KoStore::Write ); 00044 return false; 00045 } 00046 void close() { } 00047 void flush() { } 00048 00049 Offset size() const { 00050 if ( m_store->mode() == KoStore::Read ) 00051 return m_store->size(); 00052 else 00053 return 0xffffffff; 00054 } 00055 00056 virtual Q_LONG readBlock( char *data, Q_ULONG maxlen ) { return m_store->read(data, maxlen); } 00057 virtual Q_LONG writeBlock( const char *data, Q_ULONG len ) { return m_store->write( data, len ); } 00058 // Not virtual, only to uncover shadow 00059 Q_LONG writeBlock( const QByteArray& data ) { return QIODevice::writeBlock( data ); } 00060 00061 int getch() { 00062 char c[2]; 00063 if ( m_store->read(c, 1) == -1) 00064 return -1; 00065 else 00066 return c[0]; 00067 } 00068 int putch( int _c ) { 00069 char c[2]; 00070 c[0] = _c; 00071 c[1] = 0; 00072 if (m_store->write( c, 1 ) == 1) 00073 return _c; 00074 else 00075 return -1; 00076 } 00077 int ungetch( int ) { return -1; } // unsupported 00078 00079 // See QIODevice 00080 virtual bool at( Offset pos ) { return m_store->at(pos); } 00081 virtual Offset at() const { return m_store->at(); } 00082 virtual bool atEnd() const { return m_store->atEnd(); } 00083 00084 protected: 00085 KoStore * m_store; 00086 }; 00087 00088 #endif

