From 26f16f74101e90456cbfcb9c362756e58e9f9bf4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 14 Aug 2023 16:37:45 +0200 Subject: [PATCH] App: modernize C++: use range-based for loop --- src/App/Application.cpp | 148 ++++++++++++++------------- src/App/ApplicationPy.cpp | 40 ++++---- src/App/ComplexGeoDataPyImp.cpp | 62 +++++------ src/App/Document.cpp | 134 +++++++++++++----------- src/App/DocumentObjectPyImp.cpp | 22 ++-- src/App/DocumentPyImp.cpp | 30 +++--- src/App/Enumeration.cpp | 4 +- src/App/Expression.cpp | 8 +- src/App/Graphviz.cpp | 74 +++++++------- src/App/GroupExtension.cpp | 10 +- src/App/Link.cpp | 8 +- src/App/LinkBaseExtensionPyImp.cpp | 8 +- src/App/ObjectIdentifier.cpp | 12 +-- src/App/PropertyContainer.cpp | 20 ++-- src/App/PropertyContainerPyImp.cpp | 8 +- src/App/PropertyExpressionEngine.cpp | 50 ++++----- src/App/PropertyGeo.cpp | 54 +++++----- src/App/PropertyLinks.cpp | 32 +++--- src/App/PropertyPythonObject.cpp | 18 ++-- src/App/PropertyStandard.cpp | 76 +++++++------- src/App/Transactions.cpp | 14 +-- src/App/VRMLObject.cpp | 8 +- 22 files changed, 422 insertions(+), 418 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 3b7aa459f0..1aeed367dd 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -573,9 +573,11 @@ App::Document* Application::getDocument(const char *Name) const const char * Application::getDocumentName(const App::Document* doc) const { - for (std::map::const_iterator it = DocMap.begin(); it != DocMap.end(); ++it) - if (it->second == doc) - return it->first.c_str(); + for (const auto & it : DocMap) { + if (it.second == doc) { + return it.first.c_str(); + } + } return nullptr; } @@ -583,8 +585,8 @@ const char * Application::getDocumentName(const App::Document* doc) const std::vector Application::getDocuments() const { std::vector docs; - for (std::map::const_iterator it = DocMap.begin(); it != DocMap.end(); ++it) - docs.push_back(it->second); + for (const auto & it : DocMap) + docs.push_back(it.second); return docs; } @@ -1334,15 +1336,15 @@ void Application::changeImportModule(const char* Type, const char* OldModuleName std::vector Application::getImportModules(const char* Type) const { std::vector modules; - for (std::vector::const_iterator it = _mImportTypes.begin(); it != _mImportTypes.end(); ++it) { - const std::vector& types = it->types; - for (std::vector::const_iterator jt = types.begin(); jt != types.end(); ++jt) { + for (const auto & it : _mImportTypes) { + const std::vector& types = it.types; + for (const auto & jt : types) { #ifdef __GNUC__ - if (strcasecmp(Type,jt->c_str()) == 0) + if (strcasecmp(Type,jt.c_str()) == 0) #else - if (_stricmp(Type,jt->c_str()) == 0) + if (_stricmp(Type,jt.c_str()) == 0) #endif - modules.push_back(it->module); + modules.push_back(it.module); } } @@ -1352,8 +1354,8 @@ std::vector Application::getImportModules(const char* Type) const std::vector Application::getImportModules() const { std::vector modules; - for (std::vector::const_iterator it = _mImportTypes.begin(); it != _mImportTypes.end(); ++it) - modules.push_back(it->module); + for (const auto & it : _mImportTypes) + modules.push_back(it.module); std::sort(modules.begin(), modules.end()); modules.erase(std::unique(modules.begin(), modules.end()), modules.end()); return modules; @@ -1362,13 +1364,13 @@ std::vector Application::getImportModules() const std::vector Application::getImportTypes(const char* Module) const { std::vector types; - for (std::vector::const_iterator it = _mImportTypes.begin(); it != _mImportTypes.end(); ++it) { + for (const auto & it : _mImportTypes) { #ifdef __GNUC__ - if (strcasecmp(Module,it->module.c_str()) == 0) + if (strcasecmp(Module,it.module.c_str()) == 0) #else - if (_stricmp(Module,it->module.c_str()) == 0) + if (_stricmp(Module,it.module.c_str()) == 0) #endif - types.insert(types.end(), it->types.begin(), it->types.end()); + types.insert(types.end(), it.types.begin(), it.types.end()); } return types; @@ -1377,8 +1379,8 @@ std::vector Application::getImportTypes(const char* Module) const std::vector Application::getImportTypes() const { std::vector types; - for (std::vector::const_iterator it = _mImportTypes.begin(); it != _mImportTypes.end(); ++it) { - types.insert(types.end(), it->types.begin(), it->types.end()); + for (const auto & it : _mImportTypes) { + types.insert(types.end(), it.types.begin(), it.types.end()); } std::sort(types.begin(), types.end()); @@ -1390,15 +1392,15 @@ std::vector Application::getImportTypes() const std::map Application::getImportFilters(const char* Type) const { std::map moduleFilter; - for (std::vector::const_iterator it = _mImportTypes.begin(); it != _mImportTypes.end(); ++it) { - const std::vector& types = it->types; - for (std::vector::const_iterator jt = types.begin(); jt != types.end(); ++jt) { + for (const auto & it : _mImportTypes) { + const std::vector& types = it.types; + for (const auto & jt : types) { #ifdef __GNUC__ - if (strcasecmp(Type,jt->c_str()) == 0) + if (strcasecmp(Type,jt.c_str()) == 0) #else - if (_stricmp(Type,jt->c_str()) == 0) + if (_stricmp(Type,jt.c_str()) == 0) #endif - moduleFilter[it->filter] = it->module; + moduleFilter[it.filter] = it.module; } } @@ -1408,8 +1410,8 @@ std::map Application::getImportFilters(const char* Typ std::map Application::getImportFilters() const { std::map filter; - for (std::vector::const_iterator it = _mImportTypes.begin(); it != _mImportTypes.end(); ++it) { - filter[it->filter] = it->module; + for (const auto & it : _mImportTypes) { + filter[it.filter] = it.module; } return filter; @@ -1457,15 +1459,15 @@ void Application::changeExportModule(const char* Type, const char* OldModuleName std::vector Application::getExportModules(const char* Type) const { std::vector modules; - for (std::vector::const_iterator it = _mExportTypes.begin(); it != _mExportTypes.end(); ++it) { - const std::vector& types = it->types; - for (std::vector::const_iterator jt = types.begin(); jt != types.end(); ++jt) { + for (const auto & it : _mExportTypes) { + const std::vector& types = it.types; + for (const auto & jt : types) { #ifdef __GNUC__ - if (strcasecmp(Type,jt->c_str()) == 0) + if (strcasecmp(Type,jt.c_str()) == 0) #else - if (_stricmp(Type,jt->c_str()) == 0) + if (_stricmp(Type,jt.c_str()) == 0) #endif - modules.push_back(it->module); + modules.push_back(it.module); } } @@ -1475,8 +1477,8 @@ std::vector Application::getExportModules(const char* Type) const std::vector Application::getExportModules() const { std::vector modules; - for (std::vector::const_iterator it = _mExportTypes.begin(); it != _mExportTypes.end(); ++it) - modules.push_back(it->module); + for (const auto & it : _mExportTypes) + modules.push_back(it.module); std::sort(modules.begin(), modules.end()); modules.erase(std::unique(modules.begin(), modules.end()), modules.end()); return modules; @@ -1485,13 +1487,13 @@ std::vector Application::getExportModules() const std::vector Application::getExportTypes(const char* Module) const { std::vector types; - for (std::vector::const_iterator it = _mExportTypes.begin(); it != _mExportTypes.end(); ++it) { + for (const auto & it : _mExportTypes) { #ifdef __GNUC__ - if (strcasecmp(Module,it->module.c_str()) == 0) + if (strcasecmp(Module,it.module.c_str()) == 0) #else - if (_stricmp(Module,it->module.c_str()) == 0) + if (_stricmp(Module,it.module.c_str()) == 0) #endif - types.insert(types.end(), it->types.begin(), it->types.end()); + types.insert(types.end(), it.types.begin(), it.types.end()); } return types; @@ -1500,8 +1502,8 @@ std::vector Application::getExportTypes(const char* Module) const std::vector Application::getExportTypes() const { std::vector types; - for (std::vector::const_iterator it = _mExportTypes.begin(); it != _mExportTypes.end(); ++it) { - types.insert(types.end(), it->types.begin(), it->types.end()); + for (const FileTypeItem& it : _mExportTypes) { + types.insert(types.end(), it.types.begin(), it.types.end()); } std::sort(types.begin(), types.end()); @@ -1513,15 +1515,15 @@ std::vector Application::getExportTypes() const std::map Application::getExportFilters(const char* Type) const { std::map moduleFilter; - for (std::vector::const_iterator it = _mExportTypes.begin(); it != _mExportTypes.end(); ++it) { - const std::vector& types = it->types; - for (std::vector::const_iterator jt = types.begin(); jt != types.end(); ++jt) { + for (const auto & it : _mExportTypes) { + const std::vector& types = it.types; + for (const auto & jt : types) { #ifdef __GNUC__ - if (strcasecmp(Type,jt->c_str()) == 0) + if (strcasecmp(Type,jt.c_str()) == 0) #else - if (_stricmp(Type,jt->c_str()) == 0) + if (_stricmp(Type,jt.c_str()) == 0) #endif - moduleFilter[it->filter] = it->module; + moduleFilter[it.filter] = it.module; } } @@ -1531,8 +1533,8 @@ std::map Application::getExportFilters(const char* Typ std::map Application::getExportFilters() const { std::map filter; - for (std::vector::const_iterator it = _mExportTypes.begin(); it != _mExportTypes.end(); ++it) { - filter[it->filter] = it->module; + for (const FileTypeItem& it : _mExportTypes) { + filter[it.filter] = it.module; } return filter; @@ -1677,12 +1679,12 @@ void Application::destruct() // now save all other parameter files auto& paramMgr = _pcSingleton->mpcPramManager; - for (auto it = paramMgr.begin(); it != paramMgr.end(); ++it) { - if ((it->second != _pcSysParamMngr) && (it->second != _pcUserParamMngr)) { - if (it->second->HasSerializer()) { - Base::Console().Log("Saving %s...\n", it->first.c_str()); - it->second->SaveDocument(); - Base::Console().Log("Saving %s...done\n", it->first.c_str()); + for (auto it : paramMgr) { + if ((it.second != _pcSysParamMngr) && (it.second != _pcUserParamMngr)) { + if (it.second->HasSerializer()) { + Base::Console().Log("Saving %s...\n", it.first.c_str()); + it.second->SaveDocument(); + Base::Console().Log("Saving %s...done\n", it.first.c_str()); } } } @@ -2362,29 +2364,29 @@ void processProgramOptions(const variables_map& vm, std::map Mods = vm["module-path"].as< vector >(); string temp; - for (vector::const_iterator It = Mods.begin(); It != Mods.end(); ++It) - temp += *It + ";"; + for (const auto & It : Mods) + temp += It + ";"; temp.erase(temp.end()-1); mConfig["AdditionalModulePaths"] = temp; } if (vm.count("python-path")) { vector Paths = vm["python-path"].as< vector >(); - for (vector::const_iterator It = Paths.begin(); It != Paths.end(); ++It) - Base::Interpreter().addPythonPath(It->c_str()); + for (const auto & It : Paths) + Base::Interpreter().addPythonPath(It.c_str()); } if (vm.count("input-file")) { vector files(vm["input-file"].as< vector >()); int OpenFileCount=0; - for (vector::const_iterator It = files.begin(); It != files.end(); ++It) { + for (const auto & It : files) { //cout << "Input files are: " // << vm["input-file"].as< vector >() << "\n"; std::ostringstream temp; temp << "OpenFile" << OpenFileCount; - mConfig[temp.str()] = *It; + mConfig[temp.str()] = It; OpenFileCount++; } std::ostringstream buffer; @@ -2440,8 +2442,8 @@ void processProgramOptions(const variables_map& vm, std::map::iterator it=mConfig.begin(); it != mConfig.end(); ++it) { - str << it->first << "=" << it->second << std::endl; + for (const auto & it : mConfig) { + str << it.first << "=" << it.second << std::endl; } throw Base::ProgramInformation(str.str()); } @@ -2746,8 +2748,8 @@ std::list Application::processFiles(const std::list& f { std::list processed; Base::Console().Log("Init: Processing command line files\n"); - for (std::list::const_iterator it = files.begin(); it != files.end(); ++it) { - Base::FileInfo file(*it); + for (const auto & it : files) { + Base::FileInfo file(it); Base::Console().Log("Init: Processing file: %s\n",file.filePath().c_str()); @@ -2755,22 +2757,22 @@ std::list Application::processFiles(const std::list& f if (file.hasExtension("fcstd") || file.hasExtension("std")) { // try to open Application::_pcSingleton->openDocument(file.filePath().c_str()); - processed.push_back(*it); + processed.push_back(it); } else if (file.hasExtension("fcscript") || file.hasExtension("fcmacro")) { Base::Interpreter().runFile(file.filePath().c_str(), true); - processed.push_back(*it); + processed.push_back(it); } else if (file.hasExtension("py")) { try { Base::Interpreter().addPythonPath(file.dirPath().c_str()); Base::Interpreter().loadModule(file.fileNamePure().c_str()); - processed.push_back(*it); + processed.push_back(it); } catch (const Base::PyException&) { // if loading the module does not work, try just running the script (run in __main__) Base::Interpreter().runFile(file.filePath().c_str(),true); - processed.push_back(*it); + processed.push_back(it); } } else { @@ -2784,7 +2786,7 @@ std::list Application::processFiles(const std::list& f Base::Interpreter().runStringArg("import %s",mods.front().c_str()); Base::Interpreter().runStringArg("%s.open(u\"%s\")",mods.front().c_str(), escapedstr.c_str()); - processed.push_back(*it); + processed.push_back(it); Base::Console().Log("Command line open: %s.open(u\"%s\")\n",mods.front().c_str(),escapedstr.c_str()); } else if (file.exists()) { @@ -2884,9 +2886,9 @@ void Application::logStatus() boost::posix_time::second_clock::local_time()); Base::Console().Log("Time = %s\n", time_str.c_str()); - for (std::map::iterator It = mConfig.begin(); It != mConfig.end(); - ++It) - Base::Console().Log("%s = %s\n", It->first.c_str(), It->second.c_str()); + for (const auto & It : mConfig) { + Base::Console().Log("%s = %s\n", It.first.c_str(), It.second.c_str()); + } } void Application::LoadParameters() diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 77b1f981f0..46bb8d1016 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -435,8 +435,8 @@ PyObject* Application::sDumpConfig(PyObject * /*self*/, PyObject *args) return nullptr; PyObject *dict = PyDict_New(); - for (auto It= GetApplication()._mConfig.begin(); It != GetApplication()._mConfig.end(); ++It) { - PyDict_SetItemString(dict,It->first.c_str(), PyUnicode_FromString(It->second.c_str())); + for (const auto & It : GetApplication()._mConfig) { + PyDict_SetItemString(dict, It.first.c_str(), PyUnicode_FromString(It.second.c_str())); } return dict; } @@ -526,8 +526,8 @@ PyObject* Application::sGetImportType(PyObject * /*self*/, PyObject *args) if (psKey) { Py::List list; std::vector modules = GetApplication().getImportModules(psKey); - for (std::vector::iterator it = modules.begin(); it != modules.end(); ++it) { - list.append(Py::String(*it)); + for (const auto & it : modules) { + list.append(Py::String(it)); } return Py::new_reference_to(list); @@ -535,20 +535,20 @@ PyObject* Application::sGetImportType(PyObject * /*self*/, PyObject *args) else { Py::Dict dict; std::vector types = GetApplication().getImportTypes(); - for (std::vector::iterator it = types.begin(); it != types.end(); ++it) { - std::vector modules = GetApplication().getImportModules(it->c_str()); + for (const auto & it : types) { + std::vector modules = GetApplication().getImportModules(it.c_str()); if (modules.empty()) { - dict.setItem(it->c_str(), Py::None()); + dict.setItem(it.c_str(), Py::None()); } else if (modules.size() == 1) { - dict.setItem(it->c_str(), Py::String(modules.front())); + dict.setItem(it.c_str(), Py::String(modules.front())); } else { Py::List list; - for (std::vector::iterator jt = modules.begin(); jt != modules.end(); ++jt) { - list.append(Py::String(*jt)); + for (const auto & jt : modules) { + list.append(Py::String(jt)); } - dict.setItem(it->c_str(), list); + dict.setItem(it.c_str(), list); } } @@ -590,8 +590,8 @@ PyObject* Application::sGetExportType(PyObject * /*self*/, PyObject *args) if (psKey) { Py::List list; std::vector modules = GetApplication().getExportModules(psKey); - for (std::vector::iterator it = modules.begin(); it != modules.end(); ++it) { - list.append(Py::String(*it)); + for (const auto & it : modules) { + list.append(Py::String(it)); } return Py::new_reference_to(list); @@ -599,20 +599,20 @@ PyObject* Application::sGetExportType(PyObject * /*self*/, PyObject *args) else { Py::Dict dict; std::vector types = GetApplication().getExportTypes(); - for (std::vector::iterator it = types.begin(); it != types.end(); ++it) { - std::vector modules = GetApplication().getExportModules(it->c_str()); + for (const auto & it : types) { + std::vector modules = GetApplication().getExportModules(it.c_str()); if (modules.empty()) { - dict.setItem(it->c_str(), Py::None()); + dict.setItem(it.c_str(), Py::None()); } else if (modules.size() == 1) { - dict.setItem(it->c_str(), Py::String(modules.front())); + dict.setItem(it.c_str(), Py::String(modules.front())); } else { Py::List list; - for (std::vector::iterator jt = modules.begin(); jt != modules.end(); ++jt) { - list.append(Py::String(*jt)); + for (const auto & jt : modules) { + list.append(Py::String(jt)); } - dict.setItem(it->c_str(), list); + dict.setItem(it.c_str(), list); } } diff --git a/src/App/ComplexGeoDataPyImp.cpp b/src/App/ComplexGeoDataPyImp.cpp index b7dd72f234..4b80e0f1e6 100644 --- a/src/App/ComplexGeoDataPyImp.cpp +++ b/src/App/ComplexGeoDataPyImp.cpp @@ -96,17 +96,15 @@ PyObject* ComplexGeoDataPy::getFacesFromSubElement(PyObject *args) Py::Tuple tuple(2); Py::List vertex; - for (std::vector::const_iterator it = points.begin(); - it != points.end(); ++it) - vertex.append(Py::asObject(new Base::VectorPy(*it))); + for (const auto & it : points) + vertex.append(Py::asObject(new Base::VectorPy(it))); tuple.setItem(0, vertex); Py::List facet; - for (std::vector::const_iterator - it = facets.begin(); it != facets.end(); ++it) { + for (const auto & it : facets) { Py::Tuple f(3); - f.setItem(0,Py::Int(int(it->I1))); - f.setItem(1,Py::Int(int(it->I2))); - f.setItem(2,Py::Int(int(it->I3))); + f.setItem(0,Py::Int(int(it.I1))); + f.setItem(1,Py::Int(int(it.I2))); + f.setItem(2,Py::Int(int(it.I3))); facet.append(f); } tuple.setItem(1, facet); @@ -133,16 +131,14 @@ PyObject* ComplexGeoDataPy::getLinesFromSubElement(PyObject *args) Py::Tuple tuple(2); Py::List vertex; - for (std::vector::const_iterator it = points.begin(); - it != points.end(); ++it) - vertex.append(Py::asObject(new Base::VectorPy(*it))); + for (const auto & it : points) + vertex.append(Py::asObject(new Base::VectorPy(it))); tuple.setItem(0, vertex); Py::List line; - for (std::vector::const_iterator - it = lines.begin(); it != lines.end(); ++it) { + for (const auto & it : lines) { Py::Tuple l(2); - l.setItem(0,Py::Int((int)it->I1)); - l.setItem(1,Py::Int((int)it->I2)); + l.setItem(0,Py::Int((int)it.I1)); + l.setItem(1,Py::Int((int)it.I2)); line.append(l); } tuple.setItem(1, line); @@ -167,16 +163,14 @@ PyObject* ComplexGeoDataPy::getPoints(PyObject *args) Py::Tuple tuple(2); Py::List vertex; - for (std::vector::const_iterator it = points.begin(); - it != points.end(); ++it) { - vertex.append(Py::asObject(new Base::VectorPy(*it))); + for (const auto & it : points) { + vertex.append(Py::asObject(new Base::VectorPy(it))); } tuple.setItem(0, vertex); Py::List normal; - for (std::vector::const_iterator it = normals.begin(); - it != normals.end(); ++it) { - normal.append(Py::asObject(new Base::VectorPy(*it))); + for (const auto & it : normals) { + normal.append(Py::asObject(new Base::VectorPy(it))); } tuple.setItem(1, normal); return Py::new_reference_to(tuple); @@ -200,16 +194,14 @@ PyObject* ComplexGeoDataPy::getLines(PyObject *args) Py::Tuple tuple(2); Py::List vertex; - for (std::vector::const_iterator it = points.begin(); - it != points.end(); ++it) - vertex.append(Py::asObject(new Base::VectorPy(*it))); + for (const auto & it : points) + vertex.append(Py::asObject(new Base::VectorPy(it))); tuple.setItem(0, vertex); Py::List line; - for (std::vector::const_iterator - it = lines.begin(); it != lines.end(); ++it) { + for (const auto & it : lines) { Py::Tuple l(2); - l.setItem(0,Py::Int((int)it->I1)); - l.setItem(1,Py::Int((int)it->I2)); + l.setItem(0,Py::Int((int)it.I1)); + l.setItem(1,Py::Int((int)it.I2)); line.append(l); } tuple.setItem(1, line); @@ -234,17 +226,15 @@ PyObject* ComplexGeoDataPy::getFaces(PyObject *args) Py::Tuple tuple(2); Py::List vertex; - for (std::vector::const_iterator it = points.begin(); - it != points.end(); ++it) - vertex.append(Py::asObject(new Base::VectorPy(*it))); + for (const auto & it : points) + vertex.append(Py::asObject(new Base::VectorPy(it))); tuple.setItem(0, vertex); Py::List facet; - for (std::vector::const_iterator - it = facets.begin(); it != facets.end(); ++it) { + for (const auto & it : facets) { Py::Tuple f(3); - f.setItem(0,Py::Int((int)it->I1)); - f.setItem(1,Py::Int((int)it->I2)); - f.setItem(2,Py::Int((int)it->I3)); + f.setItem(0,Py::Int((int)it.I1)); + f.setItem(1,Py::Int((int)it.I2)); + f.setItem(2,Py::Int((int)it.I3)); facet.append(f); } tuple.setItem(1, facet); diff --git a/src/App/Document.cpp b/src/App/Document.cpp index ae41d3638d..a35191c045 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -560,7 +560,7 @@ int Document::getTransactionID(bool undo, unsigned pos) const { if(pos>=mRedoTransactions.size()) return 0; auto rit = mRedoTransactions.rbegin(); - for(;pos;++rit,--pos); + for(;pos;++rit,--pos){} return (*rit)->getID(); } @@ -1598,8 +1598,8 @@ private: Base::FileInfo di(fi.dirPath()); std::vector backup; std::vector files = di.getDirectoryContent(); - for (std::vector::iterator it = files.begin(); it != files.end(); ++it) { - std::string file = it->fileName(); + for (const Base::FileInfo& it : files) { + std::string file = it.fileName(); if (file.substr(0,fn.length()) == fn) { // starts with the same file name std::string suf(file.substr(fn.length())); @@ -1607,7 +1607,7 @@ private: std::string::size_type nPos = suf.find_first_not_of("0123456789"); if (nPos==std::string::npos) { // store all backup files - backup.push_back(*it); + backup.push_back(it); nSuff = std::max(nSuff, std::atol(suf.c_str())); } } @@ -1617,9 +1617,9 @@ private: if (!backup.empty() && (int)backup.size() >= numberOfFiles) { // delete the oldest backup file we found Base::FileInfo del = backup.front(); - for (std::vector::iterator it = backup.begin(); it != backup.end(); ++it) { - if (it->lastModified() < del.lastModified()) - del = *it; + for (const Base::FileInfo& it : backup) { + if (it.lastModified() < del.lastModified()) + del = it; } del.deleteFile(); @@ -1673,10 +1673,10 @@ private: Base::FileInfo di(fi.dirPath()); std::vector backup; std::vector files = di.getDirectoryContent(); - for (std::vector::iterator it = files.begin(); it != files.end(); ++it) { - if (it->isFile()) { - std::string file = it->fileName(); - std::string fext = it->extension(); + for (const Base::FileInfo& it : files) { + if (it.isFile()) { + std::string file = it.fileName(); + std::string fext = it.extension(); std::string fextUp = fext; std::transform(fextUp.begin(), fextUp.end(), fextUp.begin(),(int (*)(int))toupper); // re-enforcing identification of the backup file @@ -1690,7 +1690,7 @@ private: // + complement with no "." + ".FCBak" ((fextUp == "FCBAK") && startsWith(file, pbn) && (checkValidComplement(file, pbn, fext)))) { - backup.push_back(*it); + backup.push_back(it); } } } @@ -1700,18 +1700,18 @@ private: // delete the oldest backup file we found // Base::FileInfo del = backup.front(); int nb = 0; - for (std::vector::iterator it = backup.begin(); it != backup.end(); ++it) { + for (Base::FileInfo& it : backup) { nb++; if (nb >= numberOfFiles) { try { - if (!it->deleteFile()) { + if (!it.deleteFile()) { backupManagementError = true; - Base::Console().Warning("Cannot remove backup file : %s\n", it->fileName().c_str()); + Base::Console().Warning("Cannot remove backup file : %s\n", it.fileName().c_str()); } } catch (...) { backupManagementError = true; - Base::Console().Warning("Cannot remove backup file : %s\n", it->fileName().c_str()); + Base::Console().Warning("Cannot remove backup file : %s\n", it.fileName().c_str()); } } } @@ -2192,15 +2192,17 @@ const char* Document::getFileName() const /// Remove all modifications. After this call The document becomes valid again. void Document::purgeTouched() { - for (std::vector::iterator It = d->objectArray.begin();It != d->objectArray.end();++It) - (*It)->purgeTouched(); + for (auto It : d->objectArray) + It->purgeTouched(); } bool Document::isTouched() const { - for (std::vector::const_iterator It = d->objectArray.begin();It != d->objectArray.end();++It) - if ((*It)->isTouched()) + for (auto It : d->objectArray) { + if (It->isTouched()) { return true; + } + } return false; } @@ -2208,9 +2210,11 @@ vector Document::getTouched() const { vector result; - for (std::vector::const_iterator It = d->objectArray.begin();It != d->objectArray.end();++It) - if ((*It)->isTouched()) - result.push_back(*It); + for (auto It : d->objectArray) { + if (It->isTouched()) { + result.push_back(It); + } + } return result; } @@ -2304,13 +2308,14 @@ std::vector Document::getInList(const DocumentObject* me) // result list std::vector result; // go through all objects - for (auto It = d->objectMap.begin(); It != d->objectMap.end();++It) { + for (const auto & It : d->objectMap) { // get the outList and search if me is in that list - std::vector OutList = It->second->getOutList(); - for (std::vector::const_iterator It2=OutList.begin();It2!=OutList.end();++It2) - if (*It2 && *It2 == me) + std::vector OutList = It.second->getOutList(); + for (auto obj : OutList) { + if (obj && obj == me) // add the parent object - result.push_back(It->second); + result.push_back(It.second); + } } return result; } @@ -2536,7 +2541,9 @@ void Document::_rebuildDependencyList(const std::vector &o * @param paths Map with current and new names */ -void Document::renameObjectIdentifiers(const std::map &paths, const std::function & selector) +void Document::renameObjectIdentifiers(const std::map &paths, + const std::function & selector) { std::map extendedPaths; @@ -2546,9 +2553,11 @@ void Document::renameObjectIdentifiers(const std::map::iterator it = d->objectArray.begin(); it != d->objectArray.end(); ++it) - if (selector(*it)) - (*it)->renameObjectIdentifiers(extendedPaths); + for (auto it : d->objectArray) { + if (selector(it)) { + it->renameObjectIdentifiers(extendedPaths); + } + } } #ifdef USE_OLD_DAG @@ -3213,8 +3222,8 @@ std::vector Document::addObjects(const char* sType, const std: // get all existing object names std::vector reservedNames; reservedNames.reserve(d->objectMap.size()); - for (auto pos = d->objectMap.begin();pos != d->objectMap.end();++pos) { - reservedNames.push_back(pos->first); + for (const auto & pos : d->objectMap) { + reservedNames.push_back(pos.first); } for (auto it = objects.begin(); it != objects.end(); ++it) { @@ -3576,8 +3585,8 @@ std::vector Document::copyObject( md.setVerbose(recursive); unsigned int memsize=1000; // ~ for the meta-information - for (std::vector::iterator it = deps.begin(); it != deps.end(); ++it) - memsize += (*it)->getMemSize(); + for (auto it : deps) + memsize += it->getMemSize(); // if less than ~10 MB bool use_buffer=(memsize < 0xA00000); @@ -3769,8 +3778,8 @@ DocumentObject * Document::getObjectByID(long id) const // Note: This method is only used in Tree.cpp slotChangeObject(), see explanation there bool Document::isIn(const DocumentObject *pFeat) const { - for (auto o = d->objectMap.begin(); o != d->objectMap.end(); ++o) { - if (o->second == pFeat) + for (const auto & pos : d->objectMap) { + if (pos.second == pFeat) return true; } @@ -3779,9 +3788,9 @@ bool Document::isIn(const DocumentObject *pFeat) const const char * Document::getObjectName(DocumentObject *pFeat) const { - for (auto pos = d->objectMap.begin();pos != d->objectMap.end();++pos) { - if (pos->second == pFeat) - return pos->first.c_str(); + for (const auto & pos : d->objectMap) { + if (pos.second == pFeat) + return pos.first.c_str(); } return nullptr; @@ -3825,8 +3834,8 @@ std::string Document::getStandardObjectName(const char *Name, int d) const std::vector labels; labels.reserve(mm.size()); - for (std::vector::const_iterator it = mm.begin(); it != mm.end(); ++it) { - std::string label = (*it)->Label.getValue(); + for (auto it : mm) { + std::string label = it->Label.getValue(); labels.push_back(label); } return Base::Tools::getUniqueName(Name, labels, d); @@ -3846,9 +3855,9 @@ const std::vector &Document::getObjects() const std::vector Document::getObjectsOfType(const Base::Type& typeId) const { std::vector Objects; - for (std::vector::const_iterator it = d->objectArray.begin(); it != d->objectArray.end(); ++it) { - if ((*it)->getTypeId().isDerivedFrom(typeId)) - Objects.push_back(*it); + for (auto it : d->objectArray) { + if (it->getTypeId().isDerivedFrom(typeId)) + Objects.push_back(it); } return Objects; } @@ -3856,9 +3865,9 @@ std::vector Document::getObjectsOfType(const Base::Type& typeId std::vector< DocumentObject* > Document::getObjectsWithExtension(const Base::Type& typeId, bool derived) const { std::vector Objects; - for (std::vector::const_iterator it = d->objectArray.begin(); it != d->objectArray.end(); ++it) { - if ((*it)->hasExtension(typeId, derived)) - Objects.push_back(*it); + for (auto it : d->objectArray) { + if (it->hasExtension(typeId, derived)) + Objects.push_back(it); } return Objects; } @@ -3877,14 +3886,14 @@ std::vector Document::findObjects(const Base::Type& typeId, con std::vector Objects; DocumentObject* found = nullptr; - for (std::vector::const_iterator it = d->objectArray.begin(); it != d->objectArray.end(); ++it) { - if ((*it)->getTypeId().isDerivedFrom(typeId)) { - found = *it; + for (auto it : d->objectArray) { + if (it->getTypeId().isDerivedFrom(typeId)) { + found = it; - if (!rx_name.empty() && !boost::regex_search((*it)->getNameInDocument(), what, rx_name)) + if (!rx_name.empty() && !boost::regex_search(it->getNameInDocument(), what, rx_name)) found = nullptr; - if (!rx_label.empty() && !boost::regex_search((*it)->Label.getValue(), what, rx_label)) + if (!rx_label.empty() && !boost::regex_search(it->Label.getValue(), what, rx_label)) found = nullptr; if (found) @@ -3897,8 +3906,8 @@ std::vector Document::findObjects(const Base::Type& typeId, con int Document::countObjectsOfType(const Base::Type& typeId) const { int ct=0; - for (auto it = d->objectMap.begin(); it != d->objectMap.end(); ++it) { - if (it->second->getTypeId().isDerivedFrom(typeId)) + for (const auto & it : d->objectMap) { + if (it.second->getTypeId().isDerivedFrom(typeId)) ct++; } @@ -3971,11 +3980,11 @@ Document::getPathsByOutList(const App::DocumentObject* from, const App::Document std::vector all_paths; DocumentP::findAllPathsAt(all_nodes, index_from, all_paths, tmp); - for (std::vector::iterator it = all_paths.begin(); it != all_paths.end(); ++it) { - Path::iterator jt = std::find(it->begin(), it->end(), index_to); - if (jt != it->end()) { + for (const Path& it : all_paths) { + Path::const_iterator jt = std::find(it.begin(), it.end(), index_to); + if (jt != it.end()) { std::list path; - for (Path::iterator kt = it->begin(); kt != jt; ++kt) { + for (Path::const_iterator kt = it.begin(); kt != jt; ++kt) { path.push_back(d->objectArray[*kt]); } @@ -3999,8 +4008,9 @@ bool Document::mustExecute() const return touched; } - for (std::vector::const_iterator It = d->objectArray.begin();It != d->objectArray.end();++It) - if ((*It)->isTouched() || (*It)->mustExecute()==1) + for (auto It : d->objectArray) { + if (It->isTouched() || It->mustExecute()==1) return true; + } return false; } diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index b561983bfe..98d24c7131 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -114,11 +114,11 @@ PyObject* DocumentObjectPy::supportedProperties(PyObject *args) std::vector ary; Base::Type::getAllDerivedFrom(App::Property::getClassTypeId(), ary); Py::List res; - for (std::vector::iterator it = ary.begin(); it != ary.end(); ++it) { - Base::BaseClass *data = static_cast(it->createInstance()); + for (auto & it : ary) { + Base::BaseClass *data = static_cast(it.createInstance()); if (data) { delete data; - res.append(Py::String(it->getName())); + res.append(Py::String(it.getName())); } } return Py::new_reference_to(res); @@ -253,8 +253,8 @@ Py::List DocumentObjectPy::getInList() const Py::List ret; std::vector list = getDocumentObjectPtr()->getInList(); - for (std::vector::iterator It=list.begin();It!=list.end();++It) - ret.append(Py::Object((*It)->getPyObject(), true)); + for (auto It : list) + ret.append(Py::Object(It->getPyObject(), true)); return ret; } @@ -265,8 +265,8 @@ Py::List DocumentObjectPy::getInListRecursive() const try { std::vector list = getDocumentObjectPtr()->getInListRecursive(); - for (std::vector::iterator It = list.begin(); It != list.end(); ++It) - ret.append(Py::Object((*It)->getPyObject(), true)); + for (auto It : list) + ret.append(Py::Object(It->getPyObject(), true)); } catch (const Base::Exception& e) { throw Py::IndexError(e.what()); @@ -279,8 +279,8 @@ Py::List DocumentObjectPy::getOutList() const Py::List ret; std::vector list = getDocumentObjectPtr()->getOutList(); - for (std::vector::iterator It=list.begin();It!=list.end();++It) - ret.append(Py::Object((*It)->getPyObject(), true)); + for (auto It : list) + ret.append(Py::Object(It->getPyObject(), true)); return ret; } @@ -292,8 +292,8 @@ Py::List DocumentObjectPy::getOutListRecursive() const std::vector list = getDocumentObjectPtr()->getOutListRecursive(); // create the python list for the output - for (std::vector::iterator It = list.begin(); It != list.end(); ++It) - ret.append(Py::Object((*It)->getPyObject(), true)); + for (auto It : list) + ret.append(Py::Object(It->getPyObject(), true)); } catch (const Base::Exception& e) { throw Py::IndexError(e.what()); diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp index 2a06da2ef5..a7f0e4f39d 100644 --- a/src/App/DocumentPyImp.cpp +++ b/src/App/DocumentPyImp.cpp @@ -631,9 +631,9 @@ PyObject* DocumentPy::getObjectsByLabel(PyObject *args) Py::List list; std::string name = sName; std::vector objs = getDocumentPtr()->getObjects(); - for (std::vector::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 ary; Base::Type::getAllDerivedFrom(App::DocumentObject::getClassTypeId(), ary); Py::List res; - for (std::vector::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 objs = getDocumentPtr()->getObjects(); Py::List res; - for (std::vector::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 objs = getDocumentPtr()->topologicalSort(); Py::List res; - for (std::vector::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 objs = getDocumentPtr()->getRootObjects(); Py::List res; - for (std::vector::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 vList = getDocumentPtr()->getAvailableUndoNames(); Py::List res; - for (std::vector::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 vList = getDocumentPtr()->getAvailableRedoNames(); Py::List res; - for (std::vector::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; } diff --git a/src/App/Enumeration.cpp b/src/App/Enumeration.cpp index 1d85767232..69d3027495 100644 --- a/src/App/Enumeration.cpp +++ b/src/App/Enumeration.cpp @@ -141,8 +141,8 @@ void Enumeration::setEnums(const std::vector &values) } enumArray.clear(); - for (std::vector::const_iterator it = values.begin(); it != values.end(); ++it) { - enumArray.push_back(std::make_shared(it->c_str())); + for (const auto & it : values) { + enumArray.push_back(std::make_shared(it.c_str())); } // set _index diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index db68d9e702..4b6b258224 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -2545,8 +2545,8 @@ Expression *FunctionExpression::simplify() const std::vector a; // Try to simplify each argument to function - for (auto it = args.begin(); it != args.end(); ++it) { - Expression * v = (*it)->simplify(); + for (auto it : args) { + Expression * v = it->simplify(); if (freecad_dynamic_cast(v)) ++numerics; @@ -2557,8 +2557,8 @@ Expression *FunctionExpression::simplify() const // All constants, then evaluation must also be constant // Clean-up - for (auto it = args.begin(); it != args.end(); ++it) - delete *it; + for (auto it : args) + delete it; return eval(); } diff --git a/src/App/Graphviz.cpp b/src/App/Graphviz.cpp index 54adb66928..d98ae95c28 100644 --- a/src/App/Graphviz.cpp +++ b/src/App/Graphviz.cpp @@ -399,18 +399,18 @@ void Document::exportGraphviz(std::ostream& out) const } // Internal document objects - for (auto It = d->objectMap.begin(); It != d->objectMap.end();++It) - addExpressionSubgraphIfNeeded(It->second, CSSubgraphs); + for (auto It : d->objectMap) + addExpressionSubgraphIfNeeded(It.second, CSSubgraphs); // Add external document objects - for (auto It = d->objectMap.begin(); It != d->objectMap.end();++It) { - std::vector OutList = It->second->getOutList(); - for (std::vector::const_iterator It2=OutList.begin();It2!=OutList.end();++It2) { - if (*It2) { - std::map::const_iterator item = GlobalVertexList.find(getId(*It2)); + for (auto it : d->objectMap) { + std::vector OutList = it.second->getOutList(); + for (auto obj : OutList) { + if (obj) { + std::map::const_iterator item = GlobalVertexList.find(getId(obj)); if (item == GlobalVertexList.end()) - addExpressionSubgraphIfNeeded(*It2, CSSubgraphs); + addExpressionSubgraphIfNeeded(obj, CSSubgraphs); } } } @@ -424,20 +424,20 @@ void Document::exportGraphviz(std::ostream& out) const bool CSSubgraphs = depGrp->GetBool("GeoFeatureSubgraphs", true); // Add internal document objects - for (auto It = d->objectMap.begin(); It != d->objectMap.end();++It) - add(It->second, It->second->getNameInDocument(), It->second->Label.getValue(), CSSubgraphs); + for (auto It : d->objectMap) + add(It.second, It.second->getNameInDocument(), It.second->Label.getValue(), CSSubgraphs); // Add external document objects - for (auto It = d->objectMap.begin(); It != d->objectMap.end();++It) { - std::vector OutList = It->second->getOutList(); - for (std::vector::const_iterator It2=OutList.begin();It2!=OutList.end();++It2) { - if (*It2) { - std::map::const_iterator item = GlobalVertexList.find(getId(*It2)); + for (auto It : d->objectMap) { + std::vector OutList = It.second->getOutList(); + for (auto obj : OutList) { + if (obj) { + std::map::const_iterator item = GlobalVertexList.find(getId(obj)); if (item == GlobalVertexList.end()) - add(*It2, - std::string((*It2)->getDocument()->getName()) + "#" + (*It2)->getNameInDocument(), - std::string((*It2)->getDocument()->getName()) + "#" + (*It2)->Label.getValue(), + add(obj, + std::string(obj->getDocument()->getName()) + "#" + obj->getNameInDocument(), + std::string(obj->getDocument()->getName()) + "#" + obj->Label.getValue(), CSSubgraphs); } } @@ -484,60 +484,58 @@ void Document::exportGraphviz(std::ostream& out) const bool omitGeoFeatureGroups = depGrp->GetBool("GeoFeatureSubgraphs", true); // Add edges between document objects - for (auto It = d->objectMap.begin(); It != d->objectMap.end();++It) { + for (auto It : d->objectMap) { if(omitGeoFeatureGroups) { //coordinate systems are represented by subgraphs - if(It->second->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId())) + if(It.second->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId())) continue; //as well as origins - if(It->second->isDerivedFrom(Origin::getClassTypeId())) + if(It.second->isDerivedFrom(Origin::getClassTypeId())) continue; } std::map dups; - std::vector OutList = It->second->getOutList(); - const DocumentObject * docObj = It->second; + std::vector OutList = It.second->getOutList(); + const DocumentObject * docObj = It.second; - for (std::vector::const_iterator It2=OutList.begin();It2!=OutList.end();++It2) { - if (*It2) { + for (auto obj : OutList) { + if (obj) { // Count duplicate edges - bool inserted = edge(GlobalVertexList[getId(docObj)], GlobalVertexList[getId(*It2)], DepList).second; + bool inserted = edge(GlobalVertexList[getId(docObj)], GlobalVertexList[getId(obj)], DepList).second; if (inserted) { - dups[*It2]++; + dups[obj]++; continue; } // Skip edge if an expression edge already exists - if (existingEdges.find(std::make_pair(docObj, *It2)) != existingEdges.end()) + if (existingEdges.find(std::make_pair(docObj, obj)) != existingEdges.end()) continue; // Add edge Edge edge; - tie(edge, inserted) = add_edge(GlobalVertexList[getId(docObj)], GlobalVertexList[getId(*It2)], DepList); + tie(edge, inserted) = add_edge(GlobalVertexList[getId(docObj)], GlobalVertexList[getId(obj)], DepList); // Set properties to make arrows go between subgraphs if needed if (GraphList[docObj]) edgeAttrMap[edge]["ltail"] = getClusterName(docObj); - if (GraphList[*It2]) - edgeAttrMap[edge]["lhead"] = getClusterName(*It2); + if (GraphList[obj]) + edgeAttrMap[edge]["lhead"] = getClusterName(obj); } } // Set labels for duplicate edges - for (std::map::const_iterator It2 = dups.begin(); It2 != dups.end(); ++It2) { - Edge e(edge(GlobalVertexList[getId(It->second)], GlobalVertexList[getId(It2->first)], DepList).first); + for (const auto & dup : dups) { + Edge e(edge(GlobalVertexList[getId(It.second)], GlobalVertexList[getId(dup.first)], DepList).first); std::stringstream s; - s << " " << (It2->second + 1) << "x"; + s << " " << (dup.second + 1) << "x"; edgeAttrMap[e]["label"] = s.str(); } - } - } using EdgeMap = std::unordered_multimap; @@ -632,8 +630,8 @@ void Document::exportGraphviz(std::ostream& out) const // Update colors in graph const boost::property_map::type& edgeAttrMap = boost::get(boost::edge_attribute, DepList); - for (auto ei = out_edges.begin(), ei_end = out_edges.end(); ei != ei_end; ++ei) - edgeAttrMap[ei->second]["color"] = "red"; + for (auto ei : out_edges) + edgeAttrMap[ei.second]["color"] = "red"; } #if defined(__clang__) diff --git a/src/App/GroupExtension.cpp b/src/App/GroupExtension.cpp index 87e827cae2..47369a1ff6 100644 --- a/src/App/GroupExtension.cpp +++ b/src/App/GroupExtension.cpp @@ -268,9 +268,9 @@ std::vector GroupExtension::getObjectsOfType(const Base::Type& { std::vector type; const std::vector& grp = Group.getValues(); - for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { - if ( (*it)->getTypeId().isDerivedFrom(typeId)) - type.push_back(*it); + for (auto it : grp) { + if (it->getTypeId().isDerivedFrom(typeId)) + type.push_back(it); } return type; @@ -280,8 +280,8 @@ int GroupExtension::countObjectsOfType(const Base::Type& typeId) const { int type=0; const std::vector& grp = Group.getValues(); - for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { - if ( (*it)->getTypeId().isDerivedFrom(typeId)) + for (auto it : grp) { + if ( it->getTypeId().isDerivedFrom(typeId)) type++; } diff --git a/src/App/Link.cpp b/src/App/Link.cpp index d2859600d0..183cbb5ecf 100644 --- a/src/App/Link.cpp +++ b/src/App/Link.cpp @@ -1615,8 +1615,8 @@ void LinkBaseExtension::update(App::DocumentObject *parent, const Property *prop placements.reserve(objs.size()); std::vector scales; scales.reserve(objs.size()); - for(size_t i=0;i(objs[i]); + for(auto obj : objs) { + auto element = freecad_dynamic_cast(obj); if(element) { placements.push_back(element->Placement.getValue()); scales.push_back(element->getScaleVector()); @@ -1887,8 +1887,8 @@ void LinkBaseExtension::syncElementList() { auto owner = getContainer(); auto ownerID = owner?owner->getID():0; auto elements = getElementListValue(); - for (size_t i = 0; i < elements.size(); ++i) { - auto element = freecad_dynamic_cast(elements[i]); + for (auto i : elements) { + auto element = freecad_dynamic_cast(i); if (!element || (element->_LinkOwner.getValue() && element->_LinkOwner.getValue() != ownerID)) diff --git a/src/App/LinkBaseExtensionPyImp.cpp b/src/App/LinkBaseExtensionPyImp.cpp index 77098254e6..10819f2901 100644 --- a/src/App/LinkBaseExtensionPyImp.cpp +++ b/src/App/LinkBaseExtensionPyImp.cpp @@ -185,10 +185,10 @@ PyObject* LinkBaseExtensionPy::getLinkPropertyInfo(PyObject *args) char *name; if(PyArg_ParseTuple(args,"s",&name)) { - for(int i=0;i<(int)infos.size();++i) { - if(strcmp(infos[i].name,name)==0) { - Py::TupleN ret(Py::String(infos[i].type.getName()), - Py::String(infos[i].doc)); + for(const auto & info : infos) { + if(strcmp(info.name,name)==0) { + Py::TupleN ret(Py::String(info.type.getName()), + Py::String(info.doc)); return Py::new_reference_to(ret); } } diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index 22b9c03191..baf52d40b8 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -852,14 +852,14 @@ App::DocumentObject * ObjectIdentifier::getDocumentObject(const App::Document * } std::vector docObjects = doc->getObjects(); - for (std::vector::iterator j = docObjects.begin(); j != docObjects.end(); ++j) { - if (strcmp((*j)->Label.getValue(), static_cast(name)) == 0) { + for (auto docObject : docObjects) { + if (strcmp(docObject->Label.getValue(), static_cast(name)) == 0) { // Found object with matching label if (objectByLabel) { FC_WARN("duplicate object label " << doc->getName() << '#' << static_cast(name)); return nullptr; } - objectByLabel = *j; + objectByLabel = docObject; } } @@ -1030,14 +1030,14 @@ Document * ObjectIdentifier::getDocument(String name, bool *ambiguous) const App::Document * docByLabel = nullptr; const std::vector docs = App::GetApplication().getDocuments(); - for (std::vector::const_iterator i = docs.begin(); i != docs.end(); ++i) { - if ((*i)->Label.getValue() == name.getString()) { + for (auto doc : docs) { + if (doc->Label.getValue() == name.getString()) { /* Multiple hits for same label? */ if (docByLabel) { if(ambiguous) *ambiguous = true; return nullptr; } - docByLabel = *i; + docByLabel = doc; } } diff --git a/src/App/PropertyContainer.cpp b/src/App/PropertyContainer.cpp index 09e9120c69..719c124699 100644 --- a/src/App/PropertyContainer.cpp +++ b/src/App/PropertyContainer.cpp @@ -101,8 +101,8 @@ void PropertyContainer::setPropertyStatus(unsigned char bit,bool value) { std::vector List; getPropertyList(List); - for(std::vector::const_iterator it=List.begin();it!=List.end();++it) - (**it).StatusBits.set(bit,value); + for(auto it : List) + it->StatusBits.set(bit,value); } short PropertyContainer::getPropertyType(const Property* prop) const @@ -257,21 +257,21 @@ void PropertyContainer::Save (Base::Writer &writer) const writer.decInd(); // Now store normal properties - for (auto it = Map.begin(); it != Map.end(); ++it) + for (const auto& it : Map) { writer.incInd(); // indentation for 'Property name' - writer.Stream() << writer.ind() << "first << "\" type=\"" - << it->second->getTypeId().getName(); + writer.Stream() << writer.ind() << "getTypeId().getName(); - dynamicProps.save(it->second,writer); + dynamicProps.save(it.second,writer); - auto status = it->second->getStatus(); + auto status = it.second->getStatus(); if(status) writer.Stream() << "\" status=\"" << status; writer.Stream() << "\">"; - if(it->second->testStatus(Property::Transient) - || it->second->getType() & Prop_Transient) + if(it.second->testStatus(Property::Transient) + || it.second->getType() & Prop_Transient) { writer.decInd(); writer.Stream() << "" << std::endl; @@ -286,7 +286,7 @@ void PropertyContainer::Save (Base::Writer &writer) const // We must make sure to handle all exceptions accordingly so that // the project file doesn't get invalidated. In the error case this // means to proceed instead of aborting the write operation. - it->second->Save(writer); + it.second->Save(writer); } catch (const Base::Exception &e) { Base::Console().Error("%s\n", e.what()); diff --git a/src/App/PropertyContainerPyImp.cpp b/src/App/PropertyContainerPyImp.cpp index bf22e85127..8b00033874 100644 --- a/src/App/PropertyContainerPyImp.cpp +++ b/src/App/PropertyContainerPyImp.cpp @@ -442,8 +442,8 @@ PyObject* PropertyContainerPy::getEnumerationsOfProperty(PyObject *args) std::vector enumerations = enumProp->getEnumVector(); Py::List ret; - for (std::vector::const_iterator it = enumerations.begin(); it != enumerations.end(); ++it) { - ret.append(Py::String(*it)); + for (const auto & it : enumerations) { + ret.append(Py::String(it)); } return Py::new_reference_to(ret); } @@ -583,8 +583,8 @@ PyObject *PropertyContainerPy::getCustomAttributes(const char* attr) const getPropertyContainerPtr()->getPropertyMap(Map); Py::Dict dict; - for (std::map::iterator it = Map.begin(); it != Map.end(); ++it) { - dict.setItem(it->first, Py::String("")); + for (const auto & it : Map) { + dict.setItem(it.first, Py::String("")); } return Py::new_reference_to(dict); } diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index 8844d00a6d..94fe9137d4 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -115,11 +115,11 @@ Property *PropertyExpressionEngine::Copy() const { PropertyExpressionEngine * engine = new PropertyExpressionEngine(); - for (ExpressionMap::const_iterator it = expressions.begin(); it != expressions.end(); ++it) { + for (const auto & it : expressions) { ExpressionInfo info; - if (it->second.expression) - info.expression = std::shared_ptr(it->second.expression->copy()); - engine->expressions[it->first] = info; + if (it.second.expression) + info.expression = std::shared_ptr(it.second.expression->copy()); + engine->expressions[it.first] = info; } engine->validator = validator; @@ -274,15 +274,15 @@ void PropertyExpressionEngine::Save(Base::Writer &writer) const writer.incInd(); PropertyExpressionContainer::Save(writer); } - for (ExpressionMap::const_iterator it = expressions.begin(); it != expressions.end(); ++it) { + for (const auto & it : expressions) { std::string expression, comment; - if (it->second.expression) { - expression = it->second.expression->toString(true); - comment = it->second.expression->comment; + if (it.second.expression) { + expression = it.second.expression->toString(true); + comment = it.second.expression->comment; } writer.Stream() << writer.ind() << "first.toString()) <<"\" expression=\"" + << Property::encodeAttribute(it.first.toString()) <<"\" expression=\"" << Property::encodeAttribute(expression) << "\""; if (!comment.empty()) writer.Stream() << " comment=\"" @@ -535,9 +535,9 @@ void PropertyExpressionEngine::buildGraph(const ExpressionMap & exprs, std::vector edges; // Build data structure for graph - for (ExpressionMap::const_iterator it = exprs.begin(); it != exprs.end(); ++it) { + for (const auto & expr : exprs) { if(option!=ExecuteAll) { - auto prop = it->first.getProperty(); + auto prop = expr.first.getProperty(); if(!prop) throw Base::RuntimeError("Path does not resolve to a property."); bool is_output = prop->testStatus(App::Property::Output)||(prop->getType()&App::Prop_Output); @@ -549,15 +549,15 @@ void PropertyExpressionEngine::buildGraph(const ExpressionMap & exprs, && !prop->testStatus(Property::EvalOnRestore)) continue; } - buildGraphStructures(it->first, it->second.expression, nodes, revNodes, edges); + buildGraphStructures(expr.first, expr.second.expression, nodes, revNodes, edges); } // Create graph g = DiGraph(nodes.size()); // Add edges to graph - for (std::vector::const_iterator i = edges.begin(); i != edges.end(); ++i) - add_edge(i->first, i->second, g); + for (const auto & edge : edges) + add_edge(edge.first, edge.second, g); // Check for cycles bool has_cycle = false; @@ -590,11 +590,11 @@ std::vector PropertyExpressionEngine::computeEvaluationOr std::vector c; topological_sort(g, std::back_inserter(c)); - for (std::vector::iterator i = c.begin(); i != c.end(); ++i) { + for (int i : c) { // we return the evaluation order for our properties, not the dependencies // the topo sort will contain node ids for both our props and their deps - if (revNodes.find(*i) != revNodes.end()) - evaluationOrder.push_back(revNodes[*i]); + if (revNodes.find(i) != revNodes.end()) + evaluationOrder.push_back(revNodes[i]); } return evaluationOrder; @@ -825,8 +825,8 @@ void PropertyExpressionEngine::renameExpressions(const std::map canonicalPaths; /* ensure input map uses canonical paths */ - for (std::map::const_iterator i = paths.begin(); i != paths.end(); ++i) - canonicalPaths[canonicalPath(i->first)] = i->second; + for (const auto & path : paths) + canonicalPaths[canonicalPath(path.first)] = path.second; for (ExpressionMap::const_iterator i = expressions.begin(); i != expressions.end(); ++i) { std::map::const_iterator j = canonicalPaths.find(i->first); @@ -853,19 +853,19 @@ void PropertyExpressionEngine::renameExpressions(const std::map &paths) { - for (ExpressionMap::iterator it = expressions.begin(); it != expressions.end(); ++it) { - RenameObjectIdentifierExpressionVisitor v(*this, paths, it->first); - it->second.expression->visit(v); + for (const auto & it : expressions) { + RenameObjectIdentifierExpressionVisitor v(*this, paths, it.first); + it.second.expression->visit(v); } } PyObject *PropertyExpressionEngine::getPyObject() { Py::List list; - for (ExpressionMap::const_iterator it = expressions.begin(); it != expressions.end(); ++it) { + for (const auto & it : expressions) { Py::Tuple tuple(2); - tuple.setItem(0, Py::String(it->first.toString())); - auto expr = it->second.expression; + tuple.setItem(0, Py::String(it.first.toString())); + auto expr = it.second.expression; tuple.setItem(1, expr ? Py::String(expr->toString()) : Py::None()); list.append(tuple); } diff --git a/src/App/PropertyGeo.cpp b/src/App/PropertyGeo.cpp index 7fb82d88c8..a72364f265 100644 --- a/src/App/PropertyGeo.cpp +++ b/src/App/PropertyGeo.cpp @@ -312,15 +312,15 @@ void PropertyVectorList::SaveDocFile (Base::Writer &writer) const uint32_t uCt = (uint32_t)getSize(); str << uCt; if (!isSinglePrecision()) { - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - str << it->x << it->y << it->z; + for (const auto & it : _lValueList) { + str << it.x << it.y << it.z; } } else { - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - float x = (float)it->x; - float y = (float)it->y; - float z = (float)it->z; + for (const auto & it : _lValueList) { + float x = (float)it.x; + float y = (float)it.y; + float z = (float)it.z; str << x << y << z; } } @@ -333,15 +333,15 @@ void PropertyVectorList::RestoreDocFile(Base::Reader &reader) str >> uCt; std::vector values(uCt); if (!isSinglePrecision()) { - for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { - str >> it->x >> it->y >> it->z; + for (auto & it : values) { + str >> it.x >> it.y >> it.z; } } else { float x,y,z; - for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + for (auto & it : values) { str >> x >> y >> z; - it->Set(x, y, z); + it.Set(x, y, z); } } setValues(values); @@ -912,20 +912,20 @@ void PropertyPlacementList::SaveDocFile (Base::Writer &writer) const uint32_t uCt = (uint32_t)getSize(); str << uCt; if (!isSinglePrecision()) { - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - str << it->getPosition().x << it->getPosition().y << it->getPosition().z - << it->getRotation()[0] << it->getRotation()[1] << it->getRotation()[2] << it->getRotation()[3] ; + for (const auto & it : _lValueList) { + str << it.getPosition().x << it.getPosition().y << it.getPosition().z + << it.getRotation()[0] << it.getRotation()[1] << it.getRotation()[2] << it.getRotation()[3] ; } } else { - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - float x = (float)it->getPosition().x; - float y = (float)it->getPosition().y; - float z = (float)it->getPosition().z; - float q0 = (float)it->getRotation()[0]; - float q1 = (float)it->getRotation()[1]; - float q2 = (float)it->getRotation()[2]; - float q3 = (float)it->getRotation()[3]; + for (const auto & it : _lValueList) { + float x = (float)it.getPosition().x; + float y = (float)it.getPosition().y; + float z = (float)it.getPosition().z; + float q0 = (float)it.getRotation()[0]; + float q1 = (float)it.getRotation()[1]; + float q2 = (float)it.getRotation()[2]; + float q3 = (float)it.getRotation()[3]; str << x << y << z << q0 << q1 << q2 << q3; } } @@ -938,23 +938,23 @@ void PropertyPlacementList::RestoreDocFile(Base::Reader &reader) str >> uCt; std::vector values(uCt); if (!isSinglePrecision()) { - for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + for (auto & it : values) { Base::Vector3d pos; double q0, q1, q2, q3; str >> pos.x >> pos.y >> pos.z >> q0 >> q1 >> q2 >> q3; Base::Rotation rot(q0,q1,q2,q3); - it->setPosition(pos); - it->setRotation(rot); + it.setPosition(pos); + it.setRotation(rot); } } else { float x,y,z,q0,q1,q2,q3; - for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + for (auto & it : values) { str >> x >> y >> z >> q0 >> q1 >> q2 >> q3; Base::Vector3d pos(x, y, z); Base::Rotation rot(q0,q1,q2,q3); - it->setPosition(pos); - it->setRotation(rot); + it.setPosition(pos); + it.setRotation(rot); } } setValues(values); diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index a4eb65a3b0..1620d29e6f 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -983,9 +983,11 @@ std::vector PropertyLinkSub::getSubValuesStartsWith(const char* sta (void)newStyle; std::vector temp; - for(std::vector::const_iterator it=_cSubList.begin();it!=_cSubList.end();++it) - if(strncmp(starter,it->c_str(),strlen(starter))==0) - temp.push_back(*it); + for(const auto & it : _cSubList) { + if(strncmp(starter, it.c_str(), strlen(starter)) == 0) { + temp.push_back(it); + } + } return temp; } @@ -1161,7 +1163,7 @@ const char *PropertyLinkBase::exportSubName(std::string &output, if(!dot) return res; const char *hash; - for(hash=sub;hash_lValueList.size(); i++) { + for (auto i : this->_lValueList) { if (!ret) - ret = this->_lValueList[i]; - if (ret != this->_lValueList[i]) + ret = i; + if (ret != i) return nullptr; } return ret; @@ -1922,10 +1924,10 @@ void PropertyLinkSubList::setSubListValues(const std::vector links; std::vector subs; - for (std::vector::const_iterator it = values.begin(); it != values.end(); ++it) { - for (std::vector::const_iterator jt = it->second.begin(); jt != it->second.end(); ++jt) { - links.push_back(it->first); - subs.push_back(*jt); + for (const auto & value : values) { + for (const auto& jt : value.second) { + links.push_back(value.first); + subs.push_back(jt); } } @@ -3706,9 +3708,11 @@ std::vector PropertyXLink::getSubValuesStartsWith(const char* start (void)newStyle; std::vector temp; - for(std::vector::const_iterator it=_SubList.begin();it!=_SubList.end();++it) - if(strncmp(starter,it->c_str(),strlen(starter))==0) - temp.push_back(*it); + for(const auto & it : _SubList) { + if(strncmp(starter, it.c_str(), strlen(starter)) == 0) { + temp.push_back(it); + } + } return temp; } diff --git a/src/App/PropertyPythonObject.cpp b/src/App/PropertyPythonObject.cpp index 4fa12a9ba9..c519dfb6a4 100644 --- a/src/App/PropertyPythonObject.cpp +++ b/src/App/PropertyPythonObject.cpp @@ -179,19 +179,19 @@ void PropertyPythonObject::loadPickle(const std::string& str) std::string PropertyPythonObject::encodeValue(const std::string& str) const { std::string tmp; - for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) { - if (*it == '<') + for (char it : str) { + if (it == '<') tmp += "<"; - else if (*it == '"') + else if (it == '"') tmp += """; - else if (*it == '&') + else if (it == '&') tmp += "&"; - else if (*it == '>') + else if (it == '>') tmp += ">"; - else if (*it == '\n') + else if (it == '\n') tmp += "\\n"; else - tmp += *it; + tmp += it; } return tmp; @@ -384,8 +384,8 @@ void PropertyPythonObject::Restore(Base::XMLReader &reader) void PropertyPythonObject::SaveDocFile (Base::Writer &writer) const { std::string buffer = this->toString(); - for (std::string::iterator it = buffer.begin(); it != buffer.end(); ++it) - writer.Stream().put(*it); + for (char it : buffer) + writer.Stream().put(it); } void PropertyPythonObject::RestoreDocFile(Base::Reader &reader) diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 96b69440b0..516a71a381 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -388,8 +388,8 @@ void PropertyEnumeration::Save(Base::Writer &writer) const std::vector items = getEnumVector(); writer.Stream() << writer.ind() << "" << endl; writer.incInd(); - for(std::vector::iterator it = items.begin(); it != items.end(); ++it) { - std::string val = encodeAttribute(*it); + for(auto & item : items) { + std::string val = encodeAttribute(item); writer.Stream() << writer.ind() << "" << endl; } writer.decInd(); @@ -839,8 +839,8 @@ void PropertyIntegerSet::setValues(const std::set& values) PyObject *PropertyIntegerSet::getPyObject() { PyObject* set = PySet_New(nullptr); - for(std::set::const_iterator it=_lValueSet.begin();it!=_lValueSet.end();++it) - PySet_Add(set,PyLong_FromLong(*it)); + for(long it : _lValueSet) + PySet_Add(set,PyLong_FromLong(it)); return set; } @@ -877,8 +877,8 @@ void PropertyIntegerSet::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "" << endl; writer.incInd(); - for(std::set::const_iterator it=_lValueSet.begin();it!=_lValueSet.end();++it) - writer.Stream() << writer.ind() << "" << endl; ; + for(long it : _lValueSet) + writer.Stream() << writer.ind() << "" << endl; ; writer.decInd(); writer.Stream() << writer.ind() << "" << endl ; } @@ -1248,13 +1248,13 @@ void PropertyFloatList::SaveDocFile (Base::Writer &writer) const uint32_t uCt = (uint32_t)getSize(); str << uCt; if (!isSinglePrecision()) { - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - str << *it; + for (double it : _lValueList) { + str << it; } } else { - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - float v = (float)*it; + for (double it : _lValueList) { + float v = static_cast(it); str << v; } } @@ -1267,15 +1267,15 @@ void PropertyFloatList::RestoreDocFile(Base::Reader &reader) str >> uCt; std::vector values(uCt); if (!isSinglePrecision()) { - for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { - str >> *it; + for (double & it : values) { + str >> it; } } else { - for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + for (double & it : values) { float val; str >> val; - (*it) = val; + it = val; } } setValues(values); @@ -1880,9 +1880,9 @@ void PropertyMap::setPyObject(PyObject *value) unsigned int PropertyMap::getMemSize () const { size_t size=0; - for (std::map::const_iterator it = _lValueList.begin();it!= _lValueList.end(); ++it) { - size += it->second.size(); - size += it->first.size(); + for (const auto & it : _lValueList) { + size += it.second.size(); + size += it.first.size(); } return size; } @@ -1891,9 +1891,9 @@ void PropertyMap::Save (Base::Writer &writer) const { writer.Stream() << writer.ind() << "" << endl; writer.incInd(); - for (std::map::const_iterator it = _lValueList.begin();it!= _lValueList.end(); ++it) { - writer.Stream() << writer.ind() << "first) - << "\" value=\"" << encodeAttribute(it->second) <<"\"/>" << endl; + for (const auto & it : _lValueList) { + writer.Stream() << writer.ind() << "" << endl; } writer.decInd(); @@ -2359,8 +2359,8 @@ void PropertyColorList::SaveDocFile (Base::Writer &writer) const Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); str << uCt; - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - str << it->getPackedValue(); + for (auto it : _lValueList) { + str << it.getPackedValue(); } } @@ -2371,9 +2371,9 @@ void PropertyColorList::RestoreDocFile(Base::Reader &reader) str >> uCt; std::vector values(uCt); uint32_t value; // must be 32 bit long - for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + for (auto & it : values) { str >> value; - it->setPackedValue(value); + it.setPackedValue(value); } setValues(values); } @@ -2588,13 +2588,13 @@ void PropertyMaterialList::SaveDocFile(Base::Writer &writer) const Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); str << uCt; - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - str << it->ambientColor.getPackedValue(); - str << it->diffuseColor.getPackedValue(); - str << it->specularColor.getPackedValue(); - str << it->emissiveColor.getPackedValue(); - str << it->shininess; - str << it->transparency; + for (const auto & it : _lValueList) { + str << it.ambientColor.getPackedValue(); + str << it.diffuseColor.getPackedValue(); + str << it.specularColor.getPackedValue(); + str << it.emissiveColor.getPackedValue(); + str << it.shininess; + str << it.transparency; } } @@ -2606,19 +2606,19 @@ void PropertyMaterialList::RestoreDocFile(Base::Reader &reader) std::vector values(uCt); uint32_t value; // must be 32 bit long float valueF; - for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + for (auto & it : values) { str >> value; - it->ambientColor.setPackedValue(value); + it.ambientColor.setPackedValue(value); str >> value; - it->diffuseColor.setPackedValue(value); + it.diffuseColor.setPackedValue(value); str >> value; - it->specularColor.setPackedValue(value); + it.specularColor.setPackedValue(value); str >> value; - it->emissiveColor.setPackedValue(value); + it.emissiveColor.setPackedValue(value); str >> valueF; - it->shininess = valueF; + it.shininess = valueF; str >> valueF; - it->transparency = valueF; + it.transparency = valueF; } setValues(values); } diff --git a/src/App/Transactions.cpp b/src/App/Transactions.cpp index 2f31fa4c08..132d452526 100644 --- a/src/App/Transactions.cpp +++ b/src/App/Transactions.cpp @@ -62,8 +62,8 @@ Transaction::Transaction(int id) Transaction::~Transaction() { auto &index = _Objects.get<0>(); - for (auto It= index.begin();It!=index.end();++It) { - if (It->second->status == TransactionObject::New) { + for (const auto & It : index) { + if (It.second->status == TransactionObject::New) { // If an object has been removed from the document the transaction // status is 'New'. The 'pcNameInDocument' member serves as criterion // to check whether the object is part of the document or not. @@ -75,8 +75,8 @@ Transaction::~Transaction() // to cause a memory leak. This usually is the case when the removal // of an object is not undone or when an addition is undone. - if (!It->first->isAttachedToDocument()) { - if (It->first->getTypeId().isDerivedFrom(DocumentObject::getClassTypeId())) { + if (!It.first->isAttachedToDocument()) { + if (It.first->getTypeId().isDerivedFrom(DocumentObject::getClassTypeId())) { // #0003323: Crash when clearing transaction list // It can happen that when clearing the transaction list several objects // are destroyed with dependencies which can lead to dangling pointers. @@ -85,13 +85,13 @@ Transaction::~Transaction() // possible dangling pointers. // An alternative solution is to call breakDependency inside // Document::_removeObject. Make this change in v0.18. - const DocumentObject* obj = static_cast(It->first); + const DocumentObject* obj = static_cast(It.first); const_cast(obj)->setStatus(ObjectStatus::Destroy, true); } - delete It->first; + delete It.first; } } - delete It->second; + delete It.second; } } diff --git a/src/App/VRMLObject.cpp b/src/App/VRMLObject.cpp index e2cb7a8576..a7b04846ad 100644 --- a/src/App/VRMLObject.cpp +++ b/src/App/VRMLObject.cpp @@ -139,8 +139,8 @@ void VRMLObject::Save (Base::Writer &writer) const // save also the inline files if there const std::vector& urls = Resources.getValues(); - for (std::vector::const_iterator it = urls.begin(); it != urls.end(); ++it) { - writer.addFile(it->c_str(), this); + for (const auto & url : urls) { + writer.addFile(url.c_str(), this); } this->index = 0; @@ -153,8 +153,8 @@ void VRMLObject::Restore(Base::XMLReader &reader) // restore also the inline files if there const std::vector& urls = Resources.getValues(); - for(std::vector::const_iterator it = urls.begin(); it != urls.end(); ++it) { - reader.addFile(it->c_str(), this); + for(const auto & url : urls) { + reader.addFile(url.c_str(), this); } this->index = 0;