From 02d095f6e216db710d5465c0b6c965d185b3bcb1 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Mon, 10 Mar 2025 21:36:17 +0100 Subject: [PATCH] App: use `contains()` instead of `count()` where possible --- src/App/Application.cpp | 56 ++++++++++++++-------------- src/App/Document.cpp | 4 +- src/App/DocumentObject.cpp | 4 +- src/App/Expression.cpp | 2 +- src/App/GeoFeatureGroupExtension.cpp | 2 +- src/App/Link.cpp | 4 +- src/App/PropertyExpressionEngine.cpp | 4 +- src/App/PropertyLinks.cpp | 12 +++--- 8 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 3e7d942e29..cf36bce8ab 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -865,7 +865,7 @@ std::vector Application::openDocuments(const std::vector // 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().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& 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 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 Macros = vm["macro-path"].as< std::vector >(); 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 >(); 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 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 >()); 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(); } - 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(); } - if (vm.count("user-cfg")) { + if (vm.contains("user-cfg")) { mConfig["UserParameter"] = vm["user-cfg"].as(); } - if (vm.count("system-cfg")) { + if (vm.contains("system-cfg")) { mConfig["SystemParameter"] = vm["system-cfg"].as(); } - if (vm.count("run-test") || vm.count("run-open")) { - std::string testCase = vm.count("run-open") ? vm["run-open"].as() : vm["run-test"].as(); + if (vm.contains("run-test") || vm.contains("run-open")) { + std::string testCase = vm.contains("run-open") ? vm["run-open"].as() : vm["run-test"].as(); 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::stringstream str; std::map::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 >(); 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 getStandardPaths() void Application::ExtractUserPath() { - bool keepDeprecatedPaths = mConfig.count("KeepDeprecatedPaths") > 0; + bool keepDeprecatedPaths = mConfig.contains("KeepDeprecatedPaths"); // std paths mConfig["BinPath"] = mConfig["AppHomePath"] + "bin" + PATHSEP; diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 01d1e3c3ac..5c646bebbb 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2465,7 +2465,7 @@ bool Document::afterRestore(const std::vector& objArray, bool c // partial document touched, signal full reload return false; } - else if (!d->touchedObjs.count(obj)) { + else if (!d->touchedObjs.contains(obj)) { obj->purgeTouched(); } @@ -3065,7 +3065,7 @@ int Document::recompute(const std::vector& objs, for (size_t i = 0; i < topoSortedObjects.size(); ++i) { auto obj = topoSortedObjects[i]; obj->setStatus(ObjectStatus::Recompute2, false); - if (!filter.count(obj) && obj->isTouched()) { + if (!filter.contains(obj) && obj->isTouched()) { if (passes > 0) { FC_ERR(obj->getFullName() << " still touched after recompute"); } diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index cfa8fe077f..d8d1c439af 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -581,7 +581,7 @@ bool _isInInListRecursive(const DocumentObject* act, const DocumentObject* check bool DocumentObject::isInInListRecursive(DocumentObject* linkTo) const { - return this == linkTo || getInListEx(true).count(linkTo); + return this == linkTo || getInListEx(true).contains(linkTo); } bool DocumentObject::isInInList(DocumentObject* linkTo) const @@ -644,7 +644,7 @@ bool DocumentObject::testIfLinkDAGCompatible(const std::vector& auto inLists = getInListEx(true); inLists.emplace(const_cast(this)); for (auto obj : linksTo) { - if (inLists.count(obj)) { + if (inLists.contains(obj)) { return false; } } diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 90ae19d2b0..273b8ae85d 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -997,7 +997,7 @@ ExpressionPtr Expression::importSubNames(const std::map if(it!=nameMap.end()) subNameMap.emplace(std::make_pair(obj,std::string()),it->second); auto key = std::make_pair(obj,path.getSubObjectName()); - if(key.second.empty() || subNameMap.count(key)) + if(key.second.empty() || subNameMap.contains(key)) continue; std::string imported = PropertyLinkBase::tryImportSubName( obj,key.second.c_str(),owner->getDocument(), nameMap); diff --git a/src/App/GeoFeatureGroupExtension.cpp b/src/App/GeoFeatureGroupExtension.cpp index 2828430ff4..0d0fd7c76a 100644 --- a/src/App/GeoFeatureGroupExtension.cpp +++ b/src/App/GeoFeatureGroupExtension.cpp @@ -134,7 +134,7 @@ Base::Placement GeoFeatureGroupExtension::recursiveGroupPlacement( auto parent = link->getExtensionByType(true); if (parent && parent->hasObject(group->getExtendedObject())) { // Cyclic dependencies detected - if (history.count(parent) > 0) { + if (history.contains(parent)) { break; } return recursiveGroupPlacement(parent, history) * group->placement().getValue(); diff --git a/src/App/Link.cpp b/src/App/Link.cpp index 36506e8259..b605cf08df 100644 --- a/src/App/Link.cpp +++ b/src/App/Link.cpp @@ -880,7 +880,7 @@ bool LinkBaseExtension::setupCopyOnChange( if (!gname || !boost::starts_with(gname, _GroupPrefix)) { continue; } - if (!newProps.count(prop)) { + if (!newProps.contains(prop)) { parent->removeDynamicProperty(prop->getName()); } } @@ -1833,7 +1833,7 @@ void LinkBaseExtension::updateGroup() } } for (auto it = plainGroupConns.begin(); it != plainGroupConns.end();) { - if (!groupSet.count(it->first)) { + if (!groupSet.contains(it->first)) { it = plainGroupConns.erase(it); } else { diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index 0667061b58..31038c4494 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -873,7 +873,7 @@ PropertyExpressionEngine::validateExpression(const ObjectIdentifier& path, auto inList = pathDocObj->getInListEx(true); for (auto& v : expr->getDepObjects()) { auto docObj = v.first; - if (!v.second && inList.count(docObj)) { + if (!v.second && inList.contains(docObj)) { std::stringstream ss; ss << "cyclic reference to " << docObj->getFullName(); return ss.str(); @@ -1008,7 +1008,7 @@ bool PropertyExpressionEngine::adjustLink(const std::set& inLis } bool found = false; for (auto& v : _Deps) { - if (inList.count(v.first)) { + if (inList.contains(v.first)) { found = true; break; } diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 6c536ec398..35b4ea3e29 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -2107,7 +2107,7 @@ adjustLinkSubs(App::PropertyLinkBase* prop, break; } if (!newLink) { - if (inList.count(sobj)) { + if (inList.contains(sobj)) { continue; } newLink = sobj; @@ -2138,7 +2138,7 @@ bool PropertyLinkSub::adjustLink(const std::set& inList) if (_pcScope == LinkScope::Hidden) { return false; } - if (!_pcLinkSub || !_pcLinkSub->isAttachedToDocument() || !inList.count(_pcLinkSub)) { + if (!_pcLinkSub || !_pcLinkSub->isAttachedToDocument() || !inList.contains(_pcLinkSub)) { return false; } auto subs = _cSubList; @@ -3229,7 +3229,7 @@ bool PropertyLinkSubList::adjustLink(const std::set& inLis for (std::string& sub : subs) { ++idx; auto& link = links[idx]; - if (!link || !link->isAttachedToDocument() || !inList.count(link)) { + if (!link || !link->isAttachedToDocument() || !inList.contains(link)) { continue; } touched = true; @@ -3240,7 +3240,7 @@ bool PropertyLinkSubList::adjustLink(const std::set& inLis pos = std::string::npos; break; } - if (!inList.count(sobj)) { + if (!inList.contains(sobj)) { link = sobj; sub = sub.substr(pos + 1); break; @@ -4657,7 +4657,7 @@ bool PropertyXLink::adjustLink(const std::set& inList) if (_pcScope == LinkScope::Hidden) { return false; } - if (!_pcLink || !_pcLink->isAttachedToDocument() || !inList.count(_pcLink)) { + if (!_pcLink || !_pcLink->isAttachedToDocument() || !inList.contains(_pcLink)) { return false; } auto subs = _SubList; @@ -5479,7 +5479,7 @@ bool PropertyXLinkSubList::adjustLink(const std::set& inLi ++count; continue; } - if (inList.count(obj) && adjustLinkSubs(this, inList, obj, l._SubList, &values)) { + if (inList.contains(obj) && adjustLinkSubs(this, inList, obj, l._SubList, &values)) { touched = true; } }