internalize RageFileObj implementation functions

This commit is contained in:
Glenn Maynard
2004-12-10 03:14:01 +00:00
parent 2bf27c582c
commit e2ea72dbac
5 changed files with 72 additions and 32 deletions
+21
View File
@@ -90,6 +90,27 @@ RageFileDriver *MakeFileDriver( CString Type, CString Root )
return NULL;
}
int RageFileObj::Seek( int iOffset )
{
return SeekInternal( iOffset );
}
int RageFileObj::Read( void *pBuffer, size_t iBytes )
{
return ReadInternal( pBuffer, iBytes );
}
int RageFileObj::Write( const void *pBuffer, size_t iBytes )
{
return WriteInternal( pBuffer, iBytes );
}
int RageFileObj::Flush()
{
return FlushInternal();
}
/*
* Copyright (c) 2003-2004 Glenn Maynard
* All rights reserved.
+30 -11
View File
@@ -33,24 +33,43 @@ protected:
class RageFileObj
{
protected:
void SetError( const CString &sErr ) { m_sError = sErr; }
CString m_sError;
public:
virtual ~RageFileObj() { }
CString GetError() const { return m_sError; }
virtual CString GetError() const { return m_sError; }
virtual int Seek( int offset ) = 0;
/* Seek to the given absolute offset. Return to the position actually
* seeked to; if the position given was beyond the end of the file, the
* return value will be the size of the file. */
int Seek( int iOffset );
/* Read at most iSize bytes into pBuf. Return the number of bytes read,
* 0 on end of stream, or -1 on error. Note that reading less than iSize
* does not necessarily mean that the end of the stream has been reached;
* keep reading until 0 is returned. */
int Read( void *pBuffer, size_t iBytes );
/* Write iSize bytes of data from pBuf. Return 0 on success, -1 on error. */
int Write( const void *pBuffer, size_t iBytes );
/* Due to buffering, writing may not happen by the end of a Write() call, so not
* all errors may be returned by it. Data will be flushed when the stream (or its
* underlying object) is destroyed, but errors can no longer be returned. Call
* Flush() to flush pending data, in order to check for errors. */
int Flush();
virtual int GetFileSize() = 0;
virtual CString GetDisplayPath() const { return ""; }
virtual RageFileObj *Copy() const { FAIL_M( "Copying unimplemented" ); }
/* Raw I/O: */
virtual int Read(void *buffer, size_t bytes) = 0;
virtual int Write(const void *buffer, size_t bytes) = 0;
virtual int Flush() { return 0; }
virtual RageFileObj *Copy() const = 0;
protected:
virtual int SeekInternal( int iOffset ) { FAIL_M( "Seeking unimplemented" ); }
virtual int ReadInternal( void *pBuffer, size_t iBytes ) = 0;
virtual int WriteInternal( const void *pBuffer, size_t iBytes ) = 0;
virtual int FlushInternal() { return 0; }
virtual void SetError( const CString &sError ) { m_sError = sError; }
CString m_sError;
};
/* This is used to register the driver, so RageFileManager can see it. */
+8 -8
View File
@@ -43,10 +43,10 @@ private:
public:
RageFileObjDirect( const CString &path, int fd_, int mode_ );
virtual ~RageFileObjDirect();
virtual int Read(void *buffer, size_t bytes);
virtual int Write(const void *buffer, size_t bytes);
virtual int Flush();
virtual int Seek( int offset );
virtual int ReadInternal( void *pBuffer, size_t iBytes );
virtual int WriteInternal( const void *pBuffer, size_t iBytes );
virtual int FlushInternal();
virtual int SeekInternal( int offset );
virtual RageFileObj *Copy() const;
virtual CString GetDisplayPath() const { return path; }
virtual int GetFileSize();
@@ -290,7 +290,7 @@ RageFileObjDirect::~RageFileObjDirect()
}
}
int RageFileObjDirect::Read( void *buf, size_t bytes )
int RageFileObjDirect::ReadInternal( void *buf, size_t bytes )
{
int ret = read( fd, buf, bytes );
if( ret == -1 )
@@ -316,7 +316,7 @@ static int retried_write( int fd, const void *buf, size_t count )
}
int RageFileObjDirect::Flush()
int RageFileObjDirect::FlushInternal()
{
if( !write_buf.size() )
return 0;
@@ -333,7 +333,7 @@ int RageFileObjDirect::Flush()
return ret;
}
int RageFileObjDirect::Write( const void *buf, size_t bytes )
int RageFileObjDirect::WriteInternal( const void *buf, size_t bytes )
{
if( write_buf.size()+bytes > BUFSIZE )
{
@@ -360,7 +360,7 @@ int RageFileObjDirect::Write( const void *buf, size_t bytes )
return bytes;
}
int RageFileObjDirect::Seek( int offset )
int RageFileObjDirect::SeekInternal( int offset )
{
return lseek( fd, offset, SEEK_SET );
}
+3 -3
View File
@@ -44,7 +44,7 @@ public:
delete m_pFile;
}
int Read( void *buffer, size_t bytes )
int ReadInternal( void *buffer, size_t bytes )
{
m_pFile->m_Mutex.Lock();
@@ -57,7 +57,7 @@ public:
return bytes;
}
int Write( const void *buffer, size_t bytes )
int WriteInternal( const void *buffer, size_t bytes )
{
m_pFile->m_Mutex.Lock();
m_pFile->m_sBuf.append( (const char *) buffer, bytes );
@@ -67,7 +67,7 @@ public:
return bytes;
}
int Seek( int offset )
int SeekInternal( int offset )
{
m_iFilePos = clamp( offset, 0, GetFileSize() );
return m_iFilePos;
+10 -10
View File
@@ -81,9 +81,9 @@ public:
RageFileObjZipDeflated( const RageFile &f, const FileInfo &info );
RageFileObjZipDeflated( const RageFileObjZipDeflated &cpy );
~RageFileObjZipDeflated();
int Read(void *buffer, size_t bytes);
int Write(const void *buffer, size_t bytes) { SetError( "Not implemented" ); return -1; }
int Seek( int offset );
int ReadInternal( void *pBuffer, size_t iBytes );
int WriteInternal( const void *pBuffer, size_t iBytes ) { SetError( "Not implemented" ); return -1; }
int SeekInternal( int iOffset );
int GetFileSize() { return info.uncompr_size; }
RageFileObj *Copy() const
{
@@ -102,10 +102,10 @@ private:
public:
RageFileObjZipStored( const RageFile &f, const FileInfo &info );
int Read(void *buffer, size_t bytes);
int Write(const void *buffer, size_t bytes) { SetError( "Not implemented" ); return -1; }
int ReadInternal( void *pBuffer, size_t iBytes );
int WriteInternal( const void *pBuffer, size_t iBytes ) { SetError( "Not implemented" ); return -1; }
int Seek( int offset );
int SeekInternal( int iOffset );
int GetFileSize() { return info.uncompr_size; }
RageFileObj *Copy() const
@@ -499,7 +499,7 @@ RageFileObjZipDeflated::~RageFileObjZipDeflated()
LOG->Trace( "Huh? inflateEnd() err = %i", err );
}
int RageFileObjZipDeflated::Read( void *buf, size_t bytes )
int RageFileObjZipDeflated::ReadInternal( void *buf, size_t bytes )
{
bool done=false;
int ret = 0;
@@ -560,7 +560,7 @@ int RageFileObjZipDeflated::Read( void *buf, size_t bytes )
return ret;
}
int RageFileObjZipDeflated::Seek( int iPos )
int RageFileObjZipDeflated::SeekInternal( int iPos )
{
/* Optimization: if offset is the end of the file, it's a lseek(0,SEEK_END). Don't
* decode anything. */
@@ -612,7 +612,7 @@ RageFileObjZipStored::RageFileObjZipStored( const RageFile &f, const FileInfo &i
FilePos = 0;
}
int RageFileObjZipStored::Read( void *buf, size_t bytes )
int RageFileObjZipStored::ReadInternal( void *buf, size_t bytes )
{
const int bytes_left = info.compr_size-this->FilePos;
const int got = zip.Read( buf, min( (int) bytes, bytes_left ) );
@@ -628,7 +628,7 @@ int RageFileObjZipStored::Read( void *buf, size_t bytes )
}
int RageFileObjZipStored::Seek( int offset )
int RageFileObjZipStored::SeekInternal( int offset )
{
ASSERT( offset >= 0 );
offset = min( (unsigned) offset, info.compr_size );