Modernizing countObjectsOfType functions

This commit is contained in:
Benjamin Nauck
2025-01-11 19:57:53 +01:00
parent 7b22027b90
commit 3ea3ae0132
2 changed files with 6 additions and 15 deletions

View File

@@ -4397,14 +4397,9 @@ Document::findObjects(const Base::Type& typeId, const char* objname, const char*
int Document::countObjectsOfType(const Base::Type& typeId) const
{
int ct = 0;
for (const auto& it : d->objectMap) {
if (it.second->getTypeId().isDerivedFrom(typeId)) {
ct++;
}
}
return ct;
return std::count_if(d->objectMap.begin(), d->objectMap.end(), [&](const auto& it) {
return it.second->getTypeId().isDerivedFrom(typeId);
});
}
int Document::countObjectsOfType(const char* typeName) const

View File

@@ -526,7 +526,6 @@ std::vector<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const cha
unsigned int SelectionSingleton::countObjectsOfType(const Base::Type& typeId, const char* pDocName, ResolveMode resolve) const
{
unsigned int iNbr=0;
App::Document *pcDoc = nullptr;
if(!pDocName || strcmp(pDocName,"*") != 0) {
pcDoc = getDocument(pDocName);
@@ -534,12 +533,9 @@ unsigned int SelectionSingleton::countObjectsOfType(const Base::Type& typeId, co
return 0;
}
for (auto &sel : _SelList) {
if((!pcDoc||pcDoc==sel.pDoc) && getObjectOfType(sel, typeId, resolve))
iNbr++;
}
return iNbr;
return std::count_if(_SelList.begin(), _SelList.end(), [&](auto& sel) {
return (!pcDoc || pcDoc == sel.pDoc) && getObjectOfType(sel, typeId, resolve);
});
}
unsigned int SelectionSingleton::countObjectsOfType(const char* typeName, const char* pDocName, ResolveMode resolve) const