mirror of
https://github.com/edubart/otclient.git
synced 2025-12-28 10:27:12 +01:00
Tidy up the source code
* Replaced push_back calls with emplace_back where applicable. * Replaced size() == 0 and size() != 0 with empty() and !empty(). * Replaced C style loops for range for loops where applicable. * Fixed mismatching arg names between function declarations and definitions. * Replaced NULL and 0 (in the context of pointers) with nullptr. * Remove unnecessary calls to string::c_str() where applicable. * Replaced deprecated C headers with proper C++ headers. * Removed unnecessary null pointer checks when deleting pointers (deleting a null pointer has no effect). * Fixed a potential memory leak in apngloader.cpp file. * Replaced unsafe strcpy with strncpy in the demangle_name function.
This commit is contained in:
@@ -38,7 +38,7 @@ void AsyncDispatcher::terminate()
|
||||
void AsyncDispatcher::spawn_thread()
|
||||
{
|
||||
m_running = true;
|
||||
m_threads.push_back(std::thread(std::bind(&AsyncDispatcher::exec_loop, this)));
|
||||
m_threads.emplace_back(std::bind(&AsyncDispatcher::exec_loop, this));
|
||||
}
|
||||
|
||||
void AsyncDispatcher::stop()
|
||||
@@ -55,7 +55,7 @@ void AsyncDispatcher::stop()
|
||||
void AsyncDispatcher::exec_loop() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
while(true) {
|
||||
while(m_tasks.size() == 0 && m_running)
|
||||
while(m_tasks.empty() && m_running)
|
||||
m_condition.wait(lock);
|
||||
|
||||
if(!m_running)
|
||||
|
||||
@@ -74,7 +74,7 @@ void Config::clear()
|
||||
|
||||
void Config::setValue(const std::string& key, const std::string& value)
|
||||
{
|
||||
if(value == "") {
|
||||
if(value.empty()) {
|
||||
remove(key);
|
||||
return;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ void Config::setList(const std::string& key, const std::vector<std::string>& lis
|
||||
{
|
||||
remove(key);
|
||||
|
||||
if(list.size() == 0)
|
||||
if(list.empty())
|
||||
return;
|
||||
|
||||
OTMLNodePtr child = OTMLNode::create(key, true);
|
||||
|
||||
@@ -320,7 +320,7 @@ std::string FileStream::getString()
|
||||
} else {
|
||||
if(m_pos+len > m_data.size()) {
|
||||
throwError("read failed");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
str = std::string((char*)&m_data[m_pos], len);
|
||||
|
||||
@@ -74,8 +74,8 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
|
||||
m_outFile.flush();
|
||||
}
|
||||
|
||||
std::size_t now = std::time(NULL);
|
||||
m_logMessages.push_back(LogMessage(level, outmsg, now));
|
||||
std::size_t now = std::time(nullptr);
|
||||
m_logMessages.emplace_back(level, outmsg, now);
|
||||
if(m_logMessages.size() > MAX_LOG_HISTORY)
|
||||
m_logMessages.pop_front();
|
||||
|
||||
@@ -133,7 +133,7 @@ void Logger::setLogFile(const std::string& file)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
|
||||
m_outFile.open(stdext::utf8_to_latin1(file.c_str()).c_str(), std::ios::out | std::ios::app);
|
||||
m_outFile.open(stdext::utf8_to_latin1(file).c_str(), std::ios::out | std::ios::app);
|
||||
if(!m_outFile.is_open() || !m_outFile.good()) {
|
||||
g_logger.error(stdext::format("Unable to save log to '%s'", file));
|
||||
return;
|
||||
|
||||
@@ -264,8 +264,8 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
|
||||
std::list<std::string> files;
|
||||
auto rc = PHYSFS_enumerateFiles(resolvePath(directoryPath).c_str());
|
||||
|
||||
for(int i = 0; rc[i] != NULL; i++)
|
||||
files.push_back(rc[i]);
|
||||
for(int i = 0; rc[i] != nullptr; i++)
|
||||
files.emplace_back(rc[i]);
|
||||
|
||||
PHYSFS_freeList(rc);
|
||||
return files;
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
bool addSearchPath(const std::string& path, bool pushFront = false);
|
||||
bool removeSearchPath(const std::string& path);
|
||||
void searchAndAddPackages(const std::string& packagesDir, const std::string& packagesExt);
|
||||
void searchAndAddPackages(const std::string& packagesDir, const std::string& packageExt);
|
||||
|
||||
bool fileExists(const std::string& fileName);
|
||||
bool directoryExists(const std::string& directoryName);
|
||||
|
||||
Reference in New Issue
Block a user