From e51ca542d4f451ed4b140a20ff1f682c4ddc0897 Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Fri, 23 Oct 2020 00:03:14 +0200 Subject: [PATCH] components/config cleanup --- components/config/gamesettings.cpp | 73 +++++++++----------------- components/config/gamesettings.hpp | 2 +- components/config/launchersettings.cpp | 8 +-- components/config/settingsbase.hpp | 2 +- 4 files changed, 30 insertions(+), 55 deletions(-) diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index b771b7fc8..b228d23c6 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -7,24 +7,6 @@ #include -#include - -/** - * Workaround for problems with whitespaces in paths in older versions of Boost library - */ -#if (BOOST_VERSION <= 104600) -namespace boost -{ - - template<> - inline boost::filesystem::path lexical_cast(const std::string& arg) - { - return boost::filesystem::path(arg); - } - -} /* namespace boost */ -#endif /* (BOOST_VERSION <= 104600) */ - const char Config::GameSettings::sContentKey[] = "content"; Config::GameSettings::GameSettings(Files::ConfigurationManager &cfg) @@ -32,9 +14,7 @@ Config::GameSettings::GameSettings(Files::ConfigurationManager &cfg) { } -Config::GameSettings::~GameSettings() -{ -} +Config::GameSettings::~GameSettings() = default; void Config::GameSettings::validatePaths() { @@ -51,8 +31,8 @@ void Config::GameSettings::validatePaths() mCfgMgr.processPaths(dataDirs); mDataDirs.clear(); - for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) { - QString path = QString::fromUtf8(it->string().c_str()); + for (auto & dataDir : dataDirs) { + QString path = QString::fromUtf8(dataDir.string().c_str()); QDir dir(path); if (dir.exists()) @@ -186,11 +166,11 @@ bool Config::GameSettings::writeFile(QTextStream &stream) QString string = i.value(); stream << delim; - for (QString::const_iterator it = string.begin(); it != string.end(); ++it) + for (auto it : string) { - if (*it == delim || *it == escape) + if (it == delim || it == escape) stream << escape; - stream << *it; + stream << it; } stream << delim; @@ -219,7 +199,7 @@ bool Config::GameSettings::writeFile(QTextStream &stream) return true; } -bool Config::GameSettings::isOrderedLine(const QString& line) const +bool Config::GameSettings::isOrderedLine(const QString& line) { return line.contains(QRegExp("^\\s*fallback-archive\\s*=")) || line.contains(QRegExp("^\\s*fallback\\s*=")) @@ -287,9 +267,9 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) // QRegExp settingRegex("^([^=]+)\\s*=\\s*([^,]+)(.*)$"); std::vector comments; - std::vector::iterator commentStart = fileCopy.end(); + auto commentStart = fileCopy.end(); std::map > commentsMap; - for (std::vector::iterator iter = fileCopy.begin(); iter != fileCopy.end(); ++iter) + for (auto iter = fileCopy.begin(); iter != fileCopy.end(); ++iter) { if (isOrderedLine(*iter)) { @@ -339,9 +319,9 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) if (commentStart == fileCopy.end()) throw std::runtime_error("Config::GameSettings: failed to parse settings - iterator is past of end of settings file"); - for (std::vector::const_iterator it = comments.begin(); it != comments.end(); ++it) + for (const auto & comment : comments) { - *commentStart = *it; + *commentStart = comment; ++commentStart; } comments.clear(); @@ -383,16 +363,16 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) } // comments at top of file - for (std::vector::iterator iter = fileCopy.begin(); iter != fileCopy.end(); ++iter) + for (auto & iter : fileCopy) { - if ((*iter).isNull()) + if (iter.isNull()) continue; // Below is based on readFile() code, if that changes corresponding change may be // required (for example duplicates may be inserted if the rules don't match) - if (/*(*iter).isEmpty() ||*/ (*iter).contains(QRegExp("^\\s*#"))) + if (/*(*iter).isEmpty() ||*/ iter.contains(QRegExp("^\\s*#"))) { - stream << *iter << "\n"; + stream << iter << "\n"; continue; } } @@ -416,11 +396,11 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) QString string = it.value(); settingLine += delim; - for (QString::const_iterator iter = string.begin(); iter != string.end(); ++iter) + for (auto iter : string) { - if (*iter == delim || *iter == escape) + if (iter == delim || iter == escape) settingLine += escape; - settingLine += *iter; + settingLine += iter; } settingLine += delim; } @@ -438,8 +418,7 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) if (settingRegex.indexIn(settingLine) != -1) { - std::map >::iterator i = - commentsMap.find(settingRegex.cap(1)+"="+settingRegex.cap(2)); + auto i = commentsMap.find(settingRegex.cap(1)+"="+settingRegex.cap(2)); // check if previous removed content item with comments if (i == commentsMap.end()) @@ -448,8 +427,8 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) if (i != commentsMap.end()) { std::vector cLines = i->second; - for (std::vector::const_iterator ci = cLines.begin(); ci != cLines.end(); ++ci) - stream << *ci << "\n"; + for (const auto & cLine : cLines) + stream << cLine << "\n"; commentsMap.erase(i); } @@ -461,14 +440,14 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) // flush any removed settings if (!commentsMap.empty()) { - std::map >::const_iterator i = commentsMap.begin(); + auto i = commentsMap.begin(); for (; i != commentsMap.end(); ++i) { if (i->first.contains(QRegExp("^\\s*content\\s*="))) { std::vector cLines = i->second; - for (std::vector::const_iterator ci = cLines.begin(); ci != cLines.end(); ++ci) - stream << *ci << "\n"; + for (const auto & cLine : cLines) + stream << cLine << "\n"; // mark the content line entry for future preocessing stream << "##" << i->first << "\n"; @@ -481,8 +460,8 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) // flush any end comments if (!comments.empty()) { - for (std::vector::const_iterator ci = comments.begin(); ci != comments.end(); ++ci) - stream << *ci << "\n"; + for (const auto & comment : comments) + stream << comment << "\n"; } file.resize(file.pos()); diff --git a/components/config/gamesettings.hpp b/components/config/gamesettings.hpp index a6876b83d..ccb1d5fd2 100644 --- a/components/config/gamesettings.hpp +++ b/components/config/gamesettings.hpp @@ -88,7 +88,7 @@ namespace Config static const char sContentKey[]; - bool isOrderedLine(const QString& line) const; + static bool isOrderedLine(const QString& line) ; }; } #endif // GAMESETTINGS_HPP diff --git a/components/config/launchersettings.cpp b/components/config/launchersettings.cpp index ae591ef58..ff2c38438 100644 --- a/components/config/launchersettings.cpp +++ b/components/config/launchersettings.cpp @@ -12,13 +12,9 @@ const char Config::LauncherSettings::sLauncherConfigFileName[] = "launcher.cfg"; const char Config::LauncherSettings::sContentListsSectionPrefix[] = "Profiles/"; const char Config::LauncherSettings::sContentListSuffix[] = "/content"; -Config::LauncherSettings::LauncherSettings() -{ -} +Config::LauncherSettings::LauncherSettings() = default; -Config::LauncherSettings::~LauncherSettings() -{ -} +Config::LauncherSettings::~LauncherSettings() = default; QStringList Config::LauncherSettings::subKeys(const QString &key) { diff --git a/components/config/settingsbase.hpp b/components/config/settingsbase.hpp index 119971716..86fa962ae 100644 --- a/components/config/settingsbase.hpp +++ b/components/config/settingsbase.hpp @@ -15,7 +15,7 @@ namespace Config public: SettingsBase() { mMultiValue = false; } - ~SettingsBase() {} + ~SettingsBase() = default; inline QString value(const QString &key, const QString &defaultValue = QString()) const {