• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
klimitediodevice.h
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001, 2002 David Faure <david@mandrakesoft.com>
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 #ifndef klimitediodevice_h
20 #define klimitediodevice_h
21 
22 #include <kdebug.h>
23 #include <tqiodevice.h>
31 class TDEIO_EXPORT KLimitedIODevice : public TQIODevice
32 {
33 public:
41  KLimitedIODevice( TQIODevice *dev, int start, int length )
42  : m_dev( dev ), m_start( start ), m_length( length )
43  {
44  //kdDebug(7005) << "KLimitedIODevice::KLimitedIODevice start=" << start << " length=" << length << endl;
45  setType( IO_Direct ); // we support sequential too, but then atEnd() tries getch/ungetch !
46  open( IO_ReadOnly );
47  }
48  virtual ~KLimitedIODevice() {}
49 
50  virtual bool open( TQ_OpenMode m ) {
51  //kdDebug(7005) << "KLimitedIODevice::open m=" << m << endl;
52  if ( m & IO_ReadOnly ) {
53  /*bool ok = false;
54  if ( m_dev->isOpen() )
55  ok = ( m_dev->mode() == IO_ReadOnly );
56  else
57  ok = m_dev->open( m );
58  if ( ok )*/
59  m_dev->at( m_start ); // No concurrent access !
60  }
61  else
62  kdWarning(7005) << "KLimitedIODevice::open only supports IO_ReadOnly!" << endl;
63  setState( IO_Open );
64  setMode( m );
65  return true;
66  }
67  virtual void close() {}
68  virtual void flush() {}
69 
70 #ifdef USE_QT4
71  virtual qint64 size() const { return m_length; }
72 #else // USE_QT4
73  virtual Offset size() const { return m_length; }
74 #endif // USE_QT4
75 
76  virtual TQT_TQIO_LONG tqreadBlock ( char * data, TQT_TQIO_ULONG maxlen )
77  {
78  maxlen = TQMIN( maxlen, m_length - at() ); // Apply upper limit
79  return m_dev->readBlock( data, maxlen );
80  }
81  virtual TQT_TQIO_LONG tqwriteBlock ( const char *, TQT_TQIO_ULONG ) { return -1; } // unsupported
82  virtual int putch( int ) { return -1; } // unsupported
83 
84  virtual int getch() {
85  char c[2];
86  if ( tqreadBlock(c, 1) == -1)
87  return -1;
88  else
89  return c[0];
90  }
91  virtual int ungetch( int c ) { return m_dev->ungetch(c); } // ## apply lower limit ?
92  virtual Offset at() const { return m_dev->at() - m_start; }
93  virtual bool at( Offset pos ) {
94  Q_ASSERT( pos <= m_length );
95  pos = TQMIN( pos, m_length ); // Apply upper limit
96  return m_dev->at( m_start + pos );
97  }
98  virtual bool atEnd() const { return m_dev->atEnd() || m_dev->at() >= m_start + m_length; }
99 private:
100  TQIODevice* m_dev;
101  TQ_ULONG m_start;
102  TQ_ULONG m_length;
103 };
104 
105 #endif
KLimitedIODevice::KLimitedIODevice
KLimitedIODevice(TQIODevice *dev, int start, int length)
Creates a new KLimitedIODevice.
Definition: klimitediodevice.h:41
KLimitedIODevice
A readonly device that reads from an underlying device from a given point to another (e...
Definition: klimitediodevice.h:31

tdeio/tdeio

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

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.8.8
This website is maintained by Timothy Pearson.