Modernizing countObjectsOfType functions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user