klimitediodevice.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#ifndef klimitediodevice_h
00020
#define klimitediodevice_h
00021
00029 class KLimitedIODevice :
public QIODevice
00030 {
00031
public:
00039 KLimitedIODevice(
QIODevice *dev,
int start,
int length )
00040 : m_dev( dev ), m_start( start ), m_length( length )
00041 {
00042
00043 setType( IO_Direct );
00044
open( IO_ReadOnly );
00045 }
00046
virtual ~
KLimitedIODevice() {}
00047
00048
virtual bool open(
int m ) {
00049
00050
if ( m & IO_ReadOnly ) {
00051
00052
00053
00054
00055
00056
00057 m_dev->
at( m_start );
00058 }
00059
else
00060
kdWarning(7005) <<
"KLimitedIODevice::open only supports IO_ReadOnly!" <<
endl;
00061 setState( IO_Open );
00062 setMode( m );
00063
return true;
00064 }
00065
virtual void close() {}
00066
virtual void flush() {}
00067
00068
virtual Offset size()
const {
return m_length; }
00069
00070
virtual Q_LONG
readBlock (
char * data, Q_ULONG maxlen )
00071 {
00072 maxlen = QMIN( maxlen, m_length -
at() );
00073
return m_dev->
readBlock( data, maxlen );
00074 }
00075
virtual Q_LONG
writeBlock (
const char *, Q_ULONG ) {
return -1; }
00076
virtual int putch(
int ) {
return -1; }
00077
00078
virtual int getch() {
00079
char c[2];
00080
if (
readBlock(c, 1) == -1)
00081
return -1;
00082
else
00083
return c[0];
00084 }
00085
virtual int ungetch(
int c ) {
return m_dev->
ungetch(c); }
00086
virtual Offset at()
const {
return m_dev->
at() - m_start; }
00087
virtual bool at( Offset pos ) {
00088 Q_ASSERT( pos <= m_length );
00089 pos = QMIN( pos, m_length );
00090
return m_dev->
at( m_start + pos );
00091 }
00092
virtual bool atEnd()
const {
return m_dev->
at() >= m_start + m_length; }
00093
private:
00094
QIODevice* m_dev;
00095 Q_ULONG m_start;
00096 Q_ULONG m_length;
00097 };
00098
00099
#endif
This file is part of the documentation for kio Library Version 3.2.3.