• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIO

klimitediodevice.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2001, 2002, 2007 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 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., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "klimitediodevice.h"
00020 
00021 KLimitedIODevice::KLimitedIODevice( QIODevice *dev, int start, int length )
00022     : m_dev( dev ), m_start( start ), m_length( length )
00023 {
00024     //kDebug(7005) << "start=" << start << "length=" << length;
00025     open( QIODevice::ReadOnly ); //krazy:exclude=syscalls
00026 }
00027 
00028 bool KLimitedIODevice::open( QIODevice::OpenMode m )
00029 {
00030     //kDebug(7005) << "m=" << m;
00031     if ( m & QIODevice::ReadOnly ) {
00032         /*bool ok = false;
00033           if ( m_dev->isOpen() )
00034           ok = ( m_dev->mode() == QIODevice::ReadOnly );
00035           else
00036           ok = m_dev->open( m );
00037           if ( ok )*/
00038         m_dev->seek( m_start ); // No concurrent access !
00039     }
00040     else
00041         kWarning(7005) << "KLimitedIODevice::open only supports QIODevice::ReadOnly!";
00042     setOpenMode( QIODevice::ReadOnly );
00043     return true;
00044 }
00045 
00046 void KLimitedIODevice::close()
00047 {
00048 }
00049 
00050 qint64 KLimitedIODevice::size() const
00051 {
00052     return m_length;
00053 }
00054 
00055 qint64 KLimitedIODevice::readData( char * data, qint64 maxlen )
00056 {
00057     maxlen = qMin( maxlen, m_length - pos() ); // Apply upper limit
00058     return m_dev->read( data, maxlen );
00059 }
00060 
00061 bool KLimitedIODevice::seek( qint64 pos )
00062 {
00063     Q_ASSERT( pos <= m_length );
00064     pos = qMin( pos, m_length ); // Apply upper limit
00065     return m_dev->seek( m_start + pos );
00066 }
00067 
00068 qint64 KLimitedIODevice::bytesAvailable() const
00069 {
00070      return m_length + QIODevice::bytesAvailable();
00071 }
00072 
00073 bool KLimitedIODevice::isSequential() const
00074 {
00075     return m_dev->isSequential();
00076 }

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal