lib Library API Documentation

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., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef koStoreDevice_h
00021 #define koStoreDevice_h
00022 
00023 #include <koStore.h>
00024 
00025 // ### TODO: KOffice 1.4: allow writeBlock(const QByteArray&) and readLine
00026 // ### TODO:   writeBlock is shadowed by the other writeBlock 
00027 // ### TODO:   readLine is disabled for no good reason (QIODevice can do it alone.)
00028 
00034 class KoStoreDevice : public QIODevice
00035 {
00036 public:
00037   // Note: KoStore::open() should be called before calling this.
00038   KoStoreDevice( KoStore * store ) : m_store(store) {
00039       setType( IO_Direct );
00040   }
00041   ~KoStoreDevice() {}
00042 
00043   bool open( int m ) {
00044     if ( m & IO_ReadOnly )
00045       return ( m_store->mode() == KoStore::Read );
00046     if ( m & IO_WriteOnly )
00047       return ( m_store->mode() == KoStore::Write );
00048     return false;
00049   }
00050   void close() { }
00051   void flush() { }
00052 
00053   Offset size() const {
00054     if ( m_store->mode() == KoStore::Read )
00055       return m_store->size();
00056     else
00057       return 0xffffffff;
00058   }
00059 
00060   Q_LONG readBlock( char *data, Q_ULONG maxlen ) { return m_store->read(data, maxlen); }
00061   Q_LONG writeBlock( const char *data, Q_ULONG len ) { return m_store->write( data, len ); }
00062   Q_LONG readLine( char *, Q_ULONG  ) { return -1; } // unsupported
00063 
00064   int getch() {
00065     char c[2];
00066     if ( m_store->read(c, 1) == -1)
00067       return -1;
00068     else
00069       return c[0];
00070   }
00071   int putch( int _c ) {
00072     char c[2];
00073     c[0] = _c;
00074     c[1] = 0;
00075     if (m_store->write( c, 1 ) == 1)
00076       return _c;
00077     else
00078       return -1;
00079   }
00080   int ungetch( int ) { return -1; } // unsupported
00081 
00082   // See QIODevice
00083   virtual bool at( Offset pos ) { return m_store->at(pos); }
00084   virtual Offset at() const { return m_store->at(); }
00085   virtual bool atEnd() const { return m_store->atEnd(); }
00086 
00087 protected:
00088   KoStore * m_store;
00089 };
00090 
00091 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 13:19:25 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2003