| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# klimitediodevice.h

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2001, 2002 David Faure <david@mandrakesoft.com>
    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 version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018
    00019 #ifndef klimitediodevice_h
    00020 #define klimitediodevice_h
    00021
    00029 class KLimitedIODevice : public QIODevice
    00030 {
    00031 public:
    00036     KLimitedIODevice( QIODevice *dev, int start, int length )
    00037         : m_dev( dev ), m_start( start ), m_length( length )
    00038     {
    00039         //kdDebug(7005) << "KLimitedIODevice::KLimitedIODevice start=" << start << " length=" << length << endl;
    00040         setType( IO_Direct ); // we support sequential too, but then atEnd() tries getch/ungetch !
    00041         open( IO_ReadOnly );
    00042     }
    00043     virtual ~KLimitedIODevice() {}
    00044
    00045     virtual bool open( int m ) {
    00046         //kdDebug(7005) << "KLimitedIODevice::open m=" << m << endl;
    00047         if ( m & IO_ReadOnly ) {
    00048             /*bool ok = false;
    00049             if ( m_dev->isOpen() )
    00050                 ok = ( m_dev->mode() == IO_ReadOnly );
    00051             else
    00052                 ok = m_dev->open( m );
    00053             if ( ok )*/
    00054                 m_dev->at( m_start ); // No concurrent access !
    00055         }
    00056         else
    00057             kdWarning(7005) << "KLimitedIODevice::open only supports IO_ReadOnly!" << endl;
    00058         setState( IO_Open );
    00059         setMode( m );
    00060         return true;
    00061     }
    00062     virtual void close() {}
    00063     virtual void flush() {}
    00064
    00065     virtual Offset size() const { return m_length; }
    00066
    00067     virtual Q_LONG readBlock ( char * data, Q_ULONG maxlen )
    00068     {
    00069         maxlen = QMIN( maxlen, m_length - at() ); // Apply upper limit
    00070         return m_dev->readBlock( data, maxlen );
    00071     }
    00072     virtual Q_LONG writeBlock ( const char *, Q_ULONG ) { return -1; } // unsupported
    00073     virtual int putch( int ) { return -1; } // unsupported
    00074
    00075     virtual int getch() {
    00076         char c[2];
    00077         if ( readBlock(c, 1) == -1)
    00078             return -1;
    00079         else
    00080             return c[0];
    00081     }
    00082     virtual int ungetch( int c ) { return m_dev->ungetch(c); } // ## apply lower limit ?
    00083     virtual Offset at() const { return m_dev->at() - m_start; }
    00084     virtual bool at( Offset pos ) {
    00085         Q_ASSERT( pos <= m_length );
    00086         pos = QMIN( pos, m_length ); // Apply upper limit
    00087         return m_dev->at( m_start + pos );
    00088     }
    00089     virtual bool atEnd() const { return m_dev->at() >= m_start + m_length; }
    00090 private:
    00091     QIODevice* m_dev;
    00092     Q_ULONG m_start;
    00093     Q_ULONG m_length;
    00094 };
    00095
    00096 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:38 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001