Adds const in FileUtils

`const` was missing in some getters

Signed-off-by: Ricardo Quesada <ricardoquesada@gmail.com>
This commit is contained in:
Ricardo Quesada 2013-09-06 22:52:23 -07:00
parent 2d2e15d275
commit 028deae846
13 changed files with 40 additions and 38 deletions

View File

@ -76,7 +76,7 @@ bool FileUtilsAndroid::init()
return FileUtils::init(); return FileUtils::init();
} }
bool FileUtilsAndroid::isFileExist(const std::string& strFilePath) bool FileUtilsAndroid::isFileExist(const std::string& strFilePath) const
{ {
if (0 == strFilePath.length()) if (0 == strFilePath.length())
{ {
@ -116,7 +116,7 @@ bool FileUtilsAndroid::isFileExist(const std::string& strFilePath)
return bFound; return bFound;
} }
bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const
{ {
// On Android, there are two situations for full path. // On Android, there are two situations for full path.
// 1) Files in APK, e.g. assets/path/path/file.png // 1) Files in APK, e.g. assets/path/path/file.png
@ -235,7 +235,7 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char*
return pData; return pData;
} }
string FileUtilsAndroid::getWritablePath() string FileUtilsAndroid::getWritablePath() const
{ {
// Fix for Nexus 10 (Android 4.2 multi-user environment) // Fix for Nexus 10 (Android 4.2 multi-user environment)
// the path is retrieved through Java Context.getCacheDir() method // the path is retrieved through Java Context.getCacheDir() method

View File

@ -52,9 +52,10 @@ public:
/* override funtions */ /* override funtions */
bool init(); bool init();
virtual unsigned char* getFileData(const char* filename, const char* pszMode, unsigned long * pSize); virtual unsigned char* getFileData(const char* filename, const char* pszMode, unsigned long * pSize);
virtual std::string getWritablePath();
virtual bool isFileExist(const std::string& strFilePath); virtual std::string getWritablePath() const;
virtual bool isAbsolutePath(const std::string& strPath); virtual bool isFileExist(const std::string& strFilePath) const;
virtual bool isAbsolutePath(const std::string& strPath) const;
/** This function is android specific. It is used for TextureCache::addImageAsync(). /** This function is android specific. It is used for TextureCache::addImageAsync().
Don't use it in your codes. Don't use it in your codes.

View File

@ -42,14 +42,14 @@ class CC_DLL FileUtilsApple : public FileUtils
{ {
public: public:
/* override funtions */ /* override funtions */
virtual std::string getWritablePath(); virtual std::string getWritablePath() const override;
virtual bool isFileExist(const std::string& strFilePath); virtual bool isFileExist(const std::string& strFilePath) const override;
virtual std::string getFullPathForDirectoryAndFilename(const std::string& strDirectory, const std::string& strFilename); virtual std::string getFullPathForDirectoryAndFilename(const std::string& strDirectory, const std::string& strFilename) override;
virtual Dictionary* createDictionaryWithContentsOfFile(const std::string& filename); virtual Dictionary* createDictionaryWithContentsOfFile(const std::string& filename) override;
virtual bool writeToFile(Dictionary *dict, const std::string& fullPath); virtual bool writeToFile(Dictionary *dict, const std::string& fullPath) override;
virtual Array* createArrayWithContentsOfFile(const std::string& filename); virtual Array* createArrayWithContentsOfFile(const std::string& filename) override;
}; };
// end of platform group // end of platform group

View File

@ -230,7 +230,7 @@ FileUtils* FileUtils::getInstance()
} }
std::string FileUtilsApple::getWritablePath() std::string FileUtilsApple::getWritablePath() const
{ {
// save to document folder // save to document folder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
@ -240,7 +240,7 @@ std::string FileUtilsApple::getWritablePath()
return strRet; return strRet;
} }
bool FileUtilsApple::isFileExist(const std::string& strFilePath) bool FileUtilsApple::isFileExist(const std::string& strFilePath) const
{ {
if(strFilePath.length() == 0) if(strFilePath.length() == 0)
{ {
@ -306,7 +306,7 @@ std::string FileUtilsApple::getFullPathForDirectoryAndFilename(const std::string
Dictionary* FileUtilsApple::createDictionaryWithContentsOfFile(const std::string& filename) Dictionary* FileUtilsApple::createDictionaryWithContentsOfFile(const std::string& filename)
{ {
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename.c_str()); std::string fullPath = fullPathForFilename(filename);
NSString* pPath = [NSString stringWithUTF8String:fullPath.c_str()]; NSString* pPath = [NSString stringWithUTF8String:fullPath.c_str()];
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath]; NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
@ -351,7 +351,7 @@ Array* FileUtilsApple::createArrayWithContentsOfFile(const std::string& filename
// pPath = [pPath stringByDeletingPathExtension]; // pPath = [pPath stringByDeletingPathExtension];
// pPath = [[NSBundle mainBundle] pathForResource:pPath ofType:pathExtension]; // pPath = [[NSBundle mainBundle] pathForResource:pPath ofType:pathExtension];
// fixing cannot read data using Array::createWithContentsOfFile // fixing cannot read data using Array::createWithContentsOfFile
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename.c_str()); std::string fullPath = fullPathForFilename(filename);
NSString* path = [NSString stringWithUTF8String:fullPath.c_str()]; NSString* path = [NSString stringWithUTF8String:fullPath.c_str()];
NSArray* array = [NSArray arrayWithContentsOfFile:path]; NSArray* array = [NSArray arrayWithContentsOfFile:path];

View File

@ -33,7 +33,7 @@ bool FileUtilsEmscripten::init()
return FileUtils::init(); return FileUtils::init();
} }
string FileUtilsEmscripten::getWritablePath() string FileUtilsEmscripten::getWritablePath() const
{ {
// Let's write it in the current working directory's data folder // Let's write it in the current working directory's data folder
char cwd[FILENAME_MAX] = {0}; char cwd[FILENAME_MAX] = {0};
@ -47,7 +47,7 @@ string FileUtilsEmscripten::getWritablePath()
return path; return path;
} }
bool FileUtilsEmscripten::isAbsolutePath(const std::string& strPath) bool FileUtilsEmscripten::isAbsolutePath(const std::string& strPath) const
{ {
if (strPath[0] == '/' || strPath.find(_defaultResRootPath) == 0) if (strPath[0] == '/' || strPath.find(_defaultResRootPath) == 0)
{ {
@ -56,7 +56,7 @@ bool FileUtilsEmscripten::isAbsolutePath(const std::string& strPath)
return false; return false;
} }
bool FileUtilsEmscripten::isFileExist(const std::string& strFilePath) bool FileUtilsEmscripten::isFileExist(const std::string& strFilePath) const
{ {
std::string strPath = strFilePath; std::string strPath = strFilePath;
if (strPath[0] != '/') if (strPath[0] != '/')

View File

@ -42,12 +42,13 @@ class CC_DLL FileUtilsEmscripten : public FileUtils
{ {
friend class FileUtils; friend class FileUtils;
FileUtilsEmscripten(); FileUtilsEmscripten();
public: public:
/* override funtions */ /* override funtions */
bool init(); bool init();
virtual std::string getWritablePath(); virtual std::string getWritablePath() const;
virtual bool isFileExist(const std::string& strFilePath); virtual bool isFileExist(const std::string& strFilePath) const;
virtual bool isAbsolutePath(const std::string& strPath); virtual bool isAbsolutePath(const std::string& strPath) const;
}; };
// end of platform group // end of platform group

View File

@ -67,7 +67,7 @@ bool FileUtilsLinux::init()
return FileUtils::init(); return FileUtils::init();
} }
string FileUtilsLinux::getWritablePath() string FileUtilsLinux::getWritablePath() const
{ {
struct stat st; struct stat st;
stat(_writablePath.c_str(), &st); stat(_writablePath.c_str(), &st);
@ -78,7 +78,7 @@ string FileUtilsLinux::getWritablePath()
return _writablePath; return _writablePath;
} }
bool FileUtilsLinux::isFileExist(const std::string& strFilePath) bool FileUtilsLinux::isFileExist(const std::string& strFilePath) const
{ {
if (0 == strFilePath.length()) if (0 == strFilePath.length())
{ {

View File

@ -46,8 +46,8 @@ class CC_DLL FileUtilsLinux : public FileUtils
public: public:
/* override funtions */ /* override funtions */
bool init(); bool init();
virtual std::string getWritablePath(); virtual std::string getWritablePath() const;
virtual bool isFileExist(const std::string& strFilePath); virtual bool isFileExist(const std::string& strFilePath) const;
}; };
// end of platform group // end of platform group

View File

@ -84,7 +84,7 @@ FileUtilsQt5::init()
} }
std::string std::string
FileUtilsQt5::getWritablePath() FileUtilsQt5::getWritablePath() const
{ {
QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
@ -96,7 +96,7 @@ FileUtilsQt5::getWritablePath()
return dir.path().toStdString(); return dir.path().toStdString();
} }
bool FileUtilsQt5::isFileExist(const std::string& strFilePath) bool FileUtilsQt5::isFileExist(const std::string& strFilePath) const
{ {
QString filePath = QString::fromStdString(strFilePath); QString filePath = QString::fromStdString(strFilePath);

View File

@ -80,7 +80,7 @@ bool FileUtilsTizen::init()
return FileUtils::init(); return FileUtils::init();
} }
string FileUtilsTizen::getWritablePath() string FileUtilsTizen::getWritablePath() const
{ {
UiApp* pApp = UiApp::GetInstance(); UiApp* pApp = UiApp::GetInstance();
if (!pApp) if (!pApp)
@ -101,7 +101,7 @@ string FileUtilsTizen::getWritablePath()
return path; return path;
} }
bool FileUtilsTizen::isFileExist(const std::string& strFilePath) bool FileUtilsTizen::isFileExist(const std::string& strFilePath) const
{ {
std::string strPath = strFilePath; std::string strPath = strFilePath;
if (!isAbsolutePath(strPath)) if (!isAbsolutePath(strPath))

View File

@ -47,8 +47,8 @@ class CC_DLL FileUtilsTizen : public FileUtils
public: public:
/* override funtions */ /* override funtions */
bool init(); bool init();
virtual std::string getWritablePath(); virtual std::string getWritablePath() const;
virtual bool isFileExist(const std::string& strFilePath); virtual bool isFileExist(const std::string& strFilePath) const;
}; };
// end of platform group // end of platform group

View File

@ -91,7 +91,7 @@ bool FileUtilsWin32::init()
return FileUtils::init(); return FileUtils::init();
} }
bool FileUtilsWin32::isFileExist(const std::string& strFilePath) bool FileUtilsWin32::isFileExist(const std::string& strFilePath) const
{ {
if (0 == strFilePath.length()) if (0 == strFilePath.length())
{ {
@ -110,7 +110,7 @@ bool FileUtilsWin32::isFileExist(const std::string& strFilePath)
return GetFileAttributesW(utf16Buf) != -1 ? true : false; return GetFileAttributesW(utf16Buf) != -1 ? true : false;
} }
bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const
{ {
if ( strPath.length() > 2 if ( strPath.length() > 2
&& ( (strPath[0] >= 'a' && strPath[0] <= 'z') || (strPath[0] >= 'A' && strPath[0] <= 'Z') ) && ( (strPath[0] >= 'a' && strPath[0] <= 'z') || (strPath[0] >= 'A' && strPath[0] <= 'Z') )
@ -182,7 +182,7 @@ std::string FileUtilsWin32::getFullPathForDirectoryAndFilename(const std::string
return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename); return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename);
} }
string FileUtilsWin32::getWritablePath() string FileUtilsWin32::getWritablePath() const
{ {
// Get full path of executable, e.g. c:\Program Files (x86)\My Game Folder\MyGame.exe // Get full path of executable, e.g. c:\Program Files (x86)\My Game Folder\MyGame.exe
char full_path[CC_MAX_PATH + 1]; char full_path[CC_MAX_PATH + 1];

View File

@ -45,9 +45,9 @@ class CC_DLL FileUtilsWin32 : public FileUtils
public: public:
/* override funtions */ /* override funtions */
bool init(); bool init();
virtual std::string getWritablePath(); virtual std::string getWritablePath() const;
virtual bool isFileExist(const std::string& strFilePath); virtual bool isFileExist(const std::string& strFilePath) const;
virtual bool isAbsolutePath(const std::string& strPath); virtual bool isAbsolutePath(const std::string& strPath) const;
protected: protected:
/** /**
* Gets resource file data * Gets resource file data