App: modernize C++: use range-based for loop

This commit is contained in:
wmayer
2023-08-14 16:37:45 +02:00
committed by wwmayer
parent 367cdb36ed
commit 26f16f7410
22 changed files with 422 additions and 418 deletions

View File

@@ -631,9 +631,9 @@ PyObject* DocumentPy::getObjectsByLabel(PyObject *args)
Py::List list;
std::string name = sName;
std::vector<DocumentObject*> objs = getDocumentPtr()->getObjects();
for (std::vector<DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
if (name == (*it)->Label.getValue())
list.append(Py::asObject((*it)->getPyObject()));
for (auto obj : objs) {
if (name == obj->Label.getValue())
list.append(Py::asObject(obj->getPyObject()));
}
return Py::new_reference_to(list);
@@ -687,8 +687,8 @@ PyObject* DocumentPy::supportedTypes(PyObject *args)
std::vector<Base::Type> ary;
Base::Type::getAllDerivedFrom(App::DocumentObject::getClassTypeId(), ary);
Py::List res;
for (std::vector<Base::Type>::iterator it = ary.begin(); it != ary.end(); ++it)
res.append(Py::String(it->getName()));
for (const auto & it : ary)
res.append(Py::String(it.getName()));
return Py::new_reference_to(res);
}
@@ -697,9 +697,9 @@ Py::List DocumentPy::getObjects() const
std::vector<DocumentObject*> objs = getDocumentPtr()->getObjects();
Py::List res;
for (std::vector<DocumentObject*>::const_iterator It = objs.begin();It != objs.end();++It)
for (auto obj : objs)
//Note: Here we must force the Py::Object to own this Python object as getPyObject() increments the counter
res.append(Py::Object((*It)->getPyObject(), true));
res.append(Py::Object(obj->getPyObject(), true));
return res;
}
@@ -709,9 +709,9 @@ Py::List DocumentPy::getTopologicalSortedObjects() const
std::vector<DocumentObject*> objs = getDocumentPtr()->topologicalSort();
Py::List res;
for (std::vector<DocumentObject*>::const_iterator It = objs.begin(); It != objs.end(); ++It)
for (auto obj : objs)
//Note: Here we must force the Py::Object to own this Python object as getPyObject() increments the counter
res.append(Py::Object((*It)->getPyObject(), true));
res.append(Py::Object(obj->getPyObject(), true));
return res;
}
@@ -721,9 +721,9 @@ Py::List DocumentPy::getRootObjects() const
std::vector<DocumentObject*> objs = getDocumentPtr()->getRootObjects();
Py::List res;
for (std::vector<DocumentObject*>::const_iterator It = objs.begin(); It != objs.end(); ++It)
for (auto obj : objs)
//Note: Here we must force the Py::Object to own this Python object as getPyObject() increments the counter
res.append(Py::Object((*It)->getPyObject(), true));
res.append(Py::Object(obj->getPyObject(), true));
return res;
}
@@ -759,8 +759,8 @@ Py::List DocumentPy::getUndoNames() const
std::vector<std::string> vList = getDocumentPtr()->getAvailableUndoNames();
Py::List res;
for (std::vector<std::string>::const_iterator It = vList.begin();It!=vList.end();++It)
res.append(Py::String(*It));
for (const auto & It : vList)
res.append(Py::String(It));
return res;
}
@@ -770,8 +770,8 @@ Py::List DocumentPy::getRedoNames() const
std::vector<std::string> vList = getDocumentPtr()->getAvailableRedoNames();
Py::List res;
for (std::vector<std::string>::const_iterator It = vList.begin();It!=vList.end();++It)
res.append(Py::String(*It));
for (const auto & It : vList)
res.append(Py::String(It));
return res;
}