simplify; use RageBasicFile instead of RageFileObj

This commit is contained in:
Glenn Maynard
2004-12-10 10:04:32 +00:00
parent 2474150aeb
commit 8915e3944a
9 changed files with 39 additions and 28 deletions
+5
View File
@@ -24,6 +24,11 @@ RageFile::RageFile( const RageFile &cpy ):
m_Mode = cpy.m_Mode;
}
RageBasicFile *RageFile::Copy() const
{
return new RageFile( *this );
}
CString RageFile::GetPath() const
{
if ( !IsOpen() )
+7 -1
View File
@@ -46,6 +46,11 @@ public:
* Flush() to flush pending data, in order to check for errors. */
virtual int Flush() = 0;
/* This returns a descriptive path for the file, or "". */
virtual CString GetDisplayPath() const { return ""; }
virtual RageBasicFile *Copy() const = 0;
virtual int GetLine( CString &out ) = 0;
virtual int PutLine( const CString &str ) = 0;
@@ -73,6 +78,7 @@ public:
RageFile();
~RageFile() { Close(); }
RageFile( const RageFile &cpy );
RageBasicFile *Copy() const;
/* Use GetRealPath to get the path this file was opened with; use that if you
* want a path that will probably get you the same file again.
@@ -116,7 +122,7 @@ protected:
void SetError( const CString &err );
private:
RageFileObj *m_File;
RageBasicFile *m_File;
CString m_Path;
CString m_sError;
int m_Mode;
+2 -2
View File
@@ -15,7 +15,7 @@ class RageFileDriver
public:
RageFileDriver( FilenameDB *db ) { FDB = db; }
virtual ~RageFileDriver();
virtual RageFileObj *Open( const CString &path, int mode, int &err ) = 0;
virtual RageBasicFile *Open( const CString &path, int mode, int &err ) = 0;
virtual void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo );
virtual RageFileManager::FileType GetFileType( const CString &sPath );
virtual int GetFileSizeInBytes( const CString &sFilePath );
@@ -61,7 +61,7 @@ public:
virtual int GetFileSize() const = 0;
virtual CString GetDisplayPath() const { return ""; }
virtual RageFileObj *Copy() const { FAIL_M( "Copying unimplemented" ); }
virtual RageBasicFile *Copy() const { FAIL_M( "Copying unimplemented" ); }
protected:
virtual int SeekInternal( int iOffset ) { FAIL_M( "Seeking unimplemented" ); }
+2 -2
View File
@@ -47,7 +47,7 @@ public:
virtual int WriteInternal( const void *pBuffer, size_t iBytes );
virtual int FlushInternal();
virtual int SeekInternal( int offset );
virtual RageFileObj *Copy() const;
virtual RageBasicFile *Copy() const;
virtual CString GetDisplayPath() const { return path; }
virtual int GetFileSize() const;
};
@@ -158,7 +158,7 @@ bool RageFileDriverDirect::Remove( const CString &path )
}
}
RageFileObj *RageFileObjDirect::Copy() const
RageBasicFile *RageFileObjDirect::Copy() const
{
int err;
RageFileObj *ret = MakeFileObjDirect( path, m_iMode, err );
+3 -2
View File
@@ -83,14 +83,15 @@ int RageFileObjMem::GetFileSize() const
return m_pFile->m_sBuf.size();
}
RageFileObjMem::RageFileObjMem( const RageFileObjMem &cpy )
RageFileObjMem::RageFileObjMem( const RageFileObjMem &cpy ):
RageFileObj( cpy )
{
m_pFile = cpy.m_pFile;
m_iFilePos = cpy.m_iFilePos;
RageFileObjMemFile::AddReference( m_pFile );
}
RageFileObj *RageFileObjMem::Copy() const
RageBasicFile *RageFileObjMem::Copy() const
{
RageFileObjMem *pRet = new RageFileObjMem( *this );
return pRet;
+1 -1
View File
@@ -18,7 +18,7 @@ public:
int WriteInternal( const void *buffer, size_t bytes );
int SeekInternal( int offset );
int GetFileSize() const;
RageFileObj *Copy() const;
RageBasicFile *Copy() const;
/* Retrieve the contents of this file. */
const CString &GetString() const;
+2 -2
View File
@@ -85,7 +85,7 @@ public:
int WriteInternal( const void *pBuffer, size_t iBytes ) { SetError( "Not implemented" ); return -1; }
int SeekInternal( int iOffset );
int GetFileSize() const { return info.uncompr_size; }
RageFileObj *Copy() const
RageBasicFile *Copy() const
{
RageException::Throw( "Loading ZIPs from deflated ZIPs is currently disabled; see RageFileObjZipDeflated" );
@@ -108,7 +108,7 @@ public:
int SeekInternal( int iOffset );
int GetFileSize() const { return info.uncompr_size; }
RageFileObj *Copy() const
RageBasicFile *Copy() const
{
RageFileObjZipStored *pRet = new RageFileObjZipStored( zip, info );
pRet->FilePos = FilePos;
+13 -13
View File
@@ -20,7 +20,7 @@ static RageEvent *g_Mutex;
CString InitialWorkingDirectory;
CString DirOfExecutable;
typedef map< const RageFileObj *, RageFileDriver * > FileReferences;
typedef map< const RageBasicFile *, RageFileDriver * > FileReferences;
static FileReferences g_Refs;
struct LoadedDriver
@@ -102,7 +102,7 @@ class RageFileDriverMountpoints: public RageFileDriver
{
public:
RageFileDriverMountpoints(): RageFileDriver( new FilenameDB ) { }
RageFileObj *Open( const CString &path, int mode, int &err )
RageBasicFile *Open( const CString &path, int mode, int &err )
{
err = (mode == RageFile::WRITE)? ERROR_WRITING_NOT_SUPPORTED:ENOENT;
return NULL;
@@ -593,11 +593,11 @@ static bool SortBySecond( const pair<int,int> &a, const pair<int,int> &b )
return a.second < b.second;
}
void AddReference( const RageFileObj *obj, RageFileDriver *driver )
void AddReference( const RageBasicFile *obj, RageFileDriver *driver )
{
LockMut( *g_Mutex );
pair< const RageFileObj *, RageFileDriver * > ref;
pair< const RageBasicFile *, RageFileDriver * > ref;
ref.first = obj;
ref.second = driver;
@@ -607,7 +607,7 @@ void AddReference( const RageFileObj *obj, RageFileDriver *driver )
ASSERT_M( ret.second, ssprintf( "RemoveReference: Duplicate reference (%s)", obj->GetDisplayPath().c_str() ) );
}
void RemoveReference( const RageFileObj *obj )
void RemoveReference( const RageBasicFile *obj )
{
LockMut( *g_Mutex );
@@ -638,7 +638,7 @@ static bool PathUsesSlowFlush( const CString &sPath )
}
/* Used only by RageFile: */
RageFileObj *RageFileManager::Open( CString sPath, int mode, int &err )
RageBasicFile *RageFileManager::Open( CString sPath, int mode, int &err )
{
err = ENOENT;
@@ -662,7 +662,7 @@ RageFileObj *RageFileManager::Open( CString sPath, int mode, int &err )
if( path.size() == 0 )
continue;
int error;
RageFileObj *ret = ld.driver->Open( path, mode, error );
RageBasicFile *ret = ld.driver->Open( path, mode, error );
if( ret )
{
AddReference( ret, ld.driver );
@@ -680,15 +680,15 @@ RageFileObj *RageFileManager::Open( CString sPath, int mode, int &err )
return NULL;
}
/* Copy a RageFileObj for a new RageFile. */
RageFileObj *RageFileManager::CopyFileObj( const RageFileObj *cpy )
/* Copy a RageBasicFile for a new RageFile. */
RageBasicFile *RageFileManager::CopyFileObj( const RageBasicFile *cpy )
{
LockMut( *g_Mutex );
FileReferences::const_iterator it = g_Refs.find( cpy );
ASSERT_M( it != g_Refs.end(), ssprintf( "CopyFileObj: Missing reference (%s)", cpy->GetDisplayPath().c_str() ) );
RageFileObj *ret = cpy->Copy();
RageBasicFile *ret = cpy->Copy();
/* It's from the same driver as the original. */
AddReference( ret, it->second );
@@ -696,7 +696,7 @@ RageFileObj *RageFileManager::CopyFileObj( const RageFileObj *cpy )
return ret;
}
RageFileObj *RageFileManager::OpenForWriting( CString sPath, int mode, int &err )
RageBasicFile *RageFileManager::OpenForWriting( CString sPath, int mode, int &err )
{
/*
* The value for a driver to open a file is the number of directories and/or files
@@ -748,7 +748,7 @@ RageFileObj *RageFileManager::OpenForWriting( CString sPath, int mode, int &err
ASSERT( path.size() );
int error;
RageFileObj *ret = ld.driver->Open( path, mode, error );
RageBasicFile *ret = ld.driver->Open( path, mode, error );
if( ret )
{
AddReference( ret, ld.driver );
@@ -769,7 +769,7 @@ RageFileObj *RageFileManager::OpenForWriting( CString sPath, int mode, int &err
return NULL;
}
void RageFileManager::Close( RageFileObj *obj )
void RageFileManager::Close( RageBasicFile *obj )
{
if( obj == NULL )
return;
+4 -5
View File
@@ -10,7 +10,6 @@
extern CString InitialWorkingDirectory;
extern CString DirOfExecutable;
class RageFileObj;
class RageFileManager
{
public:
@@ -45,12 +44,12 @@ public:
void FlushDirCache( CString sPath );
/* Used only by RageFile: */
RageFileObj *Open( CString sPath, int mode, int &err );
void Close( RageFileObj *obj );
RageFileObj *CopyFileObj( const RageFileObj *cpy );
RageBasicFile *Open( CString sPath, int mode, int &err );
void Close( RageBasicFile *obj );
RageBasicFile *CopyFileObj( const RageBasicFile *cpy );
private:
RageFileObj *OpenForWriting( CString sPath, int mode, int &err );
RageBasicFile *OpenForWriting( CString sPath, int mode, int &err );
};
extern RageFileManager *FILEMAN;