App: use contains() instead of count() where possible
This commit is contained in:
@@ -865,7 +865,7 @@ std::vector<Document*> Application::openDocuments(const std::vector<std::string>
|
||||
// It is possible that the newly opened document depends on an existing
|
||||
// document, which will be included with the above call to
|
||||
// Document::getDependentDocuments(). Make sure to exclude that.
|
||||
if(!newDocs.count(doc)) {
|
||||
if(!newDocs.contains(doc)) {
|
||||
it = docs.erase(it);
|
||||
continue;
|
||||
}
|
||||
@@ -2352,7 +2352,7 @@ void parseProgramOptions(int ac, char ** av, const std::string& exe, boost::prog
|
||||
throw Base::UnknownProgramOption(str.str());
|
||||
}
|
||||
|
||||
if (vm.count("help")) {
|
||||
if (vm.contains("help")) {
|
||||
std::stringstream str;
|
||||
str << exe << '\n' << '\n';
|
||||
str << "For a detailed description see https://www.freecad.org/wiki/Start_up_and_Configuration" << '\n'<<'\n';
|
||||
@@ -2361,7 +2361,7 @@ void parseProgramOptions(int ac, char ** av, const std::string& exe, boost::prog
|
||||
throw Base::ProgramInformation(str.str());
|
||||
}
|
||||
|
||||
if (vm.count("response-file")) {
|
||||
if (vm.contains("response-file")) {
|
||||
// Load the file and tokenize it
|
||||
std::ifstream ifs(vm["response-file"].as<std::string>().c_str());
|
||||
if (!ifs) {
|
||||
@@ -2387,14 +2387,14 @@ void parseProgramOptions(int ac, char ** av, const std::string& exe, boost::prog
|
||||
|
||||
void processProgramOptions(const boost::program_options::variables_map& vm, std::map<std::string,std::string>& mConfig)
|
||||
{
|
||||
if (vm.count("version") && !vm.count("verbose")) {
|
||||
if (vm.contains("version") && !vm.contains("verbose")) {
|
||||
std::stringstream str;
|
||||
str << mConfig["ExeName"] << " " << mConfig["ExeVersion"]
|
||||
<< " Revision: " << mConfig["BuildRevision"] << '\n';
|
||||
throw Base::ProgramInformation(str.str());
|
||||
}
|
||||
|
||||
if (vm.count("module-path")) {
|
||||
if (vm.contains("module-path")) {
|
||||
auto Mods = vm["module-path"].as< std::vector<std::string> >();
|
||||
std::string temp;
|
||||
for (const auto & It : Mods)
|
||||
@@ -2403,7 +2403,7 @@ void processProgramOptions(const boost::program_options::variables_map& vm, std:
|
||||
mConfig["AdditionalModulePaths"] = temp;
|
||||
}
|
||||
|
||||
if (vm.count("macro-path")) {
|
||||
if (vm.contains("macro-path")) {
|
||||
std::vector<std::string> Macros = vm["macro-path"].as< std::vector<std::string> >();
|
||||
std::string temp;
|
||||
for (const auto & It : Macros)
|
||||
@@ -2412,13 +2412,13 @@ void processProgramOptions(const boost::program_options::variables_map& vm, std:
|
||||
mConfig["AdditionalMacroPaths"] = std::move(temp);
|
||||
}
|
||||
|
||||
if (vm.count("python-path")) {
|
||||
if (vm.contains("python-path")) {
|
||||
auto Paths = vm["python-path"].as< std::vector<std::string> >();
|
||||
for (const auto & It : Paths)
|
||||
Base::Interpreter().addPythonPath(It.c_str());
|
||||
}
|
||||
|
||||
if (vm.count("disable-addon")) {
|
||||
if (vm.contains("disable-addon")) {
|
||||
auto Addons = vm["disable-addon"].as< std::vector<std::string> >();
|
||||
std::string temp;
|
||||
for (const auto & It : Addons) {
|
||||
@@ -2428,7 +2428,7 @@ void processProgramOptions(const boost::program_options::variables_map& vm, std:
|
||||
mConfig["DisabledAddons"] = temp;
|
||||
}
|
||||
|
||||
if (vm.count("input-file")) {
|
||||
if (vm.contains("input-file")) {
|
||||
auto files(vm["input-file"].as< std::vector<std::string> >());
|
||||
int OpenFileCount=0;
|
||||
for (const auto & It : files) {
|
||||
@@ -2443,34 +2443,34 @@ void processProgramOptions(const boost::program_options::variables_map& vm, std:
|
||||
mConfig["OpenFileCount"] = buffer.str();
|
||||
}
|
||||
|
||||
if (vm.count("output")) {
|
||||
if (vm.contains("output")) {
|
||||
mConfig["SaveFile"] = vm["output"].as<std::string>();
|
||||
}
|
||||
|
||||
if (vm.count("hidden")) {
|
||||
if (vm.contains("hidden")) {
|
||||
mConfig["StartHidden"] = "1";
|
||||
}
|
||||
|
||||
if (vm.count("write-log")) {
|
||||
if (vm.contains("write-log")) {
|
||||
mConfig["LoggingFile"] = "1";
|
||||
mConfig["LoggingFileName"] = mConfig["UserAppData"] + mConfig["ExeName"] + ".log";
|
||||
}
|
||||
|
||||
if (vm.count("log-file")) {
|
||||
if (vm.contains("log-file")) {
|
||||
mConfig["LoggingFile"] = "1";
|
||||
mConfig["LoggingFileName"] = vm["log-file"].as<std::string>();
|
||||
}
|
||||
|
||||
if (vm.count("user-cfg")) {
|
||||
if (vm.contains("user-cfg")) {
|
||||
mConfig["UserParameter"] = vm["user-cfg"].as<std::string>();
|
||||
}
|
||||
|
||||
if (vm.count("system-cfg")) {
|
||||
if (vm.contains("system-cfg")) {
|
||||
mConfig["SystemParameter"] = vm["system-cfg"].as<std::string>();
|
||||
}
|
||||
|
||||
if (vm.count("run-test") || vm.count("run-open")) {
|
||||
std::string testCase = vm.count("run-open") ? vm["run-open"].as<std::string>() : vm["run-test"].as<std::string>();
|
||||
if (vm.contains("run-test") || vm.contains("run-open")) {
|
||||
std::string testCase = vm.contains("run-open") ? vm["run-open"].as<std::string>() : vm["run-test"].as<std::string>();
|
||||
|
||||
if ( "0" == testCase) {
|
||||
testCase = "TestApp.All";
|
||||
@@ -2481,14 +2481,14 @@ void processProgramOptions(const boost::program_options::variables_map& vm, std:
|
||||
mConfig["TestCase"] = std::move(testCase);
|
||||
mConfig["RunMode"] = "Internal";
|
||||
mConfig["ScriptFileName"] = "FreeCADTest";
|
||||
mConfig["ExitTests"] = vm.count("run-open") == 0 ? "yes" : "no";
|
||||
mConfig["ExitTests"] = vm.contains("run-open") ? "no" : "yes";
|
||||
}
|
||||
|
||||
if (vm.count("single-instance")) {
|
||||
if (vm.contains("single-instance")) {
|
||||
mConfig["SingleInstance"] = "1";
|
||||
}
|
||||
|
||||
if (vm.count("dump-config")) {
|
||||
if (vm.contains("dump-config")) {
|
||||
std::stringstream str;
|
||||
for (const auto & it : mConfig) {
|
||||
str << it.first << "=" << it.second << '\n';
|
||||
@@ -2496,7 +2496,7 @@ void processProgramOptions(const boost::program_options::variables_map& vm, std:
|
||||
throw Base::ProgramInformation(str.str());
|
||||
}
|
||||
|
||||
if (vm.count("get-config")) {
|
||||
if (vm.contains("get-config")) {
|
||||
auto configKey = vm["get-config"].as<std::string>();
|
||||
std::stringstream str;
|
||||
std::map<std::string,std::string>::iterator pos;
|
||||
@@ -2508,7 +2508,7 @@ void processProgramOptions(const boost::program_options::variables_map& vm, std:
|
||||
throw Base::ProgramInformation(str.str());
|
||||
}
|
||||
|
||||
if (vm.count("set-config")) {
|
||||
if (vm.contains("set-config")) {
|
||||
auto configKeyValue = vm["set-config"].as< std::vector<std::string> >();
|
||||
for (const auto& it : configKeyValue) {
|
||||
auto pos = it.find('=');
|
||||
@@ -2572,7 +2572,7 @@ void Application::initConfig(int argc, char ** argv)
|
||||
BOOST_SCOPE_EXIT_ALL(&) {
|
||||
// console-mode needs to be set (if possible) also in case parseProgramOptions
|
||||
// throws, as it's needed when reporting such exceptions
|
||||
if (vm.count("console")) {
|
||||
if (vm.contains("console")) {
|
||||
mConfig["Console"] = "1";
|
||||
mConfig["RunMode"] = "Cmd";
|
||||
}
|
||||
@@ -2580,14 +2580,14 @@ void Application::initConfig(int argc, char ** argv)
|
||||
parseProgramOptions(argc, argv, mConfig["ExeName"], vm);
|
||||
}
|
||||
|
||||
if (vm.count("keep-deprecated-paths")) {
|
||||
if (vm.contains("keep-deprecated-paths")) {
|
||||
mConfig["KeepDeprecatedPaths"] = "1";
|
||||
}
|
||||
|
||||
// extract home paths
|
||||
ExtractUserPath();
|
||||
|
||||
if (vm.count("safe-mode")) {
|
||||
if (vm.contains("safe-mode")) {
|
||||
SafeMode::StartSafeMode();
|
||||
}
|
||||
|
||||
@@ -2654,7 +2654,7 @@ void Application::initConfig(int argc, char ** argv)
|
||||
_pConsoleObserverFile = nullptr;
|
||||
|
||||
// Banner ===========================================================
|
||||
if (mConfig["RunMode"] != "Cmd" && !(vm.count("verbose") && vm.count("version"))) {
|
||||
if (mConfig["RunMode"] != "Cmd" && !(vm.contains("verbose") && vm.contains("version"))) {
|
||||
// Remove banner if FreeCAD is invoked via the -c command as regular
|
||||
// Python interpreter
|
||||
if (mConfig["Verbose"] != "Strict")
|
||||
@@ -2766,7 +2766,7 @@ void Application::initConfig(int argc, char ** argv)
|
||||
|
||||
logStatus();
|
||||
|
||||
if (vm.count("verbose") && vm.count("version")) {
|
||||
if (vm.contains("verbose") && vm.contains("version")) {
|
||||
Application::_pcSingleton = new Application(mConfig);
|
||||
throw Base::ProgramInformation(Application::verboseVersionEmitMessage);
|
||||
}
|
||||
@@ -3290,7 +3290,7 @@ std::tuple<QString, QString, QString, QString> getStandardPaths()
|
||||
|
||||
void Application::ExtractUserPath()
|
||||
{
|
||||
bool keepDeprecatedPaths = mConfig.count("KeepDeprecatedPaths") > 0;
|
||||
bool keepDeprecatedPaths = mConfig.contains("KeepDeprecatedPaths");
|
||||
|
||||
// std paths
|
||||
mConfig["BinPath"] = mConfig["AppHomePath"] + "bin" + PATHSEP;
|
||||
|
||||
Reference in New Issue
Block a user