From ad148587dcf5244c2d2011dba339786c765c54c4 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 4 Nov 2020 16:19:54 +0100 Subject: Make Lint Happy --- src/settings.cpp | 237 ++++++++++++++++++++----------------------------------- 1 file changed, 84 insertions(+), 153 deletions(-) (limited to 'src/settings.cpp') diff --git a/src/settings.cpp b/src/settings.cpp index 55404319e..4f8b7b617 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -42,16 +42,14 @@ Settings::~Settings() clear(); } - -Settings & Settings::operator += (const Settings &other) +Settings &Settings::operator+=(const Settings &other) { update(other); return *this; } - -Settings & Settings::operator = (const Settings &other) +Settings &Settings::operator=(const Settings &other) { if (&other == this) return *this; @@ -65,7 +63,6 @@ Settings & Settings::operator = (const Settings &other) return *this; } - bool Settings::checkNameValid(const std::string &name) { bool valid = name.find_first_of("=\"{}#") == std::string::npos; @@ -73,20 +70,19 @@ bool Settings::checkNameValid(const std::string &name) valid = std::find_if(name.begin(), name.end(), ::isspace) == name.end(); if (!valid) { - errorstream << "Invalid setting name \"" << name << "\"" - << std::endl; + errorstream << "Invalid setting name \"" << name << "\"" << std::endl; return false; } return true; } - bool Settings::checkValueValid(const std::string &value) { if (value.substr(0, 3) == "\"\"\"" || - value.find("\n\"\"\"") != std::string::npos) { + value.find("\n\"\"\"") != std::string::npos) { errorstream << "Invalid character sequence '\"\"\"' found in" - " setting value!" << std::endl; + " setting value!" + << std::endl; return false; } return true; @@ -117,7 +113,6 @@ std::string Settings::getMultiline(std::istream &is, size_t *num_lines) return value; } - bool Settings::readConfigFile(const char *filename) { std::ifstream is(filename); @@ -127,7 +122,6 @@ bool Settings::readConfigFile(const char *filename) return parseConfigLines(is, ""); } - bool Settings::parseConfigLines(std::istream &is, const std::string &end) { MutexAutoLock lock(m_mutex); @@ -166,7 +160,6 @@ bool Settings::parseConfigLines(std::istream &is, const std::string &end) return end.empty(); } - void Settings::writeLines(std::ostream &os, u32 tab_depth) const { MutexAutoLock lock(m_mutex); @@ -175,9 +168,8 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const printEntry(os, setting_it.first, setting_it.second, tab_depth); } - void Settings::printEntry(std::ostream &os, const std::string &name, - const SettingsEntry &entry, u32 tab_depth) + const SettingsEntry &entry, u32 tab_depth) { for (u32 i = 0; i != tab_depth; i++) os << "\t"; @@ -200,9 +192,8 @@ void Settings::printEntry(std::ostream &os, const std::string &name, } } - -bool Settings::updateConfigObject(std::istream &is, std::ostream &os, - const std::string &end, u32 tab_depth) +bool Settings::updateConfigObject( + std::istream &is, std::ostream &os, const std::string &end, u32 tab_depth) { SettingEntries::const_iterator it; std::set present_entries; @@ -227,7 +218,8 @@ bool Settings::updateConfigObject(std::istream &is, std::ostream &os, case SPE_KVPAIR: it = m_settings.find(name); if (it != m_settings.end() && - (it->second.is_group || it->second.value != value)) { + (it->second.is_group || + it->second.value != value)) { printEntry(os, name, it->second, tab_depth); was_modified = true; } else if (it == m_settings.end()) { @@ -246,14 +238,15 @@ bool Settings::updateConfigObject(std::istream &is, std::ostream &os, if (it != m_settings.end() && it->second.is_group) { os << line << "\n"; sanity_check(it->second.group != NULL); - was_modified |= it->second.group->updateConfigObject(is, os, - "}", tab_depth + 1); + was_modified |= it->second.group->updateConfigObject( + is, os, "}", tab_depth + 1); } else if (it == m_settings.end()) { // Remove by skipping was_modified = true; Settings removed_group; // Move 'is' to group end std::stringstream ss; - removed_group.updateConfigObject(is, ss, "}", tab_depth + 1); + removed_group.updateConfigObject( + is, ss, "}", tab_depth + 1); break; } else { printEntry(os, name, it->second, tab_depth); @@ -279,7 +272,6 @@ bool Settings::updateConfigObject(std::istream &is, std::ostream &os, return was_modified; } - bool Settings::updateConfigFile(const char *filename) { MutexAutoLock lock(m_mutex); @@ -294,32 +286,31 @@ bool Settings::updateConfigFile(const char *filename) return true; if (!fs::safeWriteToFile(filename, os.str())) { - errorstream << "Error writing configuration file: \"" - << filename << "\"" << std::endl; + errorstream << "Error writing configuration file: \"" << filename << "\"" + << std::endl; return false; } return true; } - -bool Settings::parseCommandLine(int argc, char *argv[], - std::map &allowed_options) +bool Settings::parseCommandLine( + int argc, char *argv[], std::map &allowed_options) { int nonopt_index = 0; for (int i = 1; i < argc; i++) { std::string arg_name = argv[i]; if (arg_name.substr(0, 2) != "--") { // If option doesn't start with -, read it in as nonoptX - if (arg_name[0] != '-'){ + if (arg_name[0] != '-') { std::string name = "nonopt"; name += itos(nonopt_index); set(name, arg_name); nonopt_index++; continue; } - errorstream << "Invalid command-line parameter \"" - << arg_name << "\": --