diff options
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/Common.cpp | 2 | ||||
| -rw-r--r-- | src/shared/Common.h | 2 | ||||
| -rw-r--r-- | src/shared/Config/ConfigEnv.h | 1 | ||||
| -rw-r--r-- | src/shared/Database/DBCStores.cpp | 6 | ||||
| -rw-r--r-- | src/shared/Database/DBCStores.h | 2 | ||||
| -rw-r--r-- | src/shared/Log.cpp | 2 | ||||
| -rw-r--r-- | src/shared/Log.h | 2 | ||||
| -rw-r--r-- | src/shared/Util.cpp | 14 | ||||
| -rw-r--r-- | src/shared/Util.h | 16 | ||||
| -rw-r--r-- | src/shared/vmap/CoordModelMapping.h | 10 | ||||
| -rw-r--r-- | src/shared/vmap/VMapManager.cpp | 18 |
11 files changed, 34 insertions, 41 deletions
diff --git a/src/shared/Common.cpp b/src/shared/Common.cpp index 93e876bc007..5e24b0e6594 100644 --- a/src/shared/Common.cpp +++ b/src/shared/Common.cpp @@ -32,7 +32,7 @@ char const* localeNames[MAX_LOCALE] = { "ruRU" }; -LocaleConstant GetLocaleByName(std::string name) +LocaleConstant GetLocaleByName(const std::string& name) { for(uint32 i = 0; i < MAX_LOCALE; ++i) if(name==localeNames[i]) diff --git a/src/shared/Common.h b/src/shared/Common.h index 9bf44b78f16..684776a694f 100644 --- a/src/shared/Common.h +++ b/src/shared/Common.h @@ -190,7 +190,7 @@ enum LocaleConstant extern char const* localeNames[MAX_LOCALE]; -LocaleConstant GetLocaleByName(std::string name); +LocaleConstant GetLocaleByName(const std::string& name); // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms) #ifdef max diff --git a/src/shared/Config/ConfigEnv.h b/src/shared/Config/ConfigEnv.h index ad66d56b67e..1b823ccf8c8 100644 --- a/src/shared/Config/ConfigEnv.h +++ b/src/shared/Config/ConfigEnv.h @@ -25,6 +25,5 @@ #include "Common.h" #include "dotconfpp/dotconfpp.h" #include "Config.h" -#include "Log.h" #endif diff --git a/src/shared/Database/DBCStores.cpp b/src/shared/Database/DBCStores.cpp index 03536daf738..fb132c75768 100644 --- a/src/shared/Database/DBCStores.cpp +++ b/src/shared/Database/DBCStores.cpp @@ -130,7 +130,7 @@ DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt); typedef std::list<std::string> StoreProblemList; -static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, std::string filename) +static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename) { sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize); @@ -139,7 +139,7 @@ static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, std::string filename } template<class T> -inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, std::string dbc_path, std::string filename) +inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename) { // compatibility format and C++ structure sizes assert(DBCFile::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFile::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename)); @@ -174,7 +174,7 @@ inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList } } -void LoadDBCStores(std::string dataPath) +void LoadDBCStores(const std::string& dataPath) { std::string dbcPath = dataPath+"dbc/"; diff --git a/src/shared/Database/DBCStores.h b/src/shared/Database/DBCStores.h index 399b94213fe..98a54fbeccf 100644 --- a/src/shared/Database/DBCStores.h +++ b/src/shared/Database/DBCStores.h @@ -197,7 +197,7 @@ extern DBCStorage <TotemCategoryEntry> sTotemCategoryStore; //extern DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore; -- use Zone2MapCoordinates and Map2ZoneCoordinates extern DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore; -void LoadDBCStores(std::string dataPath); +void LoadDBCStores(const std::string& dataPath); // script support functions TRINITY_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore(); diff --git a/src/shared/Log.cpp b/src/shared/Log.cpp index 705b34d3cc7..518c91940dc 100644 --- a/src/shared/Log.cpp +++ b/src/shared/Log.cpp @@ -45,7 +45,7 @@ Log::Log() : Initialize(); } -void Log::InitColors(std::string str) +void Log::InitColors(const std::string& str) { if(str.empty()) { diff --git a/src/shared/Log.h b/src/shared/Log.h index 02f996d26c5..d68529a77a8 100644 --- a/src/shared/Log.h +++ b/src/shared/Log.h @@ -84,7 +84,7 @@ class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ZThr } public: void Initialize(); - void InitColors(std::string init_str); + void InitColors(const std::string& init_str); void outTitle( const char * str); void outCommand( uint32 account, const char * str, ...) ATTR_PRINTF(3,4); void outString(); // any log level diff --git a/src/shared/Util.cpp b/src/shared/Util.cpp index 4f135dcc4ce..a35af77e7f6 100644 --- a/src/shared/Util.cpp +++ b/src/shared/Util.cpp @@ -133,13 +133,13 @@ std::string secsToTimeString(uint32 timeInSecs, bool shortText, bool hoursOnly) return ss.str(); } -uint32 TimeStringToSecs(std::string timestring) +uint32 TimeStringToSecs(const std::string& timestring) { uint32 secs = 0; uint32 buffer = 0; uint32 multiplier = 0; - for(std::string::iterator itr = timestring.begin(); itr != timestring.end(); itr++ ) + for(std::string::const_iterator itr = timestring.begin(); itr != timestring.end(); itr++ ) { if(isdigit(*itr)) { @@ -195,7 +195,7 @@ bool IsIPAddress(char const* ipaddress) } /// create PID file -uint32 CreatePIDFile(std::string filename) +uint32 CreatePIDFile(const std::string& filename) { FILE * pid_file = fopen (filename.c_str(), "w" ); if (pid_file == NULL) @@ -273,7 +273,7 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize) return true; } -bool Utf8toWStr(std::string utf8str, std::wstring& wstr) +bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr) { try { @@ -378,7 +378,7 @@ std::wstring GetMainPartOfName(std::wstring wname, uint32 declension) return wname; } -bool utf8ToConsole(std::string utf8str, std::string& conStr) +bool utf8ToConsole(const std::string& utf8str, std::string& conStr) { #if PLATFORM == PLATFORM_WINDOWS std::wstring wstr; @@ -395,7 +395,7 @@ bool utf8ToConsole(std::string utf8str, std::string& conStr) return true; } -bool consoleToUtf8(std::string conStr,std::string& utf8str) +bool consoleToUtf8(const std::string& conStr,std::string& utf8str) { #if PLATFORM == PLATFORM_WINDOWS std::wstring wstr; @@ -410,7 +410,7 @@ bool consoleToUtf8(std::string conStr,std::string& utf8str) #endif } -bool Utf8FitTo(std::string str, std::wstring search) +bool Utf8FitTo(const std::string& str, std::wstring search) { std::wstring temp; diff --git a/src/shared/Util.h b/src/shared/Util.h index 44c0dda8370..b99cdb13bde 100644 --- a/src/shared/Util.h +++ b/src/shared/Util.h @@ -33,7 +33,7 @@ Tokens StrSplit(const std::string &src, const std::string &sep); void stripLineInvisibleChars(std::string &src); std::string secsToTimeString(uint32 timeInSecs, bool shortText = false, bool hoursOnly = false); -uint32 TimeStringToSecs(std::string timestring); +uint32 TimeStringToSecs(const std::string& timestring); std::string TimeToTimestampStr(time_t t); inline uint32 secsToTimeBitFields(time_t secs) @@ -97,11 +97,11 @@ inline void ApplyPercentModFloatVar(float& var, float val, bool apply) var *= (apply?(100.0f+val)/100.0f : 100.0f / (100.0f+val)); } -bool Utf8toWStr(std::string utf8str, std::wstring& wstr); +bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr); // in wsize==max size of buffer, out wsize==real string size bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize); -inline bool Utf8toWStr(std::string utf8str, wchar_t* wstr, size_t& wsize) -{ +inline bool Utf8toWStr(const std::string& utf8str, wchar_t* wstr, size_t& wsize) +{ return Utf8toWStr(utf8str.c_str(), utf8str.size(), wstr, wsize); } @@ -282,9 +282,9 @@ inline void wstrToLower(std::wstring& str) std::wstring GetMainPartOfName(std::wstring wname, uint32 declension); -bool utf8ToConsole(std::string utf8str, std::string& conStr); -bool consoleToUtf8(std::string conStr,std::string& utf8str); -bool Utf8FitTo(std::string str, std::wstring search); +bool utf8ToConsole(const std::string& utf8str, std::string& conStr); +bool consoleToUtf8(const std::string& conStr,std::string& utf8str); +bool Utf8FitTo(const std::string& str, std::wstring search); #if PLATFORM == PLATFORM_WINDOWS #define UTF8PRINTF(OUT,FRM,RESERR) \ @@ -313,6 +313,6 @@ bool Utf8FitTo(std::string str, std::wstring search); #endif bool IsIPAddress(char const* ipaddress); -uint32 CreatePIDFile(std::string filename); +uint32 CreatePIDFile(const std::string& filename); #endif diff --git a/src/shared/vmap/CoordModelMapping.h b/src/shared/vmap/CoordModelMapping.h index 9482bd23f80..59766e5e7d5 100644 --- a/src/shared/vmap/CoordModelMapping.h +++ b/src/shared/vmap/CoordModelMapping.h @@ -45,8 +45,8 @@ namespace VMAP G3D::Array<std::string> iMainFiles; G3D::Array<std::string> iSingeFiles; - void appendToMain(std::string pStr) { iMainFiles.append(pStr); } - void appendToSingle(std::string pStr) { iSingeFiles.append(pStr); } + void appendToMain(const std::string& pStr) { iMainFiles.append(pStr); } + void appendToSingle(const std::string& pStr) { iSingeFiles.append(pStr); } size_t size() { return (iMainFiles.size() + iSingeFiles.size()); } }; @@ -115,7 +115,7 @@ namespace VMAP const NameCollection getFilenamesForCoordinate(unsigned int pMapId, int xPos, int yPos); - static unsigned int getMapIdFromFilename(std::string pName) + static unsigned int getMapIdFromFilename(const std::string& pName) { size_t spos; @@ -128,8 +128,8 @@ namespace VMAP } const G3D::Array<unsigned int>& getMaps() const { return iMapIds; } - inline bool isAlreadyProcessedSingleFile(std::string pName) { return(iProcesseSingleFiles.containsKey(pName)); } - inline void addAlreadyProcessedSingleFile(std::string pName) { iProcesseSingleFiles.set(pName,pName); } + bool isAlreadyProcessedSingleFile(const std::string& pName) const { return iProcesseSingleFiles.containsKey(pName); } + void addAlreadyProcessedSingleFile(const std::string& pName) { iProcesseSingleFiles.set(pName,pName); } inline void addWorldAreaMap(unsigned int pMapId) { diff --git a/src/shared/vmap/VMapManager.cpp b/src/shared/vmap/VMapManager.cpp index fe105df1f5c..337e553f38d 100644 --- a/src/shared/vmap/VMapManager.cpp +++ b/src/shared/vmap/VMapManager.cpp @@ -277,10 +277,8 @@ namespace VMAP { dirFileName = getDirFileName(pMapId); } - size_t len = pBasePath.length() + dirFileName.length(); - char *filenameBuffer = new char[len+1]; - sprintf(filenameBuffer, "%s%s", pBasePath.c_str(), dirFileName.c_str()); - FILE* df = fopen(filenameBuffer, "rb"); + std::string fb = pBasePath + dirFileName; + FILE* df = fopen(fb.c_str(), "rb"); if(df) { char lineBuffer[FILENAMEBUFFER_SIZE]; @@ -290,8 +288,8 @@ namespace VMAP chomp(name); if(name.length() >1) { - sprintf(filenameBuffer, "%s%s", pBasePath.c_str(), name.c_str()); - FILE* df2 = fopen(filenameBuffer, "rb"); + std::string fb2 = pBasePath + name; + FILE* df2 = fopen(fb2.c_str(), "rb"); if(df2) { char magic[8]; @@ -304,7 +302,6 @@ namespace VMAP } fclose(df); } - delete[] filenameBuffer; return result; } @@ -661,14 +658,12 @@ namespace VMAP bool MapTree::loadMap(const std::string& pDirFileName, unsigned int pMapTileIdent) { bool result = true; - size_t len = iBasePath.length() + pDirFileName.length(); - char *filenameBuffer = new char[len+1]; if(!hasDirFile(pDirFileName)) { FilesInDir filesInDir; result = false; - sprintf(filenameBuffer, "%s%s", iBasePath.c_str(), pDirFileName.c_str()); - FILE* df = fopen(filenameBuffer, "rb"); + std::string fb = iBasePath + pDirFileName; + FILE* df = fopen(fb.c_str(), "rb"); if(df) { char lineBuffer[FILENAMEBUFFER_SIZE]; @@ -728,7 +723,6 @@ namespace VMAP filesInDir.incRefCount(); } } - delete [] filenameBuffer; return (result); } |
