diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp index d39ffe5a9fc6532ee19be8e76c5d295a5fc37f91..81ec937fc83de2070d25f7f20e2534be09db38fd 100644 --- a/Applications/ApplicationsLib/ProjectData.cpp +++ b/Applications/ApplicationsLib/ProjectData.cpp @@ -166,12 +166,13 @@ std::vector<std::unique_ptr<MeshLib::Mesh>> readMeshes( if (optional_meshes) { DBUG("Reading multiple meshes."); - for (auto mesh_config : - //! \ogs_file_param{prj__meshes__mesh} - optional_meshes->getConfigParameterList("mesh")) - { - meshes.push_back(readSingleMesh(mesh_config, project_directory)); - } + //! \ogs_file_param{prj__meshes__mesh} + auto const configs = optional_meshes->getConfigParameterList("mesh"); + std::transform( + configs.begin(), configs.end(), std::back_inserter(meshes), + [&project_directory](auto const& mesh_config) { + return readSingleMesh(mesh_config, project_directory); + }); } else { // Read single mesh with geometry. @@ -268,9 +269,8 @@ ProjectData::ProjectData() = default; ProjectData::ProjectData(BaseLib::ConfigTree const& project_config, std::string const& project_directory, std::string const& output_directory) + : _mesh_vec(readMeshes(project_config, project_directory)) { - _mesh_vec = readMeshes(project_config, project_directory); - if (auto const python_script = //! \ogs_file_param{prj__python_script} project_config.getConfigParameterOptional<std::string>("python_script")) diff --git a/Applications/ApplicationsLib/TestDefinition.cpp b/Applications/ApplicationsLib/TestDefinition.cpp index ccf454f03d06ad38b10690703c16785984d454e3..525744d948d2c4d24a30246fa90915464dd0efb9 100644 --- a/Applications/ApplicationsLib/TestDefinition.cpp +++ b/Applications/ApplicationsLib/TestDefinition.cpp @@ -53,7 +53,7 @@ bool isConvertibleToDouble(std::string const& s) } /// Wraps a string into double ticks. -std::string safeString(std::string s) +std::string safeString(std::string const& s) { return "\"" + s + "\""; } diff --git a/Applications/DataExplorer/DataView/ElementTreeModel.cpp b/Applications/DataExplorer/DataView/ElementTreeModel.cpp index 748921e924526af6e7f171c7d2caafc431da8bcc..5288786efbe718f2592f8dc14d503fedd35f8df4 100644 --- a/Applications/DataExplorer/DataView/ElementTreeModel.cpp +++ b/Applications/DataExplorer/DataView/ElementTreeModel.cpp @@ -132,15 +132,15 @@ void ElementTreeModel::setMesh(MeshLib::Mesh const& mesh) MeshLib::MeshInformation::getNumberOfElementTypes(mesh); for (auto entry : n_element_types) { - QList<QVariant> elements_number; - elements_number << QString::fromStdString( - MeshLib::MeshElemType2String( - static_cast<MeshLib::MeshElemType>( - entry.first)) + - "s:") - << QString::number(entry.second) << "" - << ""; - auto* type_item = new TreeItem(elements_number, elements_item); + QList<QVariant> number_of_element_types; + number_of_element_types + << QString::fromStdString( + MeshLib::MeshElemType2String( + static_cast<MeshLib::MeshElemType>(entry.first)) + + "s:") + << QString::number(entry.second) << "" + << ""; + auto* type_item = new TreeItem(number_of_element_types, elements_item); elements_item->appendChild(type_item); } diff --git a/Applications/DataExplorer/DataView/GEOModels.cpp b/Applications/DataExplorer/DataView/GEOModels.cpp index a98999944c32c817a03624ca3672a6a1f460861b..b94ccda1a6ebd6e0f96cfb1cd16e9fe9d0df20e1 100644 --- a/Applications/DataExplorer/DataView/GEOModels.cpp +++ b/Applications/DataExplorer/DataView/GEOModels.cpp @@ -172,17 +172,18 @@ void GEOModels::connectPolylineSegments( if (plyVec) { - const std::vector<GeoLib::Polyline*>* polylines = plyVec->getVector(); + std::vector<GeoLib::Polyline*> const& polylines = *plyVec->getVector(); std::vector<GeoLib::Polyline*> ply_list; - for (auto& elem : indexlist) - { - ply_list.push_back((*polylines)[elem]); - } + std::transform(indexlist.begin(), indexlist.end(), + std::back_inserter(ply_list), + [polylines](auto const& ply_index) { + return polylines[ply_index]; + }); // connect polylines - GeoLib::Polyline* new_line = GeoLib::Polyline::constructPolylineFromSegments( - ply_list, - proximity); + GeoLib::Polyline* new_line = + GeoLib::Polyline::constructPolylineFromSegments(ply_list, + proximity); if (new_line) { @@ -218,7 +219,7 @@ void GEOModels::connectPolylineSegments( if (!ply_name.empty()) { - plyVec->setNameOfElementByID(polylines->size(), ply_name); + plyVec->setNameOfElementByID(polylines.size(), ply_name); } } else diff --git a/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp b/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp index 28efd4a4d8809175f091e06b5b2075361a23dc39..ac3acaf68cd46c07cc652f92c5329d4534b2f4c6 100644 --- a/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp +++ b/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp @@ -57,10 +57,8 @@ GMSHPrefsDialog::GMSHPrefsDialog(GeoLib::GEOObjects const& geoObjects, QDialog* std::vector<std::string> geo_station_names; geoObjects.getStationVectorNames(geo_station_names); - for (auto& geo_station_name : geo_station_names) - { - geoNames.push_back(geo_station_name); - } + std::copy(geo_station_names.begin(), geo_station_names.end(), + geoNames.begin()); std::size_t nGeoObjects(geoNames.size()); @@ -192,9 +190,7 @@ void GMSHPrefsDialog::reject() std::vector<std::string> GMSHPrefsDialog::getSelectedObjects(QStringList list) { std::vector<std::string> indexList; - for (auto& index : list) - { - indexList.push_back(index.toStdString()); - } + std::transform(list.begin(), list.end(), std::back_inserter(indexList), + [](auto const& index) { return index.toStdString(); }); return indexList; } diff --git a/Applications/DataExplorer/DataView/GeoTreeView.cpp b/Applications/DataExplorer/DataView/GeoTreeView.cpp index aa6182c6e77a5b1e6f363f36ff65ddee2567bb2a..651364116c0eab3d28258d788d79e89ebb8f461e 100644 --- a/Applications/DataExplorer/DataView/GeoTreeView.cpp +++ b/Applications/DataExplorer/DataView/GeoTreeView.cpp @@ -142,17 +142,17 @@ void GeoTreeView::contextMenuEvent( QContextMenuEvent* event ) // The current index is a list of points/polylines/surfaces if (list != nullptr) { - QAction* convertToStationAction(nullptr); if (list->getType() == GeoLib::GEOTYPE::POINT) { - convertToStationAction = menu.addAction("Convert to Stations"); + auto const* convertToStationAction = + menu.addAction("Convert to Stations"); connect(convertToStationAction, SIGNAL(triggered()), this, SLOT(convertPointsToStations())); } - QAction* connectPlyAction(nullptr); if (list->getType() == GeoLib::GEOTYPE::POLYLINE) { - connectPlyAction = menu.addAction("Connect Polylines..."); + auto const* connectPlyAction = + menu.addAction("Connect Polylines..."); connect(connectPlyAction, SIGNAL(triggered()), this, SLOT(connectPolylines())); } diff --git a/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp b/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp index cc6026553ace00ed4d87eba4d304a8ff2e891bd4..1b180cd56354cc16c2e1b056dc184dd87b3cad0e 100644 --- a/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp +++ b/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp @@ -114,11 +114,9 @@ void MergeGeometriesDialog::reject() std::vector<std::string> MergeGeometriesDialog::getSelectedGeometries() const { std::vector<std::string> indexList; - QStringList const& list (_selGeo->stringList()); - for (const auto& index : list) - { - indexList.push_back(index.toStdString()); - } + QStringList const& list(_selGeo->stringList()); + std::transform(list.begin(), list.end(), std::back_inserter(indexList), + [](auto const& index) { return index.toStdString(); }); return indexList; } diff --git a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp index 4a4327f17bc6c889d8d7146c518e8f9b3545b122..51f798466c1d8c1b04b0814eb5874ee027264780 100644 --- a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp +++ b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp @@ -145,25 +145,20 @@ void MeshElementRemovalDialog::accept() if (anything_checked) { - MeshLib::Mesh* new_mesh = MeshLib::removeElements(*msh, ex.getSearchedElementIDs(), this->newMeshNameEdit->text().toStdString()); + MeshLib::Mesh* new_mesh = MeshLib::removeElements( + *msh, ex.getSearchedElementIDs(), + this->newMeshNameEdit->text().toStdString()); if (new_mesh) { emit meshAdded(new_mesh); } else { - if (new_mesh == nullptr) - { - OGSError::box( - "The current selection removes ALL mesh elements.\nPlease " - "change the selection."); - } if (ex.getSearchedElementIDs().empty()) { OGSError::box( "The current selection removes NO mesh elements."); } - delete new_mesh; return; } } diff --git a/Applications/DataExplorer/DataView/StationTreeModel.cpp b/Applications/DataExplorer/DataView/StationTreeModel.cpp index c3ccb786830c0b5a11a7b90e3b6818a31f0d4b21..1aab56e17d0bf8bc22b9e4baec7a53fb1b62c7c4 100644 --- a/Applications/DataExplorer/DataView/StationTreeModel.cpp +++ b/Applications/DataExplorer/DataView/StationTreeModel.cpp @@ -54,14 +54,14 @@ QModelIndex StationTreeModel::index( int row, int column, if (!parent.isValid()) { - parentItem = (ModelTreeItem*)(_rootItem); + parentItem = static_cast<ModelTreeItem*>(_rootItem); } else { parentItem = static_cast<ModelTreeItem*>(parent.internalPointer()); } - auto* childItem = (ModelTreeItem*)(parentItem->child(row)); + auto* childItem = static_cast<ModelTreeItem*>(parentItem->child(row)); if (childItem) { QModelIndex newIndex = createIndex(row, column, childItem); diff --git a/Applications/DataExplorer/VtkVis/NetCdfConfigureDialog.cpp b/Applications/DataExplorer/VtkVis/NetCdfConfigureDialog.cpp index a2d53cee2ad4fca4b352a00e12140b2e2b243e37..d42e89fe20045ee7830551ed60a4cbffc10a8eae 100644 --- a/Applications/DataExplorer/VtkVis/NetCdfConfigureDialog.cpp +++ b/Applications/DataExplorer/VtkVis/NetCdfConfigureDialog.cpp @@ -71,9 +71,8 @@ void NetCdfConfigureDialog::reject() this->done(QDialog::Rejected); } -void NetCdfConfigureDialog::on_comboBoxVariable_currentIndexChanged(int id) +void NetCdfConfigureDialog::on_comboBoxVariable_currentIndexChanged(int /*id*/) { - Q_UNUSED(id); std::string const var_name = comboBoxVariable->currentText().toStdString(); _currentVar = _currentFile.getVar(var_name); setDimensionSelect(); @@ -92,11 +91,10 @@ void NetCdfConfigureDialog::on_comboBoxDim1_currentIndexChanged(int id) } //set up y-axis/lon -void NetCdfConfigureDialog::on_comboBoxDim2_currentIndexChanged(int id) +void NetCdfConfigureDialog::on_comboBoxDim2_currentIndexChanged(int /*id*/) { if (_currentVar.getDimCount() > 1) { - if (id == -1) id = 0; double firstValue=0, lastValue=0; unsigned size = 0; getDimEdges(comboBoxDim2->currentText().toStdString(), size, firstValue, lastValue); @@ -106,11 +104,10 @@ void NetCdfConfigureDialog::on_comboBoxDim2_currentIndexChanged(int id) } //set up time -void NetCdfConfigureDialog::on_comboBoxDim3_currentIndexChanged(int id) +void NetCdfConfigureDialog::on_comboBoxDim3_currentIndexChanged(int /*id*/) { if (_currentVar.getDimCount() > 2) { - if (id == -1) id = 0; double firstValue=0, lastValue=0; unsigned size = 0; getDimEdges(comboBoxDim3->currentText().toStdString(), size, firstValue, lastValue); @@ -122,9 +119,8 @@ void NetCdfConfigureDialog::on_comboBoxDim3_currentIndexChanged(int id) } //set up additional dimension -void NetCdfConfigureDialog::on_comboBoxDim4_currentIndexChanged(int id) +void NetCdfConfigureDialog::on_comboBoxDim4_currentIndexChanged(int /*id*/) { - Q_UNUSED(id); if (_currentVar.getDimCount() > 3) { double firstValue=0, lastValue=0; @@ -293,8 +289,9 @@ void NetCdfConfigureDialog::createDataObject() data_length.push_back(sizeLon); _currentVar.getVar(data_origin, data_length, data_array.data()); - std::replace_if(data_array.begin(), data_array.end(), - [](double& x) { return x <= -9999; }, -9999); + std::replace_if( + data_array.begin(), data_array.end(), + [](double const& x) { return x <= -9999; }, -9999); double origin_x = (originLon < lastLon) ? originLon : lastLon; double origin_y = (originLat < lastLat) ? originLat : lastLat; diff --git a/Applications/DataExplorer/VtkVis/NetCdfConfigureDialog.h b/Applications/DataExplorer/VtkVis/NetCdfConfigureDialog.h index 614c37bb9eae3b70d3b5d0aabc9658ae54afd920..a194754ecbee3afcaf2c93a300de2a820f5fbc1e 100644 --- a/Applications/DataExplorer/VtkVis/NetCdfConfigureDialog.h +++ b/Applications/DataExplorer/VtkVis/NetCdfConfigureDialog.h @@ -33,8 +33,8 @@ class NetCdfConfigureDialog : public QDialog, private Ui_NetCdfConfigure Q_OBJECT public: - NetCdfConfigureDialog(const std::string& fileName, - QDialog* parent = nullptr); + explicit NetCdfConfigureDialog(const std::string& fileName, + QDialog* parent = nullptr); ~NetCdfConfigureDialog() override; MeshLib::Mesh* getMesh() { return _currentMesh; }; std::string getName(); diff --git a/Applications/DataExplorer/VtkVis/VtkColorByHeightFilter.cpp b/Applications/DataExplorer/VtkVis/VtkColorByHeightFilter.cpp index fc47e8a1858bba88ae5b0a27bfa55dcbeefa73a8..34147226f220541a70ebc8385f062f39d8f8585f 100644 --- a/Applications/DataExplorer/VtkVis/VtkColorByHeightFilter.cpp +++ b/Applications/DataExplorer/VtkVis/VtkColorByHeightFilter.cpp @@ -33,7 +33,7 @@ vtkStandardNewMacro(VtkColorByHeightFilter); VtkColorByHeightFilter::VtkColorByHeightFilter() - : ColorLookupTable(VtkColorLookupTable::New()) + : ColorLookupTable(VtkColorLookupTable::New()), _tableRange{0.0, 0.0} { } @@ -101,10 +101,13 @@ void VtkColorByHeightFilter::SetTableRange(double min, double max) this->ColorLookupTable->SetTableRange(min, max); } else - ERR("VtkColorByHeightFilter::SetLimits(min, max) - Limits not changed because min value > max value."); + { + ERR("VtkColorByHeightFilter::SetLimits(min, max) - Limits not changed " + "because min value > max value."); + } } -void VtkColorByHeightFilter::SetTableRangeScaling( double scale ) +void VtkColorByHeightFilter::SetTableRangeScaling(double scale) { this->_tableRangeScaling = scale; this->ColorLookupTable->SetTableRange( diff --git a/Applications/DataExplorer/VtkVis/VtkColorLookupTable.cpp b/Applications/DataExplorer/VtkVis/VtkColorLookupTable.cpp index 4d332370f6f5bcc4475cb457e5a3c99dd3dc3831..db18bfd8da4e0e89c4779883c922687fa572a116 100644 --- a/Applications/DataExplorer/VtkVis/VtkColorLookupTable.cpp +++ b/Applications/DataExplorer/VtkVis/VtkColorLookupTable.cpp @@ -62,14 +62,14 @@ void VtkColorLookupTable::Build() // make sure that color map starts with the first color in the dictionary unsigned char startcolor[4] = { 0, 0 , 0 , 0 }; std::pair<std::size_t, unsigned char*> lastValue(0, startcolor); - std::size_t nextIndex(0); for (auto& it : _dict) { double val = (it.first < range[0]) ? range[0] : ((it.first > range[1]) ? range[1] : it.first); - nextIndex = static_cast<std::size_t>(std::floor(val - range[0])); + auto const nextIndex = + static_cast<std::size_t>(std::floor(val - range[0])); this->SetTableValueRGBA(nextIndex, it.second); diff --git a/Applications/DataExplorer/VtkVis/VtkRaster.cpp b/Applications/DataExplorer/VtkVis/VtkRaster.cpp index 7d0ae1125aad9fd8480693a260cbb96920d09fc7..db80c188292ca0a16f1155a8400eb933dc8a2056 100644 --- a/Applications/DataExplorer/VtkVis/VtkRaster.cpp +++ b/Applications/DataExplorer/VtkVis/VtkRaster.cpp @@ -309,19 +309,18 @@ std::string VtkRaster::findWorldFile(std::string const& filename) { std::string const no_ext = BaseLib::dropFileExtension(filename); - std::vector<std::string> const supported_extensions = - { ".pgw", ".pngw", ".pgwx", - ".jgw", ".jpgw", ".jgwx", - ".tfw", ".tifw", ".tfwx", - ".bpw", ".bmpw", ".bpwx", - ".wld" }; - - for (auto& ext : supported_extensions) + constexpr std::array supported_extensions = { + ".pgw", ".pngw", ".pgwx", ".jgw", ".jpgw", ".jgwx", ".tfw", + ".tifw", ".tfwx", ".bpw", ".bmpw", ".bpwx", ".wld"}; + + auto const res = + std::find_if(supported_extensions.begin(), supported_extensions.end(), + [&no_ext](auto const& ext) -> bool { + return BaseLib::IsFileExisting(no_ext + ext); + }); + if (res != supported_extensions.end()) { - if (BaseLib::IsFileExisting(no_ext + ext)) - { - return no_ext + ext; - } + return no_ext + *res; } // no world file found diff --git a/Applications/DataHolderLib/FemCondition.cpp b/Applications/DataHolderLib/FemCondition.cpp index 27143a6cda5bce6f2f2b5a909716c7ab8df3e41e..eac21de50dc899e9941f0099f198b9e41e0698f4 100644 --- a/Applications/DataHolderLib/FemCondition.cpp +++ b/Applications/DataHolderLib/FemCondition.cpp @@ -17,14 +17,15 @@ FemCondition::FemCondition(ProcessVariable const& process_var, std::string const& param_name) : _process_var(process_var), _param_name(param_name){}; -void FemCondition::setMesh(std::string const mesh_name) +void FemCondition::setMesh(std::string const& mesh_name) { _base_type = BaseObjType::MESH; _base_obj_name = mesh_name; _obj_name = ""; } -void FemCondition::setGeoObject(std::string geo_name, std::string obj_name) +void FemCondition::setGeoObject(std::string const& geo_name, + std::string const& obj_name) { _base_type = BaseObjType::GEOMETRY; _base_obj_name = geo_name; diff --git a/Applications/DataHolderLib/FemCondition.h b/Applications/DataHolderLib/FemCondition.h index 936ddf2a15dc7ef3e494cdd1323a048f965fc4a2..9547fe3517ff8c6f7dddd96983b7182833fd9034 100644 --- a/Applications/DataHolderLib/FemCondition.h +++ b/Applications/DataHolderLib/FemCondition.h @@ -62,10 +62,11 @@ public: std::string const getObjName() const { return _obj_name; } /// Sets a mesh as corresponding object for the condition - void setMesh(std::string const mesh_name); + void setMesh(std::string const& mesh_name); /// Sets a geometric object as corresponding object for the condition - virtual void setGeoObject(std::string geo_name, std::string obj_name); + virtual void setGeoObject(std::string const& geo_name, + std::string const& obj_name); /// Returns the type of condition for displaying purposes virtual std::string const getConditionClassStr() const = 0; diff --git a/Applications/DataHolderLib/Project.cpp b/Applications/DataHolderLib/Project.cpp index 0e7fa62fee873d02f3e30aed80ac7b7dad515675..8f7e164f0c46dbd8d061c93335d660bf6d9af0b8 100644 --- a/Applications/DataHolderLib/Project.cpp +++ b/Applications/DataHolderLib/Project.cpp @@ -98,7 +98,7 @@ bool Project::getUniqueName(std::string &name) const return isUnique; } -void Project::removePrimaryVariable(std::string const primary_var_name) +void Project::removePrimaryVariable(std::string const& primary_var_name) { std::size_t const n_bc(_boundary_conditions.size()); for (int i = n_bc - 1; i >= 0; --i) diff --git a/Applications/DataHolderLib/Project.h b/Applications/DataHolderLib/Project.h index 02ca92343018e77967d2618e0b7c8fe6f53ee0eb..ff082a8ba8a353c4a9f246e289ad07b8fb97d76a 100644 --- a/Applications/DataHolderLib/Project.h +++ b/Applications/DataHolderLib/Project.h @@ -90,7 +90,7 @@ public: } /// Removes a primary variable incl. all associated conditions - void removePrimaryVariable(std::string const primary_var_name); + void removePrimaryVariable(std::string const& primary_var_name); /// Removes one boundary condition void removeBoundaryCondition(std::string const& primary_var_name, diff --git a/Applications/FileIO/AsciiRasterInterface.cpp b/Applications/FileIO/AsciiRasterInterface.cpp index 0e5ede1797b9b05765cb61397bed1f8aa304decb..6376de0e58f9bbe016da6d6617276c9113f09c85 100644 --- a/Applications/FileIO/AsciiRasterInterface.cpp +++ b/Applications/FileIO/AsciiRasterInterface.cpp @@ -292,10 +292,10 @@ boost::optional<std::vector<GeoLib::Raster const*>> readRasters( std::vector<GeoLib::Raster const*> rasters; rasters.reserve(raster_paths.size()); - for (auto const& path : raster_paths) - { - rasters.push_back(FileIO::AsciiRasterInterface::readRaster(path)); - } + std::transform(raster_paths.begin(), raster_paths.end(), + std::back_inserter(rasters), [](auto const& path) { + return FileIO::AsciiRasterInterface::readRaster(path); + }); return boost::make_optional(rasters); } } // end namespace FileIO diff --git a/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp b/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp index 67630e67782b7bdaca41113a619daea706e8257e..01c588c932ec508e46d2035ba52be814aeda9db7 100644 --- a/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp +++ b/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp @@ -312,7 +312,7 @@ void FEFLOWMeshInterface::readNodeCoordinates( void FEFLOWMeshInterface::readNodeCoordinates( std::ifstream& in, const FEM_CLASS& fem_class, const FEM_DIM& fem_dim, - std::vector<MeshLib::Node*>& vec_nodes) + std::vector<MeshLib::Node*> const& vec_nodes) { const std::size_t no_nodes_per_layer = (fem_class.dimension == 2) diff --git a/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.h b/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.h index 07d38f0fb4e547dfa318d77636002e4302784f55..00246c5ad945a85186eb4d1e4103cd842a7a5884 100644 --- a/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.h +++ b/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.h @@ -99,7 +99,7 @@ private: void readNodeCoordinates(std::ifstream& in, const FEM_CLASS& fem_class, const FEM_DIM& fem_dim, - std::vector<MeshLib::Node*>& nodes); + std::vector<MeshLib::Node*> const& nodes); /// read elevation data void readElevation(std::ifstream& in, diff --git a/Applications/FileIO/GMSInterface.cpp b/Applications/FileIO/GMSInterface.cpp index 71cab4a8c2e76a44a53cc72d6ca31fb0b269f2f5..10415bddc5f4e54033f66ce5546cd268127618aa 100644 --- a/Applications/FileIO/GMSInterface.cpp +++ b/Applications/FileIO/GMSInterface.cpp @@ -304,14 +304,7 @@ MeshLib::Mesh* GMSInterface::readGMS3DMMesh(const std::string& filename) if (!opt_pv) { ERR("Could not create PropertyVector for material ids."); - for (auto element : elements) - { - delete element; - } - for (auto node : nodes) - { - delete node; - } + BaseLib::cleanupVectorElements(nodes, elements); return nullptr; } opt_pv->reserve(mat_ids.size()); diff --git a/Applications/FileIO/GocadIO/GocadAsciiReader.cpp b/Applications/FileIO/GocadIO/GocadAsciiReader.cpp index c5f4dd22ba7c0b22800ba3c7028eeaa6c415d034..26147fa5b8a0e6c30457dc4782498de84835c99a 100644 --- a/Applications/FileIO/GocadIO/GocadAsciiReader.cpp +++ b/Applications/FileIO/GocadIO/GocadAsciiReader.cpp @@ -64,20 +64,6 @@ bool isCommentLine(std::string const& str) return (str.substr(0, 1) == "#"); } -/// Clears data vectors if an error occured -void clearData(std::vector<MeshLib::Node*>& nodes, - std::vector<MeshLib::Element*>& elems) -{ - for (MeshLib::Element* e : elems) - { - delete e; - } - for (MeshLib::Node* n : nodes) - { - delete n; - } -} - /// Parses current section until END-tag is reached bool skipToEND(std::ifstream& in) { @@ -177,13 +163,12 @@ std::string propertyCheck(std::string const& strng) {"PROPERTY_CLASSES", "PROP_LEGAL_RANGES", "NO_DATA_VALUES", "PROPERTY_KINDS", "PROPERTY_SUBCLASSES", "UNITS", "ESIZES"}}; - std::vector<std::string> str = BaseLib::splitString(strng); - for (std::string key : property_keywords) + std::string const str = BaseLib::splitString(strng)[0]; + auto res = + std::find(property_keywords.begin(), property_keywords.end(), str); + if (res != property_keywords.end()) { - if (str[0] == key) - { - return key; - } + return *res; } return std::string(""); } @@ -538,7 +523,7 @@ MeshLib::Mesh* createMesh(std::ifstream& in, DataType type, return new MeshLib::Mesh(mesh_name, nodes, elems, mesh_prop); } ERR("Error parsing {:s} {:s}.", dataType2ShortString(type), mesh_name); - clearData(nodes, elems); + BaseLib::cleanupVectorElements(nodes, elems); return nullptr; } diff --git a/Applications/FileIO/GocadIO/GocadSGridReader.cpp b/Applications/FileIO/GocadIO/GocadSGridReader.cpp index b31846fe0cbee95bb6739cbdaf42980021a1c9eb..8ed53a9ab52a7133506b3a8eff106db2f8e9918a 100644 --- a/Applications/FileIO/GocadIO/GocadSGridReader.cpp +++ b/Applications/FileIO/GocadIO/GocadSGridReader.cpp @@ -636,7 +636,7 @@ void GocadSGridReader::readSplitInformation() void GocadSGridReader::applySplitInformation( std::vector<MeshLib::Node*>& nodes, - std::vector<MeshLib::Element*>& elements) const + std::vector<MeshLib::Element*> const& elements) const { for (auto split_node : _split_nodes) { diff --git a/Applications/FileIO/GocadIO/GocadSGridReader.h b/Applications/FileIO/GocadIO/GocadSGridReader.h index 15b04dda5cb56c03d260e296b7730abc8cdd1e06..3cfb6f9bdd203e5468516823ada10e42a397ec1c 100644 --- a/Applications/FileIO/GocadIO/GocadSGridReader.h +++ b/Applications/FileIO/GocadIO/GocadSGridReader.h @@ -71,8 +71,9 @@ private: // split handling void readSplitInformation(); - void applySplitInformation(std::vector<MeshLib::Node*>& nodes, - std::vector<MeshLib::Element*>& elements) const; + void applySplitInformation( + std::vector<MeshLib::Node*>& nodes, + std::vector<MeshLib::Element*> const& elements) const; void modifyElement(MeshLib::Element* hex, MeshLib::Node const* node2sub, MeshLib::Node* substitute_node) const; diff --git a/Applications/FileIO/GocadIO/Property.cpp b/Applications/FileIO/GocadIO/Property.cpp index 615a93ceb6e742f3a8d8a298ac959534ac135288..c89cd317dfcec49fe9eac4452ff9c5508565c4b5 100644 --- a/Applications/FileIO/GocadIO/Property.cpp +++ b/Applications/FileIO/GocadIO/Property.cpp @@ -59,7 +59,8 @@ Property parseGocadPropertyMetaData(std::string& line, std::istream& in, BaseLib::trim(prop._property_name, '\"'); auto checkPropertyID = - [](boost::tokenizer<boost::char_separator<char>>::iterator& tok_it, + [](boost::tokenizer<boost::char_separator<char>>::iterator const& + tok_it, Property const& prop) { if (!prop.checkID(*tok_it)) { diff --git a/Applications/FileIO/Legacy/createSurface.cpp b/Applications/FileIO/Legacy/createSurface.cpp index d6aa2684d286cb945361034afd7cc155430406ca..6e8211906e17eb4f6c1632a36d8181842b913a78 100644 --- a/Applications/FileIO/Legacy/createSurface.cpp +++ b/Applications/FileIO/Legacy/createSurface.cpp @@ -56,10 +56,9 @@ bool createSurface(GeoLib::Polyline const& ply, auto polyline_points = std::make_unique<std::vector<GeoLib::Point*>>(); GeoLib::GEOObjects geo; auto ply_points = ply.getPointsVec(); - for (auto p : ply_points) - { - polyline_points->push_back(new GeoLib::Point(*p)); - } + std::transform(ply_points.begin(), ply_points.end(), + std::back_inserter(*polyline_points), + [](auto const* p) { return new GeoLib::Point(*p); }); std::string ply_name = "temporary_polyline_name"; geo.addPointVec(std::move(polyline_points), ply_name); auto polyline = diff --git a/Applications/FileIO/SWMM/SWMMInterface.cpp b/Applications/FileIO/SWMM/SWMMInterface.cpp index 072afa331289b49bd23a8ca59f07cb0f9b382398..2c45596b395888d5df22b287951b106c8f6490f3 100644 --- a/Applications/FileIO/SWMM/SWMMInterface.cpp +++ b/Applications/FileIO/SWMM/SWMMInterface.cpp @@ -350,16 +350,6 @@ bool SwmmInterface::readLinksAsPolylines(std::ifstream &in, return true; } -/// Deletes the geometric objects and returns false -bool geometryCleanup(std::vector<GeoLib::Point*> &points, std::vector<GeoLib::Polyline*> &lines) -{ - for (auto line : lines) - delete line; - for (auto point : points) - delete point; - return false; -} - bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, GeoLib::GEOObjects &geo_objects, bool add_subcatchments) { @@ -380,27 +370,24 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, std::string geo_name = BaseLib::extractBaseNameWithoutExtension(inp_file_name); std::string line; - while ( std::getline(in, line) ) + while (std::getline(in, line)) { - if (line == "[COORDINATES]") - { - if (!readCoordinates<GeoLib::Point>(in, *points, pnt_names)) - return geometryCleanup(*points, *lines); - } - if (line == "[VERTICES]") + if (line == "[COORDINATES]" || line == "[VERTICES]" || + line == "[SYMBOLS]") { if (!readCoordinates<GeoLib::Point>(in, *points, pnt_names)) - return geometryCleanup(*points, *lines); + { + BaseLib::cleanupVectorElements(*points, *lines); + return false; + } } if (line == "[Polygons]" && add_subcatchments) { if (!readPolygons(in, *lines, line_names, *points, pnt_names)) - return geometryCleanup(*points, *lines); - } - if (line == "[SYMBOLS]") - { - if (!readCoordinates<GeoLib::Point>(in, *points, pnt_names)) - return geometryCleanup(*points, *lines); + { + BaseLib::cleanupVectorElements(*points, *lines); + return false; + } } } @@ -411,8 +398,9 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, } if (points->size() != pnt_names.size()) { - ERR ("Length of point vector and point name vector do not match."); - return geometryCleanup(*points, *lines); + ERR("Length of point vector and point name vector do not match."); + BaseLib::cleanupVectorElements(*points, *lines); + return false; } auto name_id_map = std::make_unique<std::map<std::string, std::size_t>>(); @@ -429,31 +417,43 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, in.clear(); in.seekg(0, in.beg); - while ( std::getline(in, line) ) + while (std::getline(in, line)) { if (line == "[JUNCTIONS]") { INFO ("Reading point elevation..."); if (!addPointElevation(in, *points, *name_id_map)) - return geometryCleanup(*points, *lines); + { + BaseLib::cleanupVectorElements(*points, *lines); + return false; + } } if (line == "[CONDUITS]") { INFO ("Reading conduits..."); if (!readLinksAsPolylines(in, *lines, line_names, *points, *name_id_map)) - return geometryCleanup(*points, *lines); + { + BaseLib::cleanupVectorElements(*points, *lines); + return false; + } } else if (line == "[PUMPS]") { INFO ("Reading pumps..."); if (!readLinksAsPolylines(in, *lines, line_names, *points, *name_id_map)) - return geometryCleanup(*points, *lines); + { + BaseLib::cleanupVectorElements(*points, *lines); + return false; + } } else if (line == "[WEIRS]") { INFO ("Reading weirs..."); if (!readLinksAsPolylines(in, *lines, line_names, *points, *name_id_map)) - return geometryCleanup(*points, *lines); + { + BaseLib::cleanupVectorElements(*points, *lines); + return false; + } } } @@ -478,21 +478,23 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, } } std::vector<std::size_t> const& pnt_id_map (geo_objects.getPointVecObj(geo_name)->getIDMap()); - for (GeoLib::Polyline* line : *lines) + for (GeoLib::Polyline* polyline : *lines) { - for (std::size_t i=0; i<line->getNumberOfPoints(); ++i) + for (std::size_t i = 0; i < polyline->getNumberOfPoints(); ++i) { - line->setPointID(i, pnt_id_map[line->getPointID(i)]); - if (i>0 && line->getPointID(i-1) == line->getPointID(i)) + polyline->setPointID(i, pnt_id_map[polyline->getPointID(i)]); + if (i > 0 && + polyline->getPointID(i - 1) == polyline->getPointID(i)) { - line->removePoint(i); + polyline->removePoint(i); i--; } } - if (line->getPointID(0) == line->getPointID(line->getNumberOfPoints()-1)) + if (polyline->getPointID(0) == + polyline->getPointID(polyline->getNumberOfPoints() - 1)) { - line->removePoint(line->getNumberOfPoints()-1); - line->addPoint(line->getPointID(0)); + polyline->removePoint(polyline->getNumberOfPoints() - 1); + polyline->addPoint(polyline->getPointID(0)); } } geo_objects.addPolylineVec(std::move(lines), geo_name, @@ -851,8 +853,9 @@ std::vector<std::string> SwmmInterface::getSubcatchmentNameMap() const { std::vector<std::string> names; names.reserve(_subcatchments.size()); - for (auto sc : _subcatchments) - names.push_back(sc.name); + std::transform(_subcatchments.begin(), _subcatchments.end(), + std::back_inserter(names), + [](auto const& sc) { return sc.name; }); return names; } @@ -1306,8 +1309,7 @@ bool SwmmInterface::writeCsvForTimestep(std::string const& file_name, SwmmObject FileIO::CsvInterface csv; csv.addIndexVectorForWriting(getNumberOfObjects(obj_type)); csv.addVectorForWriting("Name", getNames(obj_type)); - std::vector<std::string> const obj_names (getNames(obj_type)); - std::size_t const n_params (getNumberOfParameters(obj_type)); + std::size_t const n_params(getNumberOfParameters(obj_type)); for (std::size_t i=0; i<n_params; ++i) { std::vector<double> data = getArrayAtTimeStep(obj_type, time_step, i); diff --git a/Applications/FileIO/TetGenInterface.cpp b/Applications/FileIO/TetGenInterface.cpp index 1548468abc65393c67d3d587dc7675cf18301e20..5e9afac09ba7813b7ab1d9225799418794d7e614 100644 --- a/Applications/FileIO/TetGenInterface.cpp +++ b/Applications/FileIO/TetGenInterface.cpp @@ -239,14 +239,7 @@ MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname, std::vector<MeshLib::Element*> elements; std::vector<int> materials; if (!readElementsFromStream (ins_ele, elements, materials, nodes)) { - // remove elements read until now - for (auto & element : elements) { - delete element; - } - // remove nodes - for (auto & node : nodes) { - delete node; - } + BaseLib::cleanupVectorElements(nodes, elements); return nullptr; } diff --git a/Applications/FileIO/XmlIO/Qt/XmlNumInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlNumInterface.cpp index 19dd30b492e05883ca068606b6249e20013d108b..5504345d67075e6cd7311af3e4da2d01939607bd 100644 --- a/Applications/FileIO/XmlIO/Qt/XmlNumInterface.cpp +++ b/Applications/FileIO/XmlIO/Qt/XmlNumInterface.cpp @@ -20,9 +20,6 @@ #include "BaseLib/Logging.h" -#include "BaseLib/FileFinder.h" - - namespace FileIO { XmlNumInterface::XmlNumInterface() : XMLQtInterface("OpenGeoSysNUM.xsd") {} diff --git a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp index 934e6cac4dbcd317664bc45c9da0a0efbdbfb2f5..c045fc06e1f1205da67f68e534c15bd087a73668 100644 --- a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp +++ b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp @@ -21,7 +21,6 @@ #include "Applications/DataExplorer/Base/OGSError.h" #include "Applications/DataHolderLib/FemCondition.h" -#include "BaseLib/FileFinder.h" #include "BaseLib/FileTools.h" #include "BaseLib/IO/Writer.h" diff --git a/Applications/Utils/FileConverter/TecPlotTools.cpp b/Applications/Utils/FileConverter/TecPlotTools.cpp index 5b060772147a22ad317e49ba776fcd632643f3d3..c0e06f37bdca758b9d0ebb4775265925eac11dd6 100644 --- a/Applications/Utils/FileConverter/TecPlotTools.cpp +++ b/Applications/Utils/FileConverter/TecPlotTools.cpp @@ -239,7 +239,7 @@ void skipGeometrySection(std::ifstream& in, std::string& line) } /// Splits a TecPlot file containing multiple sections/zones into separate files -int splitFile(std::ifstream& in, std::string file_name) +int splitFile(std::ifstream& in, std::string const& file_name) { std::ofstream out; std::string line; @@ -298,7 +298,7 @@ int splitFile(std::ifstream& in, std::string file_name) } /// Converts a TecPlot file into one or more OGS-meshes (one mesh per section/zone) -int convertFile(std::ifstream& in, std::string file_name) +int convertFile(std::ifstream& in, std::string const& file_name) { std::string line; std::string name; diff --git a/Applications/Utils/MeshEdit/moveMeshNodes.cpp b/Applications/Utils/MeshEdit/moveMeshNodes.cpp index 5a4bf10906771094b35da5fb494721612020e3e8..c5f3ef9d6c76e1d797998bffb9a785f5f9638cac 100644 --- a/Applications/Utils/MeshEdit/moveMeshNodes.cpp +++ b/Applications/Utils/MeshEdit/moveMeshNodes.cpp @@ -79,15 +79,9 @@ int main (int argc, char* argv[]) return EXIT_FAILURE; } - bool is_keyword(false); - for (auto& keyword : keywords) - { - if (current_key == keyword) - { - is_keyword = true; - break; - } - } + bool const is_keyword = std::any_of( + keywords.begin(), keywords.end(), + [current_key](auto const& keyword) { return current_key == keyword; }); if (!is_keyword) { diff --git a/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp b/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp index 976bfd26f949f5d06e8f5c7cbb79575c6634d314..180e7054dd51253d70c39b2e9fbe1cfb59968298 100644 --- a/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp +++ b/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp @@ -46,10 +46,7 @@ static bool parseNewOrder(std::string const& str_order, std::array<int, 3> &new_ return false; } - for (int& new_axes_indice : new_axes_indices) - { - new_axes_indice = -1; - } + new_axes_indices.fill(-1); for (int i=0; i<3; i++) { diff --git a/BaseLib/Algorithm.h b/BaseLib/Algorithm.h index 62a47c1dc849201021cf2e99b2de22784dc08a05..a01a42ad5e121dfa7d279906d5adf1f9bfb7ecb6 100644 --- a/BaseLib/Algorithm.h +++ b/BaseLib/Algorithm.h @@ -284,4 +284,20 @@ std::size_t findIndex(Container const& container, } return std::distance(container.begin(), it); } + +/** Util function to cleanup vectors */ +template <typename T1, typename T2> +void cleanupVectorElements(std::vector<T1*> const& items, + std::vector<T2*> const& dependent_items) +{ + for (auto dependent_item : dependent_items) + { + delete dependent_item; + } + for (auto item : items) + { + delete item; + } +} + } // namespace BaseLib diff --git a/BaseLib/FileFinder.cpp b/BaseLib/FileFinder.cpp deleted file mode 100644 index b714a0eeffbec6b7a73b07c606a7b77fc03f48d0..0000000000000000000000000000000000000000 --- a/BaseLib/FileFinder.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2010-10-26 - * \brief Definition of the FileFinder class. - * - * \copyright - * Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -#include "FileFinder.h" - -#include <fstream> - - -namespace BaseLib -{ - -FileFinder::FileFinder() -{ - addDirectory("."); -} - -FileFinder::FileFinder(std::initializer_list<std::string> dirs) -{ - addDirectory("."); - for (auto const& dir : dirs) - { - addDirectory(dir); - } -} - -void FileFinder::addDirectory(std::string const& dir) -{ - if (dir.empty()) - { - return; - } - - if (dir[dir.size() - 1] != '/') - { - _directories.emplace_back(dir + "/"); - } - else - { - _directories.push_back(dir); - } -} -} // namespace BaseLib diff --git a/BaseLib/FileFinder.h b/BaseLib/FileFinder.h deleted file mode 100644 index 841085a22ac803b8a980d9d9050ec90ee71c8b10..0000000000000000000000000000000000000000 --- a/BaseLib/FileFinder.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2010-10-26 - * \brief Definition of the FileFinder class. - * - * \copyright - * Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -#pragma once - -#include <initializer_list> -#include <string> -#include <vector> - - -namespace BaseLib -{ -/** - * FileFinder stores a list of directories and will return the complete path - * for a given filename if the corresponding file is found in any of these - * directories. - */ -class FileFinder final -{ -public: - /// Constructor having current directory (.) as the search-space - FileFinder(); - - /** - * Construct with the given directory paths in addition to current directory (.) - * - * @param dirs an initializer list of additional directory paths to the search-space - */ - FileFinder(std::initializer_list<std::string> dirs); - - /** - * \brief Adds another directory to the search-space. - * If the given directory does not end with a slash one will be appended. - */ - void addDirectory(std::string const& dir); - -private: - std::vector<std::string> _directories; -}; -} // end namespace BaseLib diff --git a/BaseLib/MemWatch.cpp b/BaseLib/MemWatch.cpp index 7804f1741ade9822f8c3a06886636424078bb9a2..37136a9d620cab48b471ea367b9f0e61716a08a9 100644 --- a/BaseLib/MemWatch.cpp +++ b/BaseLib/MemWatch.cpp @@ -49,15 +49,6 @@ unsigned MemWatch::updateMemUsage () in >> pages; _vmem_size = static_cast<unsigned long>(pages) * static_cast<unsigned long>(getpagesize()); - in >> pages; - _rmem_size =static_cast<unsigned long>(pages) * - static_cast<unsigned long>(getpagesize()); - in >> pages; - _smem_size = static_cast<unsigned long>(pages) * - static_cast<unsigned long>(getpagesize()); - in >> pages; - _cmem_size = static_cast<unsigned long>(pages) * - static_cast<unsigned long>(getpagesize()); in.close (); #endif @@ -70,20 +61,5 @@ unsigned long MemWatch::getVirtMemUsage () return _vmem_size; } -unsigned long MemWatch::getResMemUsage () { - updateMemUsage (); - return _rmem_size; -} - -unsigned long MemWatch::getShrMemUsage () { - updateMemUsage (); - return _smem_size; -} - -unsigned long MemWatch::getCodeMemUsage () { - updateMemUsage (); - return _cmem_size; -} - } // end namespace BaseLib diff --git a/BaseLib/MemWatch.h b/BaseLib/MemWatch.h index dac84bb37d75eafcf46d75ec38bfba2167657e16..4a781309bc367949847eca8abc60fd8334ea3d11 100644 --- a/BaseLib/MemWatch.h +++ b/BaseLib/MemWatch.h @@ -20,16 +20,10 @@ class MemWatch { public: MemWatch (); unsigned long getVirtMemUsage (); - unsigned long getResMemUsage (); - unsigned long getShrMemUsage (); - unsigned long getCodeMemUsage (); private: unsigned updateMemUsage (); unsigned long _vmem_size = 0; - unsigned long _rmem_size = 0; - unsigned long _smem_size = 0; - unsigned long _cmem_size = 0; }; } // namespace BaseLib diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index 2fb60f12740adf53c3f7cb7a1f278ba2e6fd661a..0f01711e2e15a477909d14e6f639f140c6241f4c 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -528,8 +528,7 @@ std::vector<MathLib::Point3d> lineSegmentIntersect2d( mat(0,1) = c[0]-d[0]; mat(1,0) = b[1]-a[1]; mat(1,1) = c[1]-d[1]; - Eigen::Vector2d rhs; - rhs << c[0] - a[0], c[1] - a[1]; + Eigen::Vector2d rhs{c[0] - a[0], c[1] - a[1]}; rhs = mat.partialPivLu().solve(rhs); if (0 <= rhs[1] && rhs[1] <= 1.0) { diff --git a/GeoLib/GEOObjects.cpp b/GeoLib/GEOObjects.cpp index 0bb1ff59ce1f64b11987df2015f7973a094e5e48..39cc9cf110fb1832469bd1dbe4a18d130a3012b6 100644 --- a/GeoLib/GEOObjects.cpp +++ b/GeoLib/GEOObjects.cpp @@ -508,8 +508,9 @@ bool GEOObjects::mergePoints(std::vector<std::string> const & geo_names, return true; } -void GEOObjects::mergePolylines(std::vector<std::string> const & geo_names, - std::string & merged_geo_name, std::vector<std::size_t> const& pnt_offsets) +void GEOObjects::mergePolylines(std::vector<std::string> const& geo_names, + std::string const& merged_geo_name, + std::vector<std::size_t> const& pnt_offsets) { const std::size_t n_geo_names(geo_names.size()); std::vector<std::size_t> ply_offsets(n_geo_names, 0); @@ -551,8 +552,9 @@ void GEOObjects::mergePolylines(std::vector<std::string> const & geo_names, } } -void GEOObjects::mergeSurfaces(std::vector<std::string> const & geo_names, - std::string & merged_geo_name, std::vector<std::size_t> const& pnt_offsets) +void GEOObjects::mergeSurfaces(std::vector<std::string> const& geo_names, + std::string const& merged_geo_name, + std::vector<std::size_t> const& pnt_offsets) { std::vector<GeoLib::Point*> const* merged_points(this->getPointVecObj(merged_geo_name)->getVector()); std::vector<std::size_t> const& id_map (this->getPointVecObj(merged_geo_name)->getIDMap ()); diff --git a/GeoLib/GEOObjects.h b/GeoLib/GEOObjects.h index 2c243f1e6ccfe10781c17e8737d873b74e63f950..599e38efd0f50f11babad1e2e08d55435df04ec8 100644 --- a/GeoLib/GEOObjects.h +++ b/GeoLib/GEOObjects.h @@ -339,8 +339,9 @@ private: * @param pnt_offsets offsets in the merged vector storing the points * @return true, if merging the points succeeded, else false */ - bool mergePoints(std::vector<std::string> const & geo_names, std::string & merged_geo_name, - std::vector<std::size_t> &pnt_offsets); + bool mergePoints(std::vector<std::string> const& geo_names, + std::string& merged_geo_name, + std::vector<std::size_t>& pnt_offsets); /** * Method merges GeoLib::Polylines from different geometries into one @@ -354,8 +355,9 @@ private: * merging. * @param pnt_offsets offsets in the merged vector storing the points. */ - void mergePolylines(std::vector<std::string> const & geo_names, std::string & merged_geo_name, - std::vector<std::size_t> const& pnt_offsets); + void mergePolylines(std::vector<std::string> const& geo_names, + std::string const& merged_geo_name, + std::vector<std::size_t> const& pnt_offsets); /** * Method merges GeoLib::Surfaces from different geometries into one @@ -367,8 +369,9 @@ private: * merging. * @param pnt_offsets offsets in the merged vector storing the points. */ - void mergeSurfaces(std::vector<std::string> const & geo_names, - std::string & merged_geo_name, std::vector<std::size_t> const& pnt_offsets); + void mergeSurfaces(std::vector<std::string> const& geo_names, + std::string const& merged_geo_name, + std::vector<std::size_t> const& pnt_offsets); void markUnusedPoints(std::string const& geo_name, std::vector<bool>& transfer_pnts) const; diff --git a/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp index a60c76464c12818046c3f9888362c032417ea8c4..9da3649c558580ae888ed941fdef8eb3f98cbe43 100644 --- a/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp +++ b/GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp @@ -20,7 +20,6 @@ #include "BaseLib/Logging.h" -#include "BaseLib/FileFinder.h" #include "GeoLib/Triangle.h" namespace diff --git a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp index fbb61d358df7254c0c5260add2eb2d15c29a6ba0..465c4cf1fa0e0700a8bc4b8c365aa4527948f279 100644 --- a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp +++ b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp @@ -23,7 +23,6 @@ #include "BaseLib/DateTools.h" #include "BaseLib/FileTools.h" -#include "BaseLib/FileFinder.h" #include "GeoLib/StationBorehole.h" #include "GeoLib/GEOObjects.h" @@ -250,8 +249,8 @@ bool XmlStnInterface::write() root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); const std::vector<GeoLib::Point*>* stations (_geo_objs.getStationVec(_exportName)); - bool isBorehole = static_cast<GeoLib::Station*>((*stations)[0])->type() == - GeoLib::Station::StationType::BOREHOLE; + bool const is_borehole = static_cast<GeoLib::Station*>((*stations)[0])->type() == + GeoLib::Station::StationType::BOREHOLE; doc.appendChild(root); QDomElement stationListTag = doc.createElement("stationlist"); @@ -261,7 +260,7 @@ bool XmlStnInterface::write() stationListTag.appendChild(listNameTag); QDomText stationListNameText = doc.createTextNode(QString::fromStdString(_exportName)); listNameTag.appendChild(stationListNameText); - QString listType = (isBorehole) ? "boreholes" : "stations"; + QString listType = is_borehole ? "boreholes" : "stations"; QDomElement stationsTag = doc.createElement(listType); stationListTag.appendChild(stationsTag); @@ -280,7 +279,7 @@ bool XmlStnInterface::write() for (std::size_t i = 0; i < nStations; i++) { - QString stationType = (isBorehole) ? "borehole" : "station"; + QString stationType = is_borehole ? "borehole" : "station"; QDomElement stationTag = doc.createElement(stationType); stationTag.setAttribute( "id", QString::number(i) ); stationTag.setAttribute( "x", QString::number((*(*stations)[i])[0], 'f', @@ -306,7 +305,7 @@ bool XmlStnInterface::write() stationValueTag.appendChild(stationValueText); } - if (isBorehole) + if (is_borehole) { writeBoreholeData( doc, stationTag, diff --git a/GeoLib/OctTree-impl.h b/GeoLib/OctTree-impl.h index f112e7f6723fc374d6db897b3c1af2700b316ea8..d7d975de366b33e10fffa1501de548ff27f5ae65 100644 --- a/GeoLib/OctTree-impl.h +++ b/GeoLib/OctTree-impl.h @@ -128,13 +128,12 @@ void OctTree<POINT, MAX_POINTS>::getPointsInRange(T const& min, T const& max, } if (_is_leaf) { - for (auto p : _pnts) { - if (min[0] <= (*p)[0] && (*p)[0] < max[0] && min[1] <= (*p)[1] && - (*p)[1] < max[1] && min[2] <= (*p)[2] && (*p)[2] < max[2]) - { - pnts.push_back(p); - } - } + std::copy_if(_pnts.begin(), _pnts.end(), std::back_inserter(pnts), + [&min, &max](auto const* p) { + return (min[0] <= (*p)[0] && (*p)[0] < max[0] && + min[1] <= (*p)[1] && (*p)[1] < max[1] && + min[2] <= (*p)[2] && (*p)[2] < max[2]); + }); } else { for (std::size_t k(0); k<8; k++) { _children[k]->getPointsInRange(min, max, pnts); diff --git a/GeoLib/Polygon.cpp b/GeoLib/Polygon.cpp index 7c01731b3028f2ce061a786af8161befbea62cdd..b02580b6d2a73c33ea013caf3a0e6257e6e5e00d 100644 --- a/GeoLib/Polygon.cpp +++ b/GeoLib/Polygon.cpp @@ -213,30 +213,33 @@ bool Polygon::containsSegment(GeoLib::LineSegment const& segment) const bool Polygon::isPolylineInPolygon(const Polyline& ply) const { - for (auto segment : ply) { - if (!containsSegment(segment)) { - return false; - } - } - return true; + return std::all_of(ply.begin(), ply.end(), [this](auto const& segment) { + return containsSegment(segment); + }); } bool Polygon::isPartOfPolylineInPolygon(const Polyline& ply) const { const std::size_t ply_size (ply.getNumberOfPoints()); // check points - for (std::size_t k(0); k < ply_size; k++) { - if (isPntInPolygon (*(ply.getPoint(k)))) { + for (std::size_t k(0); k < ply_size; k++) + { + if (isPntInPolygon(*(ply.getPoint(k)))) + { return true; } } GeoLib::Point s; - for (auto polygon_seg : *this) { - for (auto polyline_seg : ply) { - if (GeoLib::lineSegmentIntersect(polyline_seg, polygon_seg, s)) { - return true; - } + for (auto polygon_seg : *this) + { + if (std::any_of(ply.begin(), ply.end(), + [&polygon_seg, &s](auto const& polyline_seg) { + return GeoLib::lineSegmentIntersect(polyline_seg, + polygon_seg, s); + })) + { + return true; } } diff --git a/MeshLib/MeshSearch/ElementSearch.h b/MeshLib/MeshSearch/ElementSearch.h index e958074b8b27e0db5f59d9154ec8c321e34baaa1..ab9608c528812bbe0b80b5a82a63fecea4008a5f 100644 --- a/MeshLib/MeshSearch/ElementSearch.h +++ b/MeshLib/MeshSearch/ElementSearch.h @@ -62,7 +62,7 @@ public: /// element not to be marked /// @param max_property_value maximum value of the given property for the /// element not to be marked - /// @param outside_of if true, all values outside of the given range or + /// @param outside_of if true, all values outside of the given range are /// marked, if false, all values inside the given range are marked /// @return The number of marked elements will be returned. The concrete /// element ids can be requested by getSearchedElementIDs().