@ -255,7 +255,7 @@ public:
void SetVersion ( int n ) { nVersion = n ; }
void SetVersion ( int n ) { nVersion = n ; }
int GetVersion ( ) { return nVersion ; }
int GetVersion ( ) { return nVersion ; }
CDataStream & read ( char * pch , size_t nSize )
void read ( char * pch , size_t nSize )
{
{
// Read from the beginning of the buffer
// Read from the beginning of the buffer
unsigned int nReadPosNext = nReadPos + nSize ;
unsigned int nReadPosNext = nReadPos + nSize ;
@ -268,14 +268,13 @@ public:
memcpy ( pch , & vch [ nReadPos ] , nSize ) ;
memcpy ( pch , & vch [ nReadPos ] , nSize ) ;
nReadPos = 0 ;
nReadPos = 0 ;
vch . clear ( ) ;
vch . clear ( ) ;
return ( * this ) ;
return ;
}
}
memcpy ( pch , & vch [ nReadPos ] , nSize ) ;
memcpy ( pch , & vch [ nReadPos ] , nSize ) ;
nReadPos = nReadPosNext ;
nReadPos = nReadPosNext ;
return ( * this ) ;
}
}
CDataStream & ignore ( int nSize )
void ignore ( int nSize )
{
{
// Ignore from the beginning of the buffer
// Ignore from the beginning of the buffer
if ( nSize < 0 ) {
if ( nSize < 0 ) {
@ -288,17 +287,15 @@ public:
throw std : : ios_base : : failure ( " CDataStream::ignore(): end of data " ) ;
throw std : : ios_base : : failure ( " CDataStream::ignore(): end of data " ) ;
nReadPos = 0 ;
nReadPos = 0 ;
vch . clear ( ) ;
vch . clear ( ) ;
return ( * this ) ;
return ;
}
}
nReadPos = nReadPosNext ;
nReadPos = nReadPosNext ;
return ( * this ) ;
}
}
CDataStream & write ( const char * pch , size_t nSize )
void write ( const char * pch , size_t nSize )
{
{
// Write to the end of the buffer
// Write to the end of the buffer
vch . insert ( vch . end ( ) , pch , pch + nSize ) ;
vch . insert ( vch . end ( ) , pch , pch + nSize ) ;
return ( * this ) ;
}
}
template < typename Stream >
template < typename Stream >
@ -433,16 +430,15 @@ public:
void SetVersion ( int n ) { nVersion = n ; }
void SetVersion ( int n ) { nVersion = n ; }
int GetVersion ( ) { return nVersion ; }
int GetVersion ( ) { return nVersion ; }
CAutoFile & read ( char * pch , size_t nSize )
void read ( char * pch , size_t nSize )
{
{
if ( ! file )
if ( ! file )
throw std : : ios_base : : failure ( " CAutoFile::read: file handle is NULL " ) ;
throw std : : ios_base : : failure ( " CAutoFile::read: file handle is NULL " ) ;
if ( fread ( pch , 1 , nSize , file ) ! = nSize )
if ( fread ( pch , 1 , nSize , file ) ! = nSize )
throw std : : ios_base : : failure ( feof ( file ) ? " CAutoFile::read: end of file " : " CAutoFile::read: fread failed " ) ;
throw std : : ios_base : : failure ( feof ( file ) ? " CAutoFile::read: end of file " : " CAutoFile::read: fread failed " ) ;
return ( * this ) ;
}
}
CAutoFile & ignore ( size_t nSize )
void ignore ( size_t nSize )
{
{
if ( ! file )
if ( ! file )
throw std : : ios_base : : failure ( " CAutoFile::ignore: file handle is NULL " ) ;
throw std : : ios_base : : failure ( " CAutoFile::ignore: file handle is NULL " ) ;
@ -453,16 +449,14 @@ public:
throw std : : ios_base : : failure ( feof ( file ) ? " CAutoFile::ignore: end of file " : " CAutoFile::read: fread failed " ) ;
throw std : : ios_base : : failure ( feof ( file ) ? " CAutoFile::ignore: end of file " : " CAutoFile::read: fread failed " ) ;
nSize - = nNow ;
nSize - = nNow ;
}
}
return ( * this ) ;
}
}
CAutoFile & write ( const char * pch , size_t nSize )
void write ( const char * pch , size_t nSize )
{
{
if ( ! file )
if ( ! file )
throw std : : ios_base : : failure ( " CAutoFile::write: file handle is NULL " ) ;
throw std : : ios_base : : failure ( " CAutoFile::write: file handle is NULL " ) ;
if ( fwrite ( pch , 1 , nSize , file ) ! = nSize )
if ( fwrite ( pch , 1 , nSize , file ) ! = nSize )
throw std : : ios_base : : failure ( " CAutoFile::write: write failed " ) ;
throw std : : ios_base : : failure ( " CAutoFile::write: write failed " ) ;
return ( * this ) ;
}
}
template < typename T >
template < typename T >
@ -563,7 +557,7 @@ public:
}
}
// read a number of bytes
// read a number of bytes
CBufferedFile & read ( char * pch , size_t nSize ) {
void read ( char * pch , size_t nSize ) {
if ( nSize + nReadPos > nReadLimit )
if ( nSize + nReadPos > nReadLimit )
throw std : : ios_base : : failure ( " Read attempted past buffer limit " ) ;
throw std : : ios_base : : failure ( " Read attempted past buffer limit " ) ;
if ( nSize + nRewind > vchBuf . size ( ) )
if ( nSize + nRewind > vchBuf . size ( ) )
@ -582,7 +576,6 @@ public:
pch + = nNow ;
pch + = nNow ;
nSize - = nNow ;
nSize - = nNow ;
}
}
return ( * this ) ;
}
}
// return the current reading position
// return the current reading position