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;
|
||||
|
||||
@@ -2465,7 +2465,7 @@ bool Document::afterRestore(const std::vector<DocumentObject*>& 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<App::DocumentObject*>& 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");
|
||||
}
|
||||
|
||||
@@ -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<DocumentObject*>&
|
||||
auto inLists = getInListEx(true);
|
||||
inLists.emplace(const_cast<DocumentObject*>(this));
|
||||
for (auto obj : linksTo) {
|
||||
if (inLists.count(obj)) {
|
||||
if (inLists.contains(obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -997,7 +997,7 @@ ExpressionPtr Expression::importSubNames(const std::map<std::string,std::string>
|
||||
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);
|
||||
|
||||
@@ -134,7 +134,7 @@ Base::Placement GeoFeatureGroupExtension::recursiveGroupPlacement(
|
||||
auto parent = link->getExtensionByType<GeoFeatureGroupExtension>(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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<DocumentObject*>& inLis
|
||||
}
|
||||
bool found = false;
|
||||
for (auto& v : _Deps) {
|
||||
if (inList.count(v.first)) {
|
||||
if (inList.contains(v.first)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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<App::DocumentObject*>& 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<App::DocumentObject*>& 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<App::DocumentObject*>& 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<App::DocumentObject*>& 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<App::DocumentObject*>& 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user