• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • io
klimitediodevice.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2001, 2002, 2007 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "klimitediodevice_p.h"
20
21KLimitedIODevice::KLimitedIODevice( QIODevice *dev, qint64 start, qint64 length )
22 : m_dev( dev ), m_start( start ), m_length( length )
23{
24 //kDebug(7005) << "start=" << start << "length=" << length;
25 open( QIODevice::ReadOnly ); //krazy:exclude=syscalls
26}
27
28bool KLimitedIODevice::open( QIODevice::OpenMode m )
29{
30 //kDebug(7005) << "m=" << m;
31 if ( m & QIODevice::ReadOnly ) {
32 /*bool ok = false;
33 if ( m_dev->isOpen() )
34 ok = ( m_dev->mode() == QIODevice::ReadOnly );
35 else
36 ok = m_dev->open( m );
37 if ( ok )*/
38 m_dev->seek( m_start ); // No concurrent access !
39 }
40 else
41 kWarning(7005) << "KLimitedIODevice::open only supports QIODevice::ReadOnly!";
42 setOpenMode( QIODevice::ReadOnly );
43 return true;
44}
45
46void KLimitedIODevice::close()
47{
48}
49
50qint64 KLimitedIODevice::size() const
51{
52 return m_length;
53}
54
55qint64 KLimitedIODevice::readData( char * data, qint64 maxlen )
56{
57 maxlen = qMin( maxlen, m_length - pos() ); // Apply upper limit
58 return m_dev->read( data, maxlen );
59}
60
61bool KLimitedIODevice::seek( qint64 pos )
62{
63 Q_ASSERT( pos <= m_length );
64 pos = qMin( pos, m_length ); // Apply upper limit
65 bool ret = m_dev->seek( m_start + pos );
66 if ( ret ) {
67 QIODevice::seek( pos );
68 }
69 return ret;
70}
71
72qint64 KLimitedIODevice::bytesAvailable() const
73{
74 return QIODevice::bytesAvailable();
75}
76
77bool KLimitedIODevice::isSequential() const
78{
79 return m_dev->isSequential();
80}
KLimitedIODevice::readData
virtual qint64 readData(char *data, qint64 maxlen)
Definition: klimitediodevice.cpp:55
KLimitedIODevice::KLimitedIODevice
KLimitedIODevice(QIODevice *dev, qint64 start, qint64 length)
Creates a new KLimitedIODevice.
Definition: klimitediodevice.cpp:21
KLimitedIODevice::seek
virtual bool seek(qint64 pos)
Definition: klimitediodevice.cpp:61
KLimitedIODevice::size
virtual qint64 size() const
Definition: klimitediodevice.cpp:50
KLimitedIODevice::isSequential
virtual bool isSequential() const
Definition: klimitediodevice.cpp:77
KLimitedIODevice::open
virtual bool open(QIODevice::OpenMode m)
Definition: klimitediodevice.cpp:28
KLimitedIODevice::bytesAvailable
virtual qint64 bytesAvailable() const
Definition: klimitediodevice.cpp:72
KLimitedIODevice::close
virtual void close()
Definition: klimitediodevice.cpp:46
QIODevice
qint64
kWarning
#define kWarning
Definition: kdebug.h:322
klimitediodevice_p.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal