• 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( int 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  virtual Offset size() const { return m_length; }
71 
72  virtual TQ_LONG readBlock ( char * data, TQ_ULONG maxlen )
73  {
74  maxlen = TQMIN( maxlen, m_length - at() ); // Apply upper limit
75  return m_dev->readBlock( data, maxlen );
76  }
77  virtual TQ_LONG writeBlock ( const char *, TQ_ULONG ) { return -1; } // unsupported
78  virtual int putch( int ) { return -1; } // unsupported
79 
80  virtual int getch() {
81  char c[2];
82  if ( readBlock(c, 1) == -1)
83  return -1;
84  else
85  return c[0];
86  }
87  virtual int ungetch( int c ) { return m_dev->ungetch(c); } // ## apply lower limit ?
88  virtual Offset at() const { return m_dev->at() - m_start; }
89  virtual bool at( Offset pos ) {
90  Q_ASSERT( pos <= m_length );
91  pos = TQMIN( pos, m_length ); // Apply upper limit
92  return m_dev->at( m_start + pos );
93  }
94  virtual bool atEnd() const { return m_dev->atEnd() || m_dev->at() >= m_start + m_length; }
95 private:
96  TQIODevice* m_dev;
97  TQ_ULONG m_start;
98  TQ_ULONG m_length;
99 };
100 
101 #endif
KLimitedIODevice
A readonly device that reads from an underlying device from a given point to another (e....
Definition: klimitediodevice.h:32
KLimitedIODevice::KLimitedIODevice
KLimitedIODevice(TQIODevice *dev, int start, int length)
Creates a new KLimitedIODevice.
Definition: klimitediodevice.h:41

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.1
This website is maintained by Timothy Pearson.