diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index 91295bc97c..eeaaaceb8f 100644 --- a/src/apps/proj.cpp +++ b/src/apps/proj.cpp @@ -536,6 +536,7 @@ int main(int argc, char **argv) { eargv++; eargc--; // logic copied from proj_factors function + // coverity[tainted_data] if (PJ *P = proj_create(nullptr, ocrs.c_str())) { auto type = proj_get_type(P); auto ctx = P->ctx; @@ -555,7 +556,7 @@ int main(int argc, char **argv) { try { auto crs = dynamic_cast( P->iso_obj.get()); - auto& dir = + auto &dir = crs->coordinateSystem()->axisList()[0]->direction(); swapAxisCrs = dir == NS_PROJ::cs::AxisDirection::NORTH || dir == NS_PROJ::cs::AxisDirection::SOUTH; diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index f1d5ed401f..9681324c2b 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -467,7 +467,7 @@ static void outputObject( std::cout << std::endl; } - auto projStringExportable = + const auto projStringExportable = nn_dynamic_pointer_cast(obj); bool alreadyOutputted = false; if (projStringExportable) { @@ -769,7 +769,7 @@ static void outputOperationSummary( std::cout << ", "; - auto name = op->nameStr(); + const auto &name = op->nameStr(); if (!name.empty()) { std::cout << name; } else { @@ -778,7 +778,7 @@ static void outputOperationSummary( std::cout << ", "; - auto accuracies = op->coordinateOperationAccuracies(); + const auto &accuracies = op->coordinateOperationAccuracies(); if (!accuracies.empty()) { std::cout << accuracies[0]->value() << " m"; } else { @@ -791,7 +791,7 @@ static void outputOperationSummary( std::cout << ", "; - auto domains = op->domains(); + const auto &domains = op->domains(); if (!domains.empty() && domains[0]->domainOfValidity() && domains[0]->domainOfValidity()->description().has_value()) { std::cout << *(domains[0]->domainOfValidity()->description()); @@ -805,7 +805,7 @@ static void outputOperationSummary( if (dbContext && getenv("PROJINFO_NO_GRID_CHECK") == nullptr) { try { - auto setGrids = op->gridsNeeded(dbContext, false); + const auto setGrids = op->gridsNeeded(dbContext, false); for (const auto &grid : setGrids) { if (!grid.available) { std::cout << ", at least one grid missing"; @@ -841,7 +841,7 @@ static bool is3DCRS(const CRSPtr &crs) { // --------------------------------------------------------------------------- static void outputOperations( - DatabaseContextPtr dbContext, const std::string &sourceCRSStr, + const DatabaseContextPtr &dbContext, const std::string &sourceCRSStr, const std::string &sourceEpoch, const std::string &targetCRSStr, const std::string &targetEpoch, const ExtentPtr &bboxFilter, CoordinateOperationContext::SpatialCriterion spatialCriterion, @@ -907,7 +907,7 @@ static void outputOperations( auto promoted = sourceCRS->promoteTo3D(std::string(), dbContext).as_nullable(); if (!promoted->identifiers().empty()) { - sourceCRS = promoted; + sourceCRS = std::move(promoted); } } else if (is3DCRS(sourceCRS) && !is3DCRS(targetCRS) && !targetCRS->identifiers().empty() && @@ -916,7 +916,7 @@ static void outputOperations( auto promoted = targetCRS->promoteTo3D(std::string(), dbContext).as_nullable(); if (!promoted->identifiers().empty()) { - targetCRS = promoted; + targetCRS = std::move(promoted); } } } @@ -1078,7 +1078,7 @@ int main(int argc, char **argv) { bool listCRSSpecified = false; for (int i = 1; i < argc; i++) { - std::string arg(argv[i]); + const std::string arg(argv[i]); if (arg == "-o" && i + 1 < argc) { outputSwitchSpecified = true; i++; diff --git a/src/filemanager.cpp b/src/filemanager.cpp index 3ea3ad6e47..c6c646ea01 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -1203,7 +1203,7 @@ const char *proj_context_get_user_writable_directory(PJ_CONTEXT *ctx, } #endif path += "/proj"; - ctx->user_writable_directory = path; + ctx->user_writable_directory = std::move(path); } if (create != FALSE) { CreateDirectoryRecursively(ctx, ctx->user_writable_directory); @@ -1655,7 +1655,7 @@ NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name, auto dbContext = getDBcontext(ctx); if (dbContext) { try { - auto filename = dbContext->getProjGridName(name); + const auto filename = dbContext->getProjGridName(name); if (!filename.empty()) { file.reset(reinterpret_cast( pj_open_lib_internal(ctx, filename.c_str(), "rb", @@ -1686,7 +1686,7 @@ NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name, auto dbContext = getDBcontext(ctx); if (dbContext) { try { - auto filename = dbContext->getOldProjGridName(name); + const auto filename = dbContext->getOldProjGridName(name); if (!filename.empty()) { file.reset(reinterpret_cast( pj_open_lib_internal(ctx, filename.c_str(), "rb", diff --git a/src/grids.cpp b/src/grids.cpp index fac25a6758..e9ae9649cb 100644 --- a/src/grids.cpp +++ b/src/grids.cpp @@ -1613,7 +1613,7 @@ VerticalShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) { if (!fp) { return nullptr; } - const auto actualName(fp->name()); + const auto &actualName(fp->name()); if (ends_with(actualName, "gtx") || ends_with(actualName, "GTX")) { auto grid = GTXVerticalShiftGrid::open(ctx, std::move(fp), actualName); if (!grid) { @@ -2657,7 +2657,7 @@ HorizontalShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) { if (!fp) { return nullptr; } - const auto actualName(fp->name()); + const auto &actualName(fp->name()); char header[160]; /* -------------------------------------------------------------------- */ @@ -3086,7 +3086,6 @@ GenericShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) { if (!fp) { return nullptr; } - const auto actualName(fp->name()); /* -------------------------------------------------------------------- */ /* Load a header, to determine the file type. */ @@ -3100,6 +3099,7 @@ GenericShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) { if (IsTIFF(header_size, header)) { #ifdef TIFF_ENABLED + const std::string actualName(fp->name()); auto set = std::unique_ptr( GTiffGenericGridShiftSet::open(ctx, std::move(fp), actualName)); if (!set) diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index 1ec48bd3b8..cc73b8f92d 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -197,7 +197,7 @@ PJ *pj_obj_create(PJ_CONTEXT *ctx, const BaseObjectNNPtr &objIn) { auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); try { auto formatter = PROJStringFormatter::create( - PROJStringFormatter::Convention::PROJ_5, dbContext); + PROJStringFormatter::Convention::PROJ_5, std::move(dbContext)); auto projString = coordop->exportToPROJString(formatter.get()); if (proj_context_is_network_enabled(ctx)) { ctx->defer_grid_opening = true; @@ -380,7 +380,7 @@ const char *proj_context_get_database_path(PJ_CONTEXT *ctx) { try { // temporary variable must be used as getDBcontext() might create // ctx->cpp_context - auto osPath(getDBcontext(ctx)->getPath()); + const auto osPath(getDBcontext(ctx)->getPath()); ctx->get_cpp_context()->lastDbPath_ = osPath; return ctx->cpp_context->lastDbPath_.c_str(); } catch (const std::exception &e) { @@ -1629,7 +1629,7 @@ const char *proj_as_wkt(PJ_CONTEXT *ctx, const PJ *obj, PJ_WKT_TYPE type, try { auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); - auto formatter = WKTFormatter::create(convention, dbContext); + auto formatter = WKTFormatter::create(convention, std::move(dbContext)); for (auto iter = options; iter && iter[0]; ++iter) { const char *value; if ((value = getOptionValue(*iter, "MULTILINE="))) { @@ -1735,7 +1735,8 @@ const char *proj_as_proj_string(PJ_CONTEXT *ctx, const PJ *obj, static_cast(type); auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); try { - auto formatter = PROJStringFormatter::create(convention, dbContext); + auto formatter = + PROJStringFormatter::create(convention, std::move(dbContext)); for (auto iter = options; iter && iter[0]; ++iter) { const char *value; if ((value = getOptionValue(*iter, "MULTILINE="))) { @@ -1807,7 +1808,7 @@ const char *proj_as_projjson(PJ_CONTEXT *ctx, const PJ *obj, auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); try { - auto formatter = JSONFormatter::create(dbContext); + auto formatter = JSONFormatter::create(std::move(dbContext)); for (auto iter = options; iter && iter[0]; ++iter) { const char *value; if ((value = getOptionValue(*iter, "MULTILINE="))) { @@ -4681,12 +4682,13 @@ static CoordinateSystemAxisNNPtr createAxis(const PJ_AXIS_DESCRIPTION &axis) { unit_type = UnitOfMeasure::Type::PARAMETRIC; break; } - auto unit = axis.unit_type == PJ_UT_ANGULAR - ? createAngularUnit(axis.unit_name, axis.unit_conv_factor) - : axis.unit_type == PJ_UT_LINEAR - ? createLinearUnit(axis.unit_name, axis.unit_conv_factor) - : UnitOfMeasure(axis.unit_name ? axis.unit_name : "unnamed", - axis.unit_conv_factor, unit_type); + const common::UnitOfMeasure unit( + axis.unit_type == PJ_UT_ANGULAR + ? createAngularUnit(axis.unit_name, axis.unit_conv_factor) + : axis.unit_type == PJ_UT_LINEAR + ? createLinearUnit(axis.unit_name, axis.unit_conv_factor) + : UnitOfMeasure(axis.unit_name ? axis.unit_name : "unnamed", + axis.unit_conv_factor, unit_type)); return CoordinateSystemAxis::create( createPropertyMapName(axis.name), diff --git a/src/iso19111/coordinatesystem.cpp b/src/iso19111/coordinatesystem.cpp index f8c455ddfe..15a0ba6010 100644 --- a/src/iso19111/coordinatesystem.cpp +++ b/src/iso19111/coordinatesystem.cpp @@ -392,7 +392,7 @@ void CoordinateSystemAxis::_exportToWKT(io::WKTFormatter *formatter, int order, formatter->startNode(io::WKTConstants::AXIS, !identifiers().empty()); const std::string &axisName = nameStr(); const std::string &abbrev = abbreviation(); - std::string parenthesizedAbbrev = "(" + abbrev + ")"; + const std::string parenthesizedAbbrev = "(" + abbrev + ")"; std::string dir = direction().toString(); std::string axisDesignation; diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index 9d04844961..f391c86fe6 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -537,7 +537,7 @@ CRSNNPtr CRS::createBoundCRSToWGS84IfPossible( dbContext, allowIntermediateCRSUse); if (horiz.get() != comps[0].get() || vert.get() != comps[1].get()) { return CompoundCRS::create(createPropertyMap(this), - {horiz, vert}); + {std::move(horiz), std::move(vert)}); } } return thisAsCRS; @@ -1012,7 +1012,7 @@ void CRS::setProperties( ObjectUsage::setProperties(newProperties); - d->extensionProj4_ = extensionProj4; + d->extensionProj4_ = std::move(extensionProj4); } //! @endcond @@ -1357,7 +1357,7 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, return util::nn_static_pointer_cast( DerivedGeographicCRS::create( createProperties(), NN_CHECK_THROW(baseGeog3DCRS), - derivedGeogCRS->derivingConversion(), cs)); + derivedGeogCRS->derivingConversion(), std::move(cs))); } } @@ -1374,7 +1374,7 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, return util::nn_static_pointer_cast( DerivedProjectedCRS::create( createProperties(), NN_CHECK_THROW(baseProj3DCRS), - derivedProjCRS->derivingConversion(), cs)); + derivedProjCRS->derivingConversion(), std::move(cs))); } } @@ -1414,7 +1414,7 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, verticalAxisIfNotAlreadyPresent); return util::nn_static_pointer_cast( GeographicCRS::create(createProperties(), geogCRS->datum(), - geogCRS->datumEnsemble(), cs)); + geogCRS->datumEnsemble(), std::move(cs))); } } @@ -1430,7 +1430,7 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, createProperties(), NN_NO_CHECK( util::nn_dynamic_pointer_cast(base3DCRS)), - projCRS->derivingConversion(), cs)); + projCRS->derivingConversion(), std::move(cs))); } } @@ -1445,7 +1445,8 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, boundCRS->hubCRS()->promoteTo3D(std::string(), dbContext), transf->promoteTo3D(std::string(), dbContext)); } catch (const io::FormattingException &) { - return BoundCRS::create(base3DCRS, boundCRS->hubCRS(), transf); + return BoundCRS::create(base3DCRS, boundCRS->hubCRS(), + std::move(transf)); } } @@ -2041,7 +2042,7 @@ static bool exportAsESRIWktCompoundCRSWithEllipsoidalHeight( assert(axisList.size() == 3U); formatter->startNode(io::WKTConstants::VERTCS, false); - auto vertcs_name = l_esri_name; + auto vertcs_name = std::move(l_esri_name); if (starts_with(vertcs_name.c_str(), "GCS_")) vertcs_name = vertcs_name.substr(4); formatter->addQuotedString(vertcs_name); @@ -2107,7 +2108,7 @@ void GeodeticCRS::_exportToWKT(io::WKTFormatter *formatter) const { const auto &axisList = cs->axisList(); const bool isGeographic3D = isGeographic && axisList.size() == 3; const auto oldAxisOutputRule = formatter->outputAxis(); - auto l_name = nameStr(); + std::string l_name = nameStr(); const auto &dbContext = formatter->databaseContext(); const bool isESRIExport = !isWKT2 && formatter->useESRIDialect(); @@ -2152,7 +2153,8 @@ void GeodeticCRS::_exportToWKT(io::WKTFormatter *formatter) const { formatter->startNode(io::WKTConstants::COMPD_CS, false); formatter->addQuotedString(l_name + " + " + l_name); geogCRS2D->_exportToWKT(formatter); - const auto oldTOWGSParameters = formatter->getTOWGS84Parameters(); + const std::vector oldTOWGSParameters( + formatter->getTOWGS84Parameters()); formatter->setTOWGS84Parameters({}); geogCRS2D->_exportToWKT(formatter); formatter->setTOWGS84Parameters(oldTOWGSParameters); @@ -2233,7 +2235,8 @@ void GeodeticCRS::_exportToWKT(io::WKTFormatter *formatter) const { } } } - l_name = l_esri_name; + const std::string &l_esri_name_ref(l_esri_name); + l_name = l_esri_name_ref; } else if (!isWKT2 && isDeprecated()) { l_name += " (deprecated)"; } @@ -2483,7 +2486,7 @@ void GeodeticCRS::_exportToJSONInternal( formatter->MakeObjectContext(objectName, !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -2744,11 +2747,11 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { &geodetic_crs_type, l_implicitCS, &dbContext]() { const auto &thisEllipsoid = thisDatum->ellipsoid(); - const auto ellipsoids = + const auto ellipsoids( thisEllipsoid->identifiers().empty() ? authorityFactory->createEllipsoidFromExisting( thisEllipsoid) - : std::list{thisEllipsoid}; + : std::list{thisEllipsoid}); for (const auto &ellps : ellipsoids) { for (const auto &id : ellps->identifiers()) { try { @@ -3505,7 +3508,7 @@ void VerticalCRS::_exportToWKT(io::WKTFormatter *formatter) const { : io::WKTConstants::VERT_CS, !identifiers().empty()); - auto l_name = nameStr(); + std::string l_name(nameStr()); const auto &dbContext = formatter->databaseContext(); if (formatter->useESRIDialect()) { bool aliasFound = false; @@ -3513,7 +3516,7 @@ void VerticalCRS::_exportToWKT(io::WKTFormatter *formatter) const { auto l_alias = dbContext->getAliasFromOfficialName( l_name, "vertical_crs", "ESRI"); if (!l_alias.empty()) { - l_name = l_alias; + l_name = std::move(l_alias); aliasFound = true; } } @@ -3645,7 +3648,7 @@ void VerticalCRS::_exportToJSON( formatter->MakeObjectContext("VerticalCRS", !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -4113,7 +4116,7 @@ void DerivedCRS::_exportToJSON( formatter->MakeObjectContext(className(), !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -4214,7 +4217,7 @@ void ProjectedCRS::_exportToWKT(io::WKTFormatter *formatter) const { // perfectly matches the database definition const auto &dbContext = formatter->databaseContext(); - auto l_name = nameStr(); + std::string l_name(nameStr()); const auto &l_coordinateSystem = d->coordinateSystem(); const auto &axisList = l_coordinateSystem->axisList(); if (axisList.size() == 3 && !(isWKT2 && formatter->use2019Keywords())) { @@ -4413,7 +4416,8 @@ void ProjectedCRS::_exportToWKT(io::WKTFormatter *formatter) const { if (l_esri_name.empty()) { l_name = io::WKTFormatter::morphNameToESRI(l_name); } else { - l_name = l_esri_name; + const std::string &l_esri_name_ref(l_esri_name); + l_name = l_esri_name_ref; } } if (!isWKT2 && !formatter->useESRIDialect() && isDeprecated()) { @@ -4500,7 +4504,7 @@ void ProjectedCRS::_exportToJSON( formatter->MakeObjectContext("ProjectedCRS", !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -4854,7 +4858,7 @@ ProjectedCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { const bool l_implicitCS = hasImplicitCS(); const auto addCRS = [&](const ProjectedCRSNNPtr &crs, const bool eqName, - bool hasNonMatchingId) { + bool hasNonMatchingId) -> Pair { const auto &l_unit = cs->axisList()[0]->unit(); if ((_isEquivalentTo(crs.get(), util::IComparable::Criterion:: @@ -5382,7 +5386,7 @@ void CompoundCRS::_exportToJSON( formatter->MakeObjectContext("CompoundCRS", !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -6568,7 +6572,7 @@ DerivedGeographicCRSNNPtr DerivedGeographicCRS::demoteTo2D( return DerivedGeographicCRS::create( util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, !newName.empty() ? newName : nameStr()), - NN_CHECK_THROW(baseGeog2DCRS), derivingConversion(), cs); + NN_CHECK_THROW(baseGeog2DCRS), derivingConversion(), std::move(cs)); } return NN_NO_CHECK(std::dynamic_pointer_cast( @@ -6683,7 +6687,7 @@ DerivedProjectedCRS::demoteTo2D(const std::string &newName, return DerivedProjectedCRS::create( util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, !newName.empty() ? newName : nameStr()), - NN_CHECK_THROW(baseProj2DCRS), derivingConversion(), cs); + NN_CHECK_THROW(baseProj2DCRS), derivingConversion(), std::move(cs)); } return NN_NO_CHECK(std::dynamic_pointer_cast( @@ -6866,7 +6870,7 @@ void TemporalCRS::_exportToJSON( formatter->MakeObjectContext("TemporalCRS", !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -6998,7 +7002,7 @@ void EngineeringCRS::_exportToJSON( formatter->MakeObjectContext("EngineeringCRS", !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -7176,7 +7180,7 @@ void ParametricCRS::_exportToJSON( formatter->MakeObjectContext("ParametricCRS", !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { diff --git a/src/iso19111/datum.cpp b/src/iso19111/datum.cpp index 91b5b8468d..dd0e79b9e9 100644 --- a/src/iso19111/datum.cpp +++ b/src/iso19111/datum.cpp @@ -405,8 +405,8 @@ void PrimeMeridian::_exportToWKT( io::WKTFormatter *formatter) const // throw(FormattingException) { const bool isWKT2 = formatter->version() == io::WKTFormatter::Version::WKT2; - std::string l_name = - name()->description().has_value() ? nameStr() : "Greenwich"; + std::string l_name(name()->description().has_value() ? nameStr() + : "Greenwich"); if (!(isWKT2 && formatter->primeMeridianOmittedIfGreenwich() && l_name == "Greenwich")) { formatter->startNode(io::WKTConstants::PRIMEM, !identifiers().empty()); @@ -418,7 +418,7 @@ void PrimeMeridian::_exportToWKT( auto l_alias = dbContext->getAliasFromOfficialName( l_name, "prime_meridian", "ESRI"); if (!l_alias.empty()) { - l_name = l_alias; + l_name = std::move(l_alias); aliasFound = true; } } @@ -873,7 +873,7 @@ void Ellipsoid::_exportToWKT( : io::WKTConstants::SPHEROID, !identifiers().empty()); { - auto l_name = nameStr(); + std::string l_name(nameStr()); if (l_name.empty()) { formatter->addQuotedString("unnamed"); } else { @@ -887,7 +887,7 @@ void Ellipsoid::_exportToWKT( auto l_alias = dbContext->getAliasFromOfficialName( l_name, "ellipsoid", "ESRI"); if (!l_alias.empty()) { - l_name = l_alias; + l_name = std::move(l_alias); aliasFound = true; } } @@ -941,7 +941,7 @@ void Ellipsoid::_exportToJSON( formatter->MakeObjectContext("Ellipsoid", !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -1334,7 +1334,7 @@ void GeodeticReferenceFrame::_exportToWKT( const bool isWKT2 = formatter->version() == io::WKTFormatter::Version::WKT2; const auto &ids = identifiers(); formatter->startNode(io::WKTConstants::DATUM, !ids.empty()); - auto l_name = nameStr(); + std::string l_name(nameStr()); if (l_name.empty()) { l_name = "unnamed"; } @@ -1356,7 +1356,7 @@ void GeodeticReferenceFrame::_exportToWKT( l_alias = dbContext->getAliasFromOfficialName( l_name.substr(0, pos), "geodetic_datum", "ESRI"); if (!l_alias.empty()) { - l_name = l_alias; + l_name = std::move(l_alias); aliasFound = true; } } @@ -1469,7 +1469,7 @@ void GeodeticReferenceFrame::_exportToJSON( auto writer = formatter->writer(); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -1935,7 +1935,7 @@ void DatumEnsemble::_exportToJSON( auto writer = formatter->writer(); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -2148,7 +2148,7 @@ void VerticalReferenceFrame::_exportToWKT( ? io::WKTConstants::VDATUM : io::WKTConstants::VERT_DATUM, !identifiers().empty()); - auto l_name = nameStr(); + std::string l_name(nameStr()); if (!l_name.empty()) { if (!isWKT2 && formatter->useESRIDialect()) { bool aliasFound = false; @@ -2157,7 +2157,7 @@ void VerticalReferenceFrame::_exportToWKT( auto l_alias = dbContext->getAliasFromOfficialName( l_name, "vertical_datum", "ESRI"); if (!l_alias.empty()) { - l_name = l_alias; + l_name = std::move(l_alias); aliasFound = true; } } @@ -2217,7 +2217,7 @@ void VerticalReferenceFrame::_exportToJSON( auto writer = formatter->writer(); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 5115030cce..21070a3c0d 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -392,7 +392,7 @@ SQLResultSet SQLiteHandle::run(sqlite3_stmt *stmt, const std::string &sql, for (const auto ¶m : parameters) { const auto ¶mType = param.type(); if (paramType == SQLValues::Type::STRING) { - auto strValue = param.stringValue(); + const auto &strValue = param.stringValue(); sqlite3_bind_text(stmt, nBindField, strValue.c_str(), static_cast(strValue.size()), SQLITE_TRANSIENT); @@ -1199,7 +1199,7 @@ void DatabaseContext::Private::open(const std::string &databasePath, sqlite_handle_ = SQLiteHandleCache::get().getHandle(path, ctx); - databasePath_ = path; + databasePath_ = std::move(path); } // --------------------------------------------------------------------------- @@ -1253,7 +1253,7 @@ void DatabaseContext::Private::attachExtraDatabases( "AND name NOT LIKE 'sqlite_stat%'"); std::map> tableStructure; for (const auto &rowTable : tables) { - auto tableName = rowTable[0]; + const auto &tableName = rowTable[0]; auto tableInfo = run("PRAGMA table_info(\"" + replaceAll(tableName, "\"", "\"\"") + "\")"); for (const auto &rowCol : tableInfo) { @@ -1451,7 +1451,7 @@ static void identifyFromNameOrCode( for (const auto &id : obj->identifiers()) { try { - const auto idAuthName = *(id->codeSpace()); + const auto &idAuthName = *(id->codeSpace()); if (std::find(allowedAuthoritiesTmp.begin(), allowedAuthoritiesTmp.end(), idAuthName) != allowedAuthoritiesTmp.end()) { @@ -2885,7 +2885,7 @@ DatabaseContext::create(const std::string &databasePath, } if (!auxDbs.empty()) { dbCtxPrivate->attachExtraDatabases(auxDbs); - dbCtxPrivate->auxiliaryDatabasePaths_ = auxDbs; + dbCtxPrivate->auxiliaryDatabasePaths_ = std::move(auxDbs); } dbCtxPrivate->self_ = dbCtx.as_nullable(); return dbCtx; @@ -3341,7 +3341,7 @@ bool DatabaseContext::lookForGridInfo( fullFilenameNewName.resize(strlen(fullFilenameNewName.c_str())); if (gridAvailableWithNewName) { gridAvailable = true; - fullFilename = fullFilenameNewName; + fullFilename = std::move(fullFilenameNewName); } } @@ -5548,7 +5548,8 @@ AuthorityFactory::createCompoundCRS(const std::string &code) const { auto props = d->createPropertiesSearchUsages("compound_crs", code, name, deprecated); return crs::CompoundCRS::create( - props, std::vector{horizCRS, vertCRS}); + props, std::vector{std::move(horizCRS), + std::move(vertCRS)}); } catch (const std::exception &ex) { throw buildFactoryException("compoundCRS", d->authority(), code, ex); } @@ -7347,7 +7348,7 @@ AuthorityFactory::createFromCRSCodesWithIntermediates( listTmp.emplace_back( operation::ConcatenatedOperation::createComputeMetadata( - {op1, op2}, false)); + {std::move(op1), std::move(op2)}, false)); } catch (const std::exception &e) { // Mostly for debugging purposes when using an inconsistent // database @@ -7403,7 +7404,7 @@ AuthorityFactory::createFromCRSCodesWithIntermediates( listTmp.emplace_back( operation::ConcatenatedOperation::createComputeMetadata( - {op1, op2->inverse()}, false)); + {std::move(op1), op2->inverse()}, false)); } catch (const std::exception &e) { // Mostly for debugging purposes when using an inconsistent // database @@ -7480,7 +7481,7 @@ AuthorityFactory::createFromCRSCodesWithIntermediates( listTmp.emplace_back( operation::ConcatenatedOperation::createComputeMetadata( - {op1->inverse(), op2}, false)); + {op1->inverse(), std::move(op2)}, false)); } catch (const std::exception &e) { // Mostly for debugging purposes when using an inconsistent // database diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index aa9ba0089d..8c74b6b06c 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -205,7 +205,7 @@ WKTFormatterNNPtr WKTFormatter::create(Convention convention, // cppcheck-suppress passedByValue DatabaseContextPtr dbContext) { auto ret = NN_NO_CHECK(WKTFormatter::make_unique(convention)); - ret->d->dbContext_ = dbContext; + ret->d->dbContext_ = std::move(dbContext); return ret; } @@ -1623,7 +1623,7 @@ IdentifierPtr WKTParser::Private::buildId(const WKTNodeNNPtr &node, std::string codeSpaceOut; if (dbContext_->getVersionedAuthority(codeSpace, version, codeSpaceOut)) { - codeSpace = codeSpaceOut; + codeSpace = std::move(codeSpaceOut); version.clear(); } } @@ -1761,7 +1761,7 @@ PropertyMap &WKTParser::Private::buildProperties(const WKTNodeNNPtr &node, name, tableNameForAlias, "ESRI", false, outTableName, authNameFromAlias, codeFromAlias); if (!officialName.empty()) { - name = officialName; + name = std::move(officialName); // Clearing authority for geodetic_crs because of // potential axis order mismatch. @@ -1994,9 +1994,9 @@ UnitOfMeasure WKTParser::Private::buildUnit(const WKTNodeNNPtr &node, unitName, "unit_of_measure", "ESRI", false, outTableName, authNameFromAlias, codeFromAlias); if (!officialName.empty()) { - unitName = officialName; - codeSpace = authNameFromAlias; - code = codeFromAlias; + unitName = std::move(officialName); + codeSpace = std::move(authNameFromAlias); + code = std::move(codeFromAlias); } } @@ -2415,10 +2415,10 @@ GeodeticReferenceFrameNNPtr WKTParser::Private::buildGeodeticReferenceFrame( auto nameWithPM = officialName + " (" + primeMeridian->nameStr() + ")"; if (dbContext_->isKnownName(nameWithPM, "geodetic_datum")) { - officialName = nameWithPM; + officialName = std::move(nameWithPM); } } - name = officialName; + name = std::move(officialName); } } @@ -3634,8 +3634,8 @@ WKTParser::Private::buildCoordinateOperation(const WKTNodeNNPtr &node) { std::vector parameters; std::vector values; - auto defaultLinearUnit = UnitOfMeasure::NONE; - auto defaultAngularUnit = UnitOfMeasure::NONE; + const auto &defaultLinearUnit = UnitOfMeasure::NONE; + const auto &defaultAngularUnit = UnitOfMeasure::NONE; consumeParameters(node, false, parameters, values, defaultLinearUnit, defaultAngularUnit); @@ -3680,8 +3680,8 @@ WKTParser::Private::buildPointMotionOperation(const WKTNodeNNPtr &node) { std::vector parameters; std::vector values; - auto defaultLinearUnit = UnitOfMeasure::NONE; - auto defaultAngularUnit = UnitOfMeasure::NONE; + const auto &defaultLinearUnit = UnitOfMeasure::NONE; + const auto &defaultAngularUnit = UnitOfMeasure::NONE; consumeParameters(node, false, parameters, values, defaultLinearUnit, defaultAngularUnit); @@ -4511,7 +4511,7 @@ WKTParser::Private::buildProjectedCRS(const WKTNodeNNPtr &node) { false, outTableName, authNameFromAlias, codeFromAlias); if (!officialNameFromFeet.empty()) { - officialName = officialNameFromFeet; + officialName = std::move(officialNameFromFeet); } } @@ -4540,11 +4540,11 @@ WKTParser::Private::buildProjectedCRS(const WKTNodeNNPtr &node) { // For WKT2, if there is no explicit parameter unit, use metre for linear // units and degree for angular units - auto linearUnit = + const UnitOfMeasure linearUnit( !isNull(conversionNode) ? UnitOfMeasure::METRE - : buildUnitInSubNode(node, UnitOfMeasure::Type::LINEAR); - auto angularUnit = + : buildUnitInSubNode(node, UnitOfMeasure::Type::LINEAR)); + const auto &angularUnit = !isNull(conversionNode) ? UnitOfMeasure::DEGREE : baseGeodCRS->coordinateSystem()->axisList()[0]->unit(); @@ -5131,7 +5131,7 @@ static TransformationNNPtr buildTransformationForBoundCRS( EPSG_CODE_PARAMETER_GEOID_CORRECTION_FILENAME); if (fileParameter && fileParameter->type() == ParameterValue::Type::FILENAME) { - auto filename = fileParameter->valueFile(); + const auto &filename = fileParameter->valueFile(); transformation = Transformation::createGravityRelatedHeightToGeographic3D( @@ -5183,8 +5183,8 @@ BoundCRSNNPtr WKTParser::Private::buildBoundCRS(const WKTNodeNNPtr &node) { std::vector parameters; std::vector values; - auto defaultLinearUnit = UnitOfMeasure::NONE; - auto defaultAngularUnit = UnitOfMeasure::NONE; + const auto &defaultLinearUnit = UnitOfMeasure::NONE; + const auto &defaultAngularUnit = UnitOfMeasure::NONE; consumeParameters(abridgedNode, true, parameters, values, defaultLinearUnit, defaultAngularUnit); @@ -5397,7 +5397,7 @@ WKTParser::Private::buildDerivedProjectedCRS(const WKTNodeNNPtr &node) { } auto linearUnit = buildUnitInSubNode(node); - auto angularUnit = + const auto &angularUnit = baseProjCRS->baseCRS()->coordinateSystem()->axisList()[0]->unit(); auto conversion = buildConversion(conversionNode, linearUnit, angularUnit); @@ -6081,7 +6081,7 @@ IdentifierNNPtr JSONParser::buildId(const json &j, bool removeInverseOf) { std::string codeSpaceOut; if (dbContext_->getVersionedAuthority(codeSpace, version, codeSpaceOut)) { - codeSpace = codeSpaceOut; + codeSpace = std::move(codeSpaceOut); version.clear(); } } @@ -6779,9 +6779,10 @@ MeridianNNPtr JSONParser::buildMeridian(const json &j) { CoordinateSystemAxisNNPtr JSONParser::buildAxis(const json &j) { auto dirString = getString(j, "direction"); auto abbreviation = getString(j, "abbreviation"); - auto unit = j.contains("unit") ? getUnit(j, "unit") - : UnitOfMeasure(std::string(), 1.0, - UnitOfMeasure::Type::NONE); + const UnitOfMeasure unit( + j.contains("unit") + ? getUnit(j, "unit") + : UnitOfMeasure(std::string(), 1.0, UnitOfMeasure::Type::NONE)); auto direction = AxisDirection::valueOf(dirString); if (!direction) { throw ParsingException(concat("unhandled axis direction: ", dirString)); @@ -7275,7 +7276,7 @@ static CRSNNPtr importFromWMSAUTO(const std::string &text) { } }; - const auto getUnits = [=]() { + const auto getUnits = [=]() -> const UnitOfMeasure & { switch (nUnitsId) { case 9001: return UnitOfMeasure::METRE; @@ -7767,7 +7768,7 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text, // urn:ogc:def:crs:EPSG::4326 if (tokens.size() == 7 && tolower(tokens[0]) == "urn") { - const auto type = tokens[3] == "CRS" ? "crs" : tokens[3]; + const std::string type(tokens[3] == "CRS" ? "crs" : tokens[3]); const auto &authName = tokens[4]; const auto &version = tokens[5]; const auto &code = tokens[6]; @@ -8751,10 +8752,10 @@ const std::string &PROJStringFormatter::toString() const { first.paramValues[0].keyEquals("z_in") && first.paramValues[1].keyEquals("z_out")) { - auto xy_in = second.paramValues[0].value; - auto xy_out = second.paramValues[1].value; - auto z_in = first.paramValues[0].value; - auto z_out = first.paramValues[1].value; + const std::string xy_in(second.paramValues[0].value); + const std::string xy_out(second.paramValues[1].value); + const std::string z_in(first.paramValues[0].value); + const std::string z_out(first.paramValues[1].value); iterCur->paramValues.clear(); iterCur->paramValues.emplace_back( @@ -8793,8 +8794,8 @@ const std::string &PROJStringFormatter::toString() const { second.paramValues[1].keyEquals("xy_out") && first.paramValues[0].value == second.paramValues[1].value && first.paramValues[2].value == second.paramValues[0].value) { - auto z_in = first.paramValues[1].value; - auto z_out = first.paramValues[3].value; + const std::string z_in(first.paramValues[1].value); + const std::string z_out(first.paramValues[3].value); if (z_in != z_out) { iterCur->paramValues.clear(); iterCur->paramValues.emplace_back( @@ -8828,10 +8829,10 @@ const std::string &PROJStringFormatter::toString() const { curStep.paramValues[0].keyEquals("z_in") && curStep.paramValues[1].keyEquals("z_out") && prevStep.paramValues[3].value == curStep.paramValues[0].value) { - auto xy_in = prevStep.paramValues[0].value; - auto z_in = prevStep.paramValues[1].value; - auto xy_out = prevStep.paramValues[2].value; - auto z_out = curStep.paramValues[1].value; + const std::string xy_in(prevStep.paramValues[0].value); + const std::string z_in(prevStep.paramValues[1].value); + const std::string xy_out(prevStep.paramValues[2].value); + const std::string z_out(curStep.paramValues[1].value); iterCur->paramValues.clear(); iterCur->paramValues.emplace_back( @@ -8861,10 +8862,10 @@ const std::string &PROJStringFormatter::toString() const { curStep.paramValues[2].keyEquals("xy_out") && curStep.paramValues[3].keyEquals("z_out") && prevStep.paramValues[1].value == curStep.paramValues[1].value) { - auto xy_in = curStep.paramValues[0].value; - auto z_in = prevStep.paramValues[0].value; - auto xy_out = curStep.paramValues[2].value; - auto z_out = curStep.paramValues[3].value; + const std::string xy_in(curStep.paramValues[0].value); + const std::string z_in(prevStep.paramValues[0].value); + const std::string xy_out(curStep.paramValues[2].value); + const std::string z_out(curStep.paramValues[3].value); iterCur->paramValues.clear(); iterCur->paramValues.emplace_back( @@ -8894,10 +8895,10 @@ const std::string &PROJStringFormatter::toString() const { curStep.paramValues[0].keyEquals("xy_in") && curStep.paramValues[1].keyEquals("xy_out") && prevStep.paramValues[2].value == curStep.paramValues[0].value) { - auto xy_in = prevStep.paramValues[0].value; - auto z_in = prevStep.paramValues[1].value; - auto xy_out = curStep.paramValues[1].value; - auto z_out = prevStep.paramValues[3].value; + const std::string xy_in(prevStep.paramValues[0].value); + const std::string z_in(prevStep.paramValues[1].value); + const std::string xy_out(curStep.paramValues[1].value); + const std::string z_out(prevStep.paramValues[3].value); iterCur->paramValues.clear(); iterCur->paramValues.emplace_back( @@ -8940,10 +8941,10 @@ const std::string &PROJStringFormatter::toString() const { curStep.paramValues[3].keyEquals("z_out") && prevStep.paramValues[2].value == curStep.paramValues[0].value && curStep.paramValues[1].value == curStep.paramValues[3].value) { - auto xy_in = prevStep.paramValues[0].value; - auto z_in = prevStep.paramValues[1].value; - auto xy_out = curStep.paramValues[2].value; - auto z_out = prevStep.paramValues[3].value; + const std::string xy_in(prevStep.paramValues[0].value); + const std::string z_in(prevStep.paramValues[1].value); + const std::string xy_out(curStep.paramValues[2].value); + const std::string z_out(prevStep.paramValues[3].value); iterCur->paramValues.clear(); iterCur->paramValues.emplace_back( @@ -8979,10 +8980,10 @@ const std::string &PROJStringFormatter::toString() const { prevStep.paramValues[1].value == prevStep.paramValues[3].value && curStep.paramValues[0].value == prevStep.paramValues[2].value) { - auto xy_in = prevStep.paramValues[0].value; - auto z_in = curStep.paramValues[1].value; - auto xy_out = curStep.paramValues[2].value; - auto z_out = curStep.paramValues[3].value; + const std::string xy_in(prevStep.paramValues[0].value); + const std::string z_in(curStep.paramValues[1].value); + const std::string xy_out(curStep.paramValues[2].value); + const std::string z_out(curStep.paramValues[3].value); iterCur->paramValues.clear(); iterCur->paramValues.emplace_back( @@ -9532,9 +9533,10 @@ const std::string &PROJStringFormatter::toString() const { } if (ok) { - auto stepVgridshift = *iterVgridshift; + Step stepVgridshift(*iterVgridshift); steps.erase(iterPrev, iterPush); - steps.insert(std::next(iterNext), stepVgridshift); + steps.insert(std::next(iterNext), + std::move(stepVgridshift)); iterPrev = iterPush; iterCur = std::next(iterPush); continue; @@ -9779,9 +9781,10 @@ PROJStringSyntaxParser(const std::string &projString, std::vector &steps, const auto pos = word.find('='); auto key = word.substr(0, pos); - auto pair = (pos != std::string::npos) - ? Step::KeyValue(key, word.substr(pos + 1)) - : Step::KeyValue(key); + const Step::KeyValue pair( + (pos != std::string::npos) + ? Step::KeyValue(key, word.substr(pos + 1)) + : Step::KeyValue(key)); if (steps.empty()) { globalParamValues.push_back(pair); } else { @@ -9814,11 +9817,11 @@ PROJStringSyntaxParser(const std::string &projString, std::vector &steps, } else if (inPipeline && !steps.empty() && starts_with(word, "proj=") && steps.back().name.empty()) { auto stepName = word.substr(strlen("proj=")); - steps.back().name = stepName; + steps.back().name = std::move(stepName); } else if (inPipeline && !steps.empty() && starts_with(word, "init=") && steps.back().name.empty()) { auto initName = word.substr(strlen("init=")); - steps.back().name = initName; + steps.back().name = std::move(initName); steps.back().isInit = true; } else if (!inPipeline && starts_with(word, "title=")) { title = word.substr(strlen("title=")); @@ -10999,7 +11002,7 @@ PROJStringParser::Private::processAxisSwap(Step &step, /*: (axisType == AxisType::SOUTH_POLE) ? AxisDirection::NORTH*/ : AxisDirection::NORTH; - CoordinateSystemAxisNNPtr north = createAxis( + const CoordinateSystemAxisNNPtr north = createAxis( northName, northAbbev, northDir, unit, isGeographic ? nullMeridian : (axisType == AxisType::NORTH_POLE) @@ -11008,7 +11011,7 @@ PROJStringParser::Private::processAxisSwap(Step &step, ? Meridian::create(Angle(0, UnitOfMeasure::DEGREE)).as_nullable() : nullMeridian); - CoordinateSystemAxisNNPtr west = + const CoordinateSystemAxisNNPtr west = createAxis(isSpherical ? "Planetocentric longitude" : isGeographic ? AxisName::Longitude : AxisName::Westing, @@ -11017,7 +11020,7 @@ PROJStringParser::Private::processAxisSwap(Step &step, : std::string(), AxisDirection::WEST, unit); - CoordinateSystemAxisNNPtr south = + const CoordinateSystemAxisNNPtr south = createAxis(isSpherical ? "Planetocentric latitude" : isGeographic ? AxisName::Latitude : AxisName::Southing, @@ -12321,7 +12324,7 @@ PROJStringParser::createFromPROJString(const std::string &projString) { newParamValues.emplace_back(kv); } } - step.paramValues = newParamValues; + step.paramValues = std::move(newParamValues); d->projString_.clear(); if (!step.name.empty()) { @@ -12346,13 +12349,13 @@ PROJStringParser::createFromPROJString(const std::string &projString) { if (!valid) { const int l_errno = proj_context_errno(pj_context); - std::string prefix("Error " + toString(l_errno) + " (" + - proj_errno_string(l_errno) + ")"); - if (logger.msg.empty()) { - logger.msg = prefix; - } else { - logger.msg = prefix + ": " + logger.msg; + std::string msg("Error " + toString(l_errno) + " (" + + proj_errno_string(l_errno) + ")"); + if (!logger.msg.empty()) { + msg += ": "; + msg += logger.msg; } + logger.msg = std::move(msg); } if (pj_context != d->ctx_) { @@ -12478,7 +12481,7 @@ struct JSONFormatter::Private { JSONFormatterNNPtr JSONFormatter::create( // cppcheck-suppress passedByValue DatabaseContextPtr dbContext) { auto ret = NN_NO_CHECK(JSONFormatter::make_unique()); - ret->d->dbContext_ = dbContext; + ret->d->dbContext_ = std::move(dbContext); return ret; } diff --git a/src/iso19111/operation/concatenatedoperation.cpp b/src/iso19111/operation/concatenatedoperation.cpp index b3164e67c8..6fe3462c0d 100644 --- a/src/iso19111/operation/concatenatedoperation.cpp +++ b/src/iso19111/operation/concatenatedoperation.cpp @@ -177,7 +177,7 @@ ConcatenatedOperationNNPtr ConcatenatedOperation::create( if (interpolationCRSValid) { auto subOpInterpCRS = operationsIn[i]->interpolationCRS(); if (interpolationCRS == nullptr) - interpolationCRS = subOpInterpCRS; + interpolationCRS = std::move(subOpInterpCRS); else if (subOpInterpCRS == nullptr || !(subOpInterpCRS->isEquivalentTo( interpolationCRS.get(), @@ -218,7 +218,7 @@ ConcatenatedOperationNNPtr ConcatenatedOperation::create( "Inconsistent chaining of CRS in operations"); } } - lastTargetCRS = l_targetCRS; + lastTargetCRS = std::move(l_targetCRS); } // When chaining VerticalCRS -> GeographicCRS -> VerticalCRS, use @@ -784,7 +784,7 @@ void ConcatenatedOperation::_exportToJSON( !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -828,7 +828,7 @@ CoordinateOperationNNPtr ConcatenatedOperation::_shallowClone() const { for (const auto &subOp : d->operations_) { ops.emplace_back(subOp->shallowClone()); } - op->d->operations_ = ops; + op->d->operations_ = std::move(ops); op->assignSelf(op); op->setCRSs(this, false); return util::nn_static_pointer_cast(op); diff --git a/src/iso19111/operation/conversion.cpp b/src/iso19111/operation/conversion.cpp index c70a5214c5..cdb3e6666d 100644 --- a/src/iso19111/operation/conversion.cpp +++ b/src/iso19111/operation/conversion.cpp @@ -3447,7 +3447,7 @@ void Conversion::_exportToJSON( formatter->MakeObjectContext("Conversion", !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { @@ -3539,7 +3539,7 @@ static bool createPROJ4WebMercator(const Conversion *conv, util::IComparable::Criterion::EQUIVALENT)) { auto projUnit = unit.exportToPROJString(); if (!projUnit.empty()) { - units = projUnit; + units = std::move(projUnit); } else { return false; } diff --git a/src/iso19111/operation/coordinateoperationfactory.cpp b/src/iso19111/operation/coordinateoperationfactory.cpp index 1804c3d27e..3cda6aad9e 100644 --- a/src/iso19111/operation/coordinateoperationfactory.cpp +++ b/src/iso19111/operation/coordinateoperationfactory.cpp @@ -1947,7 +1947,7 @@ findCandidateGeodCRSForDatum(const io::AuthorityFactoryPtr &authFactory, const crs::GeodeticCRS *crs, const datum::GeodeticReferenceFrameNNPtr &datum) { std::string preferredAuthName; - const auto crsIds = crs->identifiers(); + const auto &crsIds = crs->identifiers(); if (crsIds.size() == 1) preferredAuthName = *(crsIds.front()->codeSpace()); return authFactory->createGeodeticCRSFromDatum(datum, preferredAuthName, @@ -2767,13 +2767,13 @@ CoordinateOperationFactory::Private::createOperationsGeogToGeog( const auto &src_pm = geogSrc->primeMeridian()->longitude(); const auto &dst_pm = geogDst->primeMeridian()->longitude(); - auto offset_pm = + const common::Angle offset_pm( (src_pm.unit() == dst_pm.unit()) ? common::Angle(src_pm.value() - dst_pm.value(), src_pm.unit()) : common::Angle( src_pm.convertToUnit(common::UnitOfMeasure::DEGREE) - dst_pm.convertToUnit(common::UnitOfMeasure::DEGREE), - common::UnitOfMeasure::DEGREE); + common::UnitOfMeasure::DEGREE)); double vconvSrc = 1.0; const auto &srcCS = geogSrc->coordinateSystem(); @@ -3107,12 +3107,12 @@ void CoordinateOperationFactory::Private::createOperationsWithDatumPivot( } } - const auto opsSecond = + const std::vector opsSecond( useOnlyDirectRegistryOp ? findOpsInRegistryDirect(candidateSrcGeod, candidateDstGeod, context, resNonEmptyBeforeFiltering) : createOperations(candidateSrcGeod, targetEpoch, - candidateDstGeod, targetEpoch, context); + candidateDstGeod, targetEpoch, context)); const auto opsThird = createOperations( sourceAndTargetAre3D ? candidateDstGeod->promoteTo3D(std::string(), dbContext) @@ -3703,12 +3703,11 @@ void CoordinateOperationFactory::Private::createOperationsFromProj4Ext( projFormatter->ingestPROJString(tmpFormatter->toString()); } - const auto PROJString = projFormatter->toString(); auto properties = util::PropertyMap().set( common::IdentifiedObject::NAME_KEY, buildTransfName(sourceCRS->nameStr(), targetCRS->nameStr())); res.emplace_back(SingleOperation::createPROJBased( - properties, PROJString, sourceCRS, targetCRS, {})); + properties, projFormatter->toString(), sourceCRS, targetCRS, {})); } // --------------------------------------------------------------------------- @@ -4181,7 +4180,7 @@ CoordinateOperationFactory::Private::createOperationsGeogToVertFromGeoid( for (const auto &model : models) { const auto &modelName = model->nameStr(); const auto &modelIds = model->identifiers(); - const auto transformations = + const std::vector transformations( !modelIds.empty() ? std::vector< CoordinateOperationNNPtr>{io::AuthorityFactory::create( @@ -4198,7 +4197,7 @@ CoordinateOperationFactory::Private::createOperationsGeogToVertFromGeoid( model, modelName.substr(strlen("PROJ ")))} : authFactory->getTransformationsForGeoid( modelName, - context.context->getUsePROJAlternativeGridNames()); + context.context->getUsePROJAlternativeGridNames())); for (const auto &transf : transformations) { if (dynamic_cast( transf->sourceCRS().get()) && @@ -4706,7 +4705,8 @@ void CoordinateOperationFactory::Private:: // need it in practice. setCRSs(opSecondClone.get(), intermBoundCRS, targetCRS); res.emplace_back(ConcatenatedOperation::createComputeMetadata( - {opFirst, opSecondClone}, disallowEmptyIntersection)); + {opFirst, std::move(opSecondClone)}, + disallowEmptyIntersection)); } catch (const InvalidOperationEmptyIntersection &) { } } @@ -4766,7 +4766,7 @@ void CoordinateOperationFactory::Private::createOperationsBoundToGeog( auto baseCRS = std::dynamic_pointer_cast( derivedGeogCRS->baseCRS().as_nullable()); if (baseCRS) { - geogCRSOfBaseOfBoundSrc = baseCRS; + geogCRSOfBaseOfBoundSrc = std::move(baseCRS); } } } @@ -5078,7 +5078,7 @@ void CoordinateOperationFactory::Private::createOperationsBoundToGeog( } } } else { - res = opsFirst; + res = std::move(opsFirst); } } return; @@ -5930,7 +5930,7 @@ void CoordinateOperationFactory::Private::createOperationsCompoundToGeog( } } if (foundRegisteredTransformWithAllGridsAvailable) { - verticalTransforms = verticalTransformsTmp; + verticalTransforms = std::move(verticalTransformsTmp); } else if (foundRegisteredTransform) { verticalTransforms.insert(verticalTransforms.end(), verticalTransformsTmp.begin(), @@ -6196,7 +6196,7 @@ void CoordinateOperationFactory::Private::createOperationsToGeod( setCRSs(newOp.get(), sourceCRS, intermGeog3DCRS); try { res.emplace_back(ConcatenatedOperation::createComputeMetadata( - {newOp, geog3DToTargetOps.front()}, + {std::move(newOp), geog3DToTargetOps.front()}, disallowEmptyIntersection)); } catch (const InvalidOperationEmptyIntersection &) { } @@ -6688,7 +6688,7 @@ void CoordinateOperationFactory::Private::createOperationsCompoundToCompound( verticalTransform->nameStr().find( "CGVD28 height to CGVD2013a(2002) height (1)") != std::string::npos))) { - interpolationGeogCRS = nad83CSRSv7; + interpolationGeogCRS = std::move(nad83CSRSv7); } } catch (const std::exception &) { } @@ -7259,7 +7259,7 @@ crs::CRSNNPtr CRS::getResolvedCRS(const crs::CRSNNPtr &crs, extentOut = extentOut->intersection( NN_NO_CHECK(componentExtent)); else if (componentExtent) - extentOut = componentExtent; + extentOut = std::move(componentExtent); } } } diff --git a/src/iso19111/operation/projbasedoperation.cpp b/src/iso19111/operation/projbasedoperation.cpp index fd03fc0943..04275f3f5f 100644 --- a/src/iso19111/operation/projbasedoperation.cpp +++ b/src/iso19111/operation/projbasedoperation.cpp @@ -118,7 +118,7 @@ PROJBasedOperationNNPtr PROJBasedOperation::create( if (inverse) { formatter->stopInversion(); } - auto projString = formatter->toString(); + const auto &projString = formatter->toString(); auto method = OperationMethod::create( util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, @@ -209,7 +209,7 @@ void PROJBasedOperation::_exportToJSON( !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { diff --git a/src/iso19111/operation/singleoperation.cpp b/src/iso19111/operation/singleoperation.cpp index 197dbd0d9d..9ea0306cdf 100644 --- a/src/iso19111/operation/singleoperation.cpp +++ b/src/iso19111/operation/singleoperation.cpp @@ -2382,7 +2382,7 @@ TransformationNNPtr SingleOperation::substitutePROJAlternativeGridNames( EPSG_CODE_PARAMETER_GEOID_CORRECTION_FILENAME); if (fileParameter && fileParameter->type() == ParameterValue::Type::FILENAME) { - auto filename = fileParameter->valueFile(); + const auto &filename = fileParameter->valueFile(); if (databaseContext->lookForGridAlternative( filename, projFilename, projGridFormat, inverseDirection)) { @@ -3152,12 +3152,12 @@ void SingleOperation::exportToPROJStringChangeVerticalUnit( const auto uom = common::UnitOfMeasure(std::string(), convFactor, common::UnitOfMeasure::Type::LINEAR) .exportToPROJString(); - const auto reverse_uom = + const std::string reverse_uom( convFactor == 0.0 ? std::string() : common::UnitOfMeasure(std::string(), 1.0 / convFactor, common::UnitOfMeasure::Type::LINEAR) - .exportToPROJString(); + .exportToPROJString()); if (uom == "m") { // do nothing } else if (!uom.empty()) { @@ -4078,8 +4078,8 @@ bool SingleOperation::exportToPROJStringGeneric( sourceCRSGeog->ellipsoid()->_exportToPROJString(formatter); formatter->addStep("deformation"); - auto srcName = sourceCRS()->nameStr(); - auto dstName = targetCRS()->nameStr(); + const std::string srcName(sourceCRS()->nameStr()); + const std::string dstName(targetCRS()->nameStr()); const struct { const char *name; double epoch; @@ -4260,7 +4260,7 @@ bool SingleOperation::exportToPROJStringGeneric( EPSG_CODE_PARAMETER_GEOID_CORRECTION_FILENAME); if (fileParameter && fileParameter->type() == ParameterValue::Type::FILENAME) { - auto filename = fileParameter->valueFile(); + const auto &filename = fileParameter->valueFile(); auto l_sourceCRS = sourceCRS(); auto sourceCRSGeog = @@ -4920,7 +4920,7 @@ void PointMotionOperation::_exportToJSON( !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { diff --git a/src/iso19111/operation/transformation.cpp b/src/iso19111/operation/transformation.cpp index 22569c5a5f..52898d8192 100644 --- a/src/iso19111/operation/transformation.cpp +++ b/src/iso19111/operation/transformation.cpp @@ -1577,7 +1577,7 @@ TransformationNNPtr Transformation::inverseAsTransformation() const { } if (isLongitudeRotation()) { - auto offset = + const auto &offset = parameterValueMeasure(EPSG_CODE_PARAMETER_LONGITUDE_OFFSET); const common::Angle newOffset(negate(offset.value()), offset.unit()); return Private::registerInv( @@ -1587,12 +1587,12 @@ TransformationNNPtr Transformation::inverseAsTransformation() const { } if (methodEPSGCode == EPSG_CODE_METHOD_GEOGRAPHIC2D_OFFSETS) { - auto offsetLat = + const auto &offsetLat = parameterValueMeasure(EPSG_CODE_PARAMETER_LATITUDE_OFFSET); const common::Angle newOffsetLat(negate(offsetLat.value()), offsetLat.unit()); - auto offsetLong = + const auto &offsetLong = parameterValueMeasure(EPSG_CODE_PARAMETER_LONGITUDE_OFFSET); const common::Angle newOffsetLong(negate(offsetLong.value()), offsetLong.unit()); @@ -1605,17 +1605,17 @@ TransformationNNPtr Transformation::inverseAsTransformation() const { } if (methodEPSGCode == EPSG_CODE_METHOD_GEOGRAPHIC3D_OFFSETS) { - auto offsetLat = + const auto &offsetLat = parameterValueMeasure(EPSG_CODE_PARAMETER_LATITUDE_OFFSET); const common::Angle newOffsetLat(negate(offsetLat.value()), offsetLat.unit()); - auto offsetLong = + const auto &offsetLong = parameterValueMeasure(EPSG_CODE_PARAMETER_LONGITUDE_OFFSET); const common::Angle newOffsetLong(negate(offsetLong.value()), offsetLong.unit()); - auto offsetHeight = + const auto &offsetHeight = parameterValueMeasure(EPSG_CODE_PARAMETER_VERTICAL_OFFSET); const common::Length newOffsetHeight(negate(offsetHeight.value()), offsetHeight.unit()); @@ -1633,12 +1633,12 @@ TransformationNNPtr Transformation::inverseAsTransformation() const { const common::Angle newOffsetLat(negate(offsetLat.value()), offsetLat.unit()); - auto offsetLong = + const auto &offsetLong = parameterValueMeasure(EPSG_CODE_PARAMETER_LONGITUDE_OFFSET); const common::Angle newOffsetLong(negate(offsetLong.value()), offsetLong.unit()); - auto offsetHeight = + const auto &offsetHeight = parameterValueMeasure(EPSG_CODE_PARAMETER_GEOID_UNDULATION); const common::Length newOffsetHeight(negate(offsetHeight.value()), offsetHeight.unit()); @@ -1652,7 +1652,7 @@ TransformationNNPtr Transformation::inverseAsTransformation() const { if (methodEPSGCode == EPSG_CODE_METHOD_VERTICAL_OFFSET) { - auto offsetHeight = + const auto &offsetHeight = parameterValueMeasure(EPSG_CODE_PARAMETER_VERTICAL_OFFSET); const common::Length newOffsetHeight(negate(offsetHeight.value()), offsetHeight.unit()); @@ -1773,7 +1773,7 @@ void Transformation::_exportToJSON( !identifiers().empty())); writer->AddObjKey("name"); - auto l_name = nameStr(); + const auto &l_name = nameStr(); if (l_name.empty()) { writer->Add("unnamed"); } else { diff --git a/src/transformations/gridshift.cpp b/src/transformations/gridshift.cpp index 44504ae30d..d628d36d32 100644 --- a/src/transformations/gridshift.cpp +++ b/src/transformations/gridshift.cpp @@ -96,7 +96,7 @@ struct gridshiftData { bool gridshiftData::checkGridTypes(PJ *P) { for (const auto &gridset : m_grids) { for (const auto &grid : gridset->grids()) { - const auto type = grid->metadataItem("TYPE"); + const auto &type = grid->metadataItem("TYPE"); if (type == "HORIZONTAL_OFFSET") m_bHasHorizontalOffset = true; else if (type == "GEOGRAPHIC_3D_OFFSET") @@ -268,8 +268,7 @@ PJ_LPZ gridshiftData::grid_interpolate(PJ_CONTEXT *ctx, const std::string &type, gridInfo.idxSampleLatLongZ[0] = idxSampleLat; gridInfo.idxSampleLatLongZ[1] = idxSampleLong; gridInfo.idxSampleLatLongZ[2] = idxSampleZ; - m_cacheGridInfo[grid] = gridInfo; - iterCache = m_cacheGridInfo.find(grid); + iterCache = m_cacheGridInfo.emplace(grid, std::move(gridInfo)).first; } GridInfo &gridInfo = iterCache->second; const int idxSampleLat = gridInfo.idxSampleLat;