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

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • 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 
21 KLimitedIODevice::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 
28 bool 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 
46 void KLimitedIODevice::close()
47 {
48 }
49 
50 qint64 KLimitedIODevice::size() const
51 {
52  return m_length;
53 }
54 
55 qint64 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 
61 bool 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 
72 qint64 KLimitedIODevice::bytesAvailable() const
73 {
74  return QIODevice::bytesAvailable();
75 }
76 
77 bool KLimitedIODevice::isSequential() const
78 {
79  return m_dev->isSequential();
80 }
KLimitedIODevice::seek
virtual bool seek(qint64 pos)
Definition: klimitediodevice.cpp:61
qint64
KLimitedIODevice::readData
virtual qint64 readData(char *data, qint64 maxlen)
Definition: klimitediodevice.cpp:55
KLimitedIODevice::close
virtual void close()
Definition: klimitediodevice.cpp:46
klimitediodevice_p.h
kWarning
#define kWarning
Definition: kdebug.h:322
KLimitedIODevice::bytesAvailable
virtual qint64 bytesAvailable() const
Definition: klimitediodevice.cpp:72
KLimitedIODevice::open
virtual bool open(QIODevice::OpenMode m)
Definition: klimitediodevice.cpp:28
KLimitedIODevice::size
virtual qint64 size() const
Definition: klimitediodevice.cpp:50
QIODevice
KLimitedIODevice::KLimitedIODevice
KLimitedIODevice(QIODevice *dev, qint64 start, qint64 length)
Creates a new KLimitedIODevice.
Definition: klimitediodevice.cpp:21
KLimitedIODevice::isSequential
virtual bool isSequential() const
Definition: klimitediodevice.cpp:77
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:08 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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