From fe3a68d5cd161371d4ab7e41ca8142a26db2107c Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 28 Dec 2005 03:10:07 +0000 Subject: [PATCH] make string params const (stepping into RString constructors makes for frustrating debugging) --- stepmania/src/RageFileManager.cpp | 54 ++++++++++++++++++++++--------- stepmania/src/RageFileManager.h | 30 ++++++++--------- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index d94dc1a3b9..8ac905c489 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -223,7 +223,7 @@ static void ChangeToDirOfExecutable( RString argv0 ) #endif } -RageFileManager::RageFileManager( RString argv0 ) +RageFileManager::RageFileManager( const RString &argv0 ) { CHECKPOINT_M( argv0 ); ChangeToDirOfExecutable( argv0 ); @@ -291,8 +291,9 @@ static void NormalizePath( RString &sPath ) bool ilt( const RString &a, const RString &b ) { return a.CompareNoCase(b) < 0; } bool ieq( const RString &a, const RString &b ) { return a.CompareNoCase(b) == 0; } -void RageFileManager::GetDirListing( RString sPath, vector &AddTo, bool bOnlyDirs, bool bReturnPathToo ) +void RageFileManager::GetDirListing( const RString &sPath_, vector &AddTo, bool bOnlyDirs, bool bReturnPathToo ) { + RString sPath = sPath_; NormalizePath( sPath ); vector apDriverList; @@ -337,8 +338,11 @@ void RageFileManager::GetDirListing( RString sPath, vector &AddTo, bool } /* Files may only be moved within the same file driver. */ -bool RageFileManager::Move( RString sOldPath, RString sNewPath ) +bool RageFileManager::Move( const RString &sOldPath_, const RString &sNewPath_ ) { + RString sOldPath = sOldPath_; + RString sNewPath = sNewPath_; + vector aDriverList; ReferenceAllDrivers( aDriverList ); @@ -364,8 +368,10 @@ bool RageFileManager::Move( RString sOldPath, RString sNewPath ) return Deleted; } -bool RageFileManager::Remove( RString sPath ) +bool RageFileManager::Remove( const RString &sPath_ ) { + RString sPath = sPath_; + vector apDriverList; ReferenceAllDrivers( apDriverList ); @@ -389,7 +395,7 @@ bool RageFileManager::Remove( RString sPath ) return bDeleted; } -void RageFileManager::CreateDir( RString sDir ) +void RageFileManager::CreateDir( const RString &sDir ) { RString sTempFile = sDir + "temp"; RageFile f; @@ -425,8 +431,11 @@ static void AddFilesystemDriver( LoadedDriver *pLoadedDriver, bool bAddToEnd ) g_Mutex->Unlock(); } -bool RageFileManager::Mount( RString sType, RString sRoot, RString sMountPoint, bool bAddToEnd ) +bool RageFileManager::Mount( const RString &sType, const RString &sRoot_, const RString &sMountPoint_, bool bAddToEnd ) { + RString sRoot = sRoot_; + RString sMountPoint = sMountPoint_; + FixSlashesInPlace( sRoot ); AdjustMountpoint( sMountPoint ); @@ -463,8 +472,10 @@ bool RageFileManager::Mount( RString sType, RString sRoot, RString sMountPoint, } /* Mount a custom filesystem. */ -void RageFileManager::Mount( RageFileDriver *pDriver, RString sMountPoint, bool bAddToEnd ) +void RageFileManager::Mount( RageFileDriver *pDriver, const RString &sMountPoint_, bool bAddToEnd ) { + RString sMountPoint = sMountPoint_; + AdjustMountpoint( sMountPoint ); LoadedDriver *pLoadedDriver = new LoadedDriver; @@ -476,8 +487,11 @@ void RageFileManager::Mount( RageFileDriver *pDriver, RString sMountPoint, bool AddFilesystemDriver( pLoadedDriver, bAddToEnd ); } -void RageFileManager::Unmount( RString sType, RString sRoot, RString sMountPoint ) +void RageFileManager::Unmount( const RString &sType, const RString &sRoot_, const RString &sMountPoint_ ) { + RString sRoot = sRoot_; + RString sMountPoint = sMountPoint_; + FixSlashesInPlace( sRoot ); FixSlashesInPlace( sMountPoint ); @@ -567,8 +581,10 @@ void RageFileManager::GetLoadedDrivers( vector &asMounts ) } } -void RageFileManager::FlushDirCache( RString sPath ) +void RageFileManager::FlushDirCache( const RString &sPath_ ) { + RString sPath = sPath_; + LockMut( *g_Mutex ); if( sPath == "" ) @@ -589,8 +605,10 @@ void RageFileManager::FlushDirCache( RString sPath ) } } -RageFileManager::FileType RageFileManager::GetFileType( RString sPath ) +RageFileManager::FileType RageFileManager::GetFileType( const RString &sPath_ ) { + RString sPath = sPath_; + NormalizePath( sPath ); vector apDriverList; @@ -613,8 +631,10 @@ RageFileManager::FileType RageFileManager::GetFileType( RString sPath ) } -int RageFileManager::GetFileSizeInBytes( RString sPath ) +int RageFileManager::GetFileSizeInBytes( const RString &sPath_ ) { + RString sPath = sPath_; + NormalizePath( sPath ); vector apDriverList; @@ -635,8 +655,10 @@ int RageFileManager::GetFileSizeInBytes( RString sPath ) return iRet; } -int RageFileManager::GetFileHash( RString sPath ) +int RageFileManager::GetFileHash( const RString &sPath_ ) { + RString sPath = sPath_; + NormalizePath( sPath ); vector apDriverList; @@ -684,8 +706,10 @@ static bool PathUsesSlowFlush( const RString &sPath ) } /* Used only by RageFile: */ -RageFileBasic *RageFileManager::Open( RString sPath, int mode, int &err ) +RageFileBasic *RageFileManager::Open( const RString &sPath_, int mode, int &err ) { + RString sPath = sPath_; + err = ENOENT; if( (mode & RageFile::WRITE) && PathUsesSlowFlush(sPath) ) @@ -701,7 +725,7 @@ RageFileBasic *RageFileManager::Open( RString sPath, int mode, int &err ) return OpenForReading( sPath, mode, err ); } -RageFileBasic *RageFileManager::OpenForReading( RString sPath, int mode, int &err ) +RageFileBasic *RageFileManager::OpenForReading( const RString &sPath, int mode, int &err ) { vector apDriverList; ReferenceAllDrivers( apDriverList ); @@ -730,7 +754,7 @@ RageFileBasic *RageFileManager::OpenForReading( RString sPath, int mode, int &er return NULL; } -RageFileBasic *RageFileManager::OpenForWriting( RString sPath, int mode, int &iError ) +RageFileBasic *RageFileManager::OpenForWriting( const RString &sPath, int mode, int &iError ) { /* * The value for a driver to open a file is the number of directories and/or files diff --git a/stepmania/src/RageFileManager.h b/stepmania/src/RageFileManager.h index 80339de82d..18bcf38262 100644 --- a/stepmania/src/RageFileManager.h +++ b/stepmania/src/RageFileManager.h @@ -15,28 +15,28 @@ class RageFileBasic; class RageFileManager { public: - RageFileManager( RString argv0 ); + RageFileManager( const RString &argv0 ); ~RageFileManager(); void MountInitialFilesystems(); - void GetDirListing( RString sPath, vector &AddTo, bool bOnlyDirs, bool bReturnPathToo ); - bool Move( RString sOldPath, RString sNewPath ); - bool Remove( RString sPath ); - void CreateDir( RString sDir ); + void GetDirListing( const RString &sPath, vector &AddTo, bool bOnlyDirs, bool bReturnPathToo ); + bool Move( const RString &sOldPath, const RString &sNewPath ); + bool Remove( const RString &sPath ); + void CreateDir( const RString &sDir ); enum FileType { TYPE_FILE, TYPE_DIR, TYPE_NONE }; - FileType GetFileType( RString sPath ); + FileType GetFileType( const RString &sPath ); bool IsAFile( const RString &sPath ); bool IsADirectory( const RString &sPath ); bool DoesFileExist( const RString &sPath ); - int GetFileSizeInBytes( RString sPath ); - int GetFileHash( RString sPath ); + int GetFileSizeInBytes( const RString &sPath ); + int GetFileHash( const RString &sPath ); - bool Mount( RString sType, RString sRealPath, RString sMountPoint, bool bAddToEnd = true ); - void Mount( RageFileDriver *pDriver, RString sMountPoint, bool bAddToEnd = true ); - void Unmount( RString sType, RString sRoot, RString sMountPoint ); + bool Mount( const RString &sType, const RString &sRealPath, const RString &sMountPoint, bool bAddToEnd = true ); + void Mount( RageFileDriver *pDriver, const RString &sMountPoint, bool bAddToEnd = true ); + void Unmount( const RString &sType, const RString &sRoot, const RString &sMountPoint ); /* Change the root of a filesystem. Only a couple drivers support this; it's * used to change memory card mountpoints without having to actually unmount @@ -49,18 +49,18 @@ public: }; void GetLoadedDrivers( vector &asMounts ); - void FlushDirCache( RString sPath ); + void FlushDirCache( const RString &sPath ); /* Used only by RageFile: */ - RageFileBasic *Open( RString sPath, int iMode, int &iError ); + RageFileBasic *Open( const RString &sPath, int iMode, int &iError ); /* Retrieve or release a reference to the low-level driver for a mountpoint. */ RageFileDriver *GetFileDriver( RString sMountpoint ); void ReleaseFileDriver( RageFileDriver *pDriver ); private: - RageFileBasic *OpenForReading( RString sPath, int iMode, int &iError ); - RageFileBasic *OpenForWriting( RString sPath, int iMode, int &iError ); + RageFileBasic *OpenForReading( const RString &sPath, int iMode, int &iError ); + RageFileBasic *OpenForWriting( const RString &sPath, int iMode, int &iError ); }; extern RageFileManager *FILEMAN;