From dcff935457b5bf9847b65e4857faf337ac90a62b Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 17 Mar 2024 23:52:30 +0100 Subject: [PATCH] gcore: use new CSLConstList/CPLStringList facilities --- gcore/gdaldataset.cpp | 35 +++++----------- gcore/gdaldriver.cpp | 68 ++++++++++++------------------- gcore/gdaljp2abstractdataset.cpp | 28 ++++++------- gcore/gdalmultidim.cpp | 7 ++-- gcore/gdalpamdataset.cpp | 13 +++--- gcore/gdalpython.cpp | 65 ++++++++++++++--------------- gcore/gdalrelationship.cpp | 70 +++++--------------------------- 7 files changed, 99 insertions(+), 187 deletions(-) diff --git a/gcore/gdaldataset.cpp b/gcore/gdaldataset.cpp index 8ffe1a75ef6d..30ba458663ae 100644 --- a/gcore/gdaldataset.cpp +++ b/gcore/gdaldataset.cpp @@ -190,9 +190,8 @@ static std::string GDALSharedDatasetConcatenateOpenOptions(CSLConstList papszOpenOptions) { std::string osStr; - for (CSLConstList papszIter = papszOpenOptions; papszIter && *papszIter; - ++papszIter) - osStr += *papszIter; + for (const char *pszOption : cpl::Iterate(papszOpenOptions)) + osStr += *pszOption; return osStr; } @@ -2105,18 +2104,10 @@ CPLErr GDALDataset::BuildOverviews(const char *pszResampling, int nOverviews, // At time of writing, all overview generation options are actually // expected to be passed as configuration options. std::vector> apoConfigOptionSetter; - for (CSLConstList papszIter = papszOptions; papszIter && *papszIter; - ++papszIter) + for (const auto &[pszKey, pszValue] : cpl::IterateNameValue(papszOptions)) { - char *pszKey = nullptr; - const char *pszValue = CPLParseNameValue(*papszIter, &pszKey); - if (pszKey && pszValue) - { - apoConfigOptionSetter.emplace_back( - std::make_unique(pszKey, pszValue, - false)); - } - CPLFree(pszKey); + apoConfigOptionSetter.emplace_back( + std::make_unique(pszKey, pszValue, false)); } const CPLErr eErr = @@ -3244,15 +3235,12 @@ char **GDALDataset::GetFileList() if (oOvManager.HaveMaskFile()) { auto iter = aosDatasetList.insert(datasetCtxt).first; - char **papszMskList = oOvManager.poMaskDS->GetFileList(); - char **papszIter = papszMskList; - while (papszIter && *papszIter) + for (const char *pszFile : + CPLStringList(oOvManager.poMaskDS->GetFileList())) { - if (CSLFindString(papszList, *papszIter) < 0) - papszList = CSLAddString(papszList, *papszIter); - ++papszIter; + if (CSLFindString(papszList, pszFile) < 0) + papszList = CSLAddString(papszList, pszFile); } - CSLDestroy(papszMskList); aosDatasetList.erase(iter); } @@ -3594,9 +3582,8 @@ GDALDatasetH CPL_STDCALL GDALOpenEx(const char *pszFilename, } std::string osAllowedDrivers; - for (CSLConstList papszIter = papszAllowedDrivers; papszIter && *papszIter; - ++papszIter) - osAllowedDrivers += *papszIter; + for (const char *pszDriverName : cpl::Iterate(papszAllowedDrivers)) + osAllowedDrivers += pszDriverName; auto dsCtxt = GDALAntiRecursionStruct::DatasetContext( std::string(pszFilename), nOpenFlags, osAllowedDrivers); if (sAntiRecursion.aosDatasetNamesWithFlags.find(dsCtxt) != diff --git a/gcore/gdaldriver.cpp b/gcore/gdaldriver.cpp index d0f69059b443..56b6f3cbd7e0 100644 --- a/gcore/gdaldriver.cpp +++ b/gcore/gdaldriver.cpp @@ -575,11 +575,10 @@ GDALDataset *GDALDriver::DefaultCreateCopy(const char *pszFilename, if (poSrcGroup != nullptr && GetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER)) { CPLStringList aosDatasetCO; - for (CSLConstList papszIter = papszOptions; papszIter && *papszIter; - ++papszIter) + for (const char *pszOption : cpl::Iterate(papszOptions)) { - if (!STARTS_WITH_CI(*papszIter, "ARRAY:")) - aosDatasetCO.AddString(*papszIter); + if (!STARTS_WITH_CI(pszOption, "ARRAY:")) + aosDatasetCO.AddString(pszOption); } auto poDstDS = std::unique_ptr( CreateMultiDimensional(pszFilename, nullptr, aosDatasetCO.List())); @@ -932,13 +931,9 @@ void GDALDriver::DefaultCopyMetadata(GDALDataset *poSrcDS, GDALDataset *poDstDS, if ((!EQUAL(pszCopySrcMDD, "AUTO") && CPLTestBool(pszCopySrcMDD)) || papszSrcMDD) { - char **papszDomainList = poSrcDS->GetMetadataDomainList(); - constexpr const char *apszReservedDomains[] = { - "IMAGE_STRUCTURE", "DERIVED_SUBDATASETS"}; - for (char **papszIter = papszDomainList; papszIter && *papszIter; - ++papszIter) + for (const char *pszDomain : + CPLStringList(poSrcDS->GetMetadataDomainList())) { - const char *pszDomain = *papszIter; if (pszDomain[0] != 0 && (!papszSrcMDD || CSLFindString(papszSrcMDD, pszDomain) >= 0)) @@ -960,6 +955,8 @@ void GDALDriver::DefaultCopyMetadata(GDALDataset *poSrcDS, GDALDataset *poDstDS, } if (!papszSrcMDD) { + constexpr const char *const apszReservedDomains[] = + {"IMAGE_STRUCTURE", "DERIVED_SUBDATASETS"}; for (const char *pszOtherDomain : apszReservedDomains) { @@ -978,7 +975,6 @@ void GDALDriver::DefaultCopyMetadata(GDALDataset *poSrcDS, GDALDataset *poDstDS, } } } - CSLDestroy(papszDomainList); } } CSLDestroy(papszSrcMDD); @@ -1018,14 +1014,12 @@ CPLErr GDALDriver::QuietDeleteForCreateCopy(const char *pszFilename, pszFilename, GDAL_OF_RASTER, apszAllowedDrivers)); if (poExistingOutputDS) { - char **papszFileList = poExistingOutputDS->GetFileList(); - for (char **papszIter = papszFileList; papszIter && *papszIter; - ++papszIter) + for (const char *pszFileInList : + CPLStringList(poExistingOutputDS->GetFileList())) { oSetExistingDestFiles.insert( - CPLString(*papszIter).replaceAll('\\', '/')); + CPLString(pszFileInList).replaceAll('\\', '/')); } - CSLDestroy(papszFileList); } CPLPopErrorHandler(); } @@ -1053,11 +1047,10 @@ CPLErr GDALDriver::QuietDeleteForCreateCopy(const char *pszFilename, poSrcDS->papszOpenOptions)); if (poSrcDSTmp) { - char **papszFileList = poSrcDSTmp->GetFileList(); - for (char **papszIter = papszFileList; papszIter && *papszIter; - ++papszIter) + for (const char *pszFileInList : + CPLStringList(poSrcDSTmp->GetFileList())) { - CPLString osFilename(*papszIter); + CPLString osFilename(pszFileInList); osFilename.replaceAll('\\', '/'); if (oSetExistingDestFiles.find(osFilename) != oSetExistingDestFiles.end()) @@ -1065,7 +1058,6 @@ CPLErr GDALDriver::QuietDeleteForCreateCopy(const char *pszFilename, oSetExistingDestFilesFoundInSource.insert(osFilename); } } - CSLDestroy(papszFileList); } CPLPopErrorHandler(); } @@ -1323,11 +1315,10 @@ GDALDataset *GDALDriver::CreateCopy(const char *pszFilename, if (poSrcGroup != nullptr && GetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER)) { CPLStringList aosDatasetCO; - for (CSLConstList papszIter = papszOptions; papszIter && *papszIter; - ++papszIter) + for (const char *pszOption : cpl::Iterate(papszOptions)) { - if (!STARTS_WITH_CI(*papszIter, "ARRAY:")) - aosDatasetCO.AddString(*papszIter); + if (!STARTS_WITH_CI(pszOption, "ARRAY:")) + aosDatasetCO.AddString(pszOption); } GDALValidateCreationOptions(this, aosDatasetCO.List()); } @@ -1462,10 +1453,9 @@ bool GDALDriver::CanVectorTranslateFrom( ppapszFailureReasons ? ppapszFailureReasons : &papszFailureReasons); if (!ppapszFailureReasons) { - for (CSLConstList papszIter = papszFailureReasons; - papszIter && *papszIter; ++papszIter) + for (const char *pszReason : cpl::Iterate(papszFailureReasons)) { - CPLDebug("GDAL", "%s", *papszIter); + CPLDebug("GDAL", "%s", pszReason); } CSLDestroy(papszFailureReasons); } @@ -1560,11 +1550,10 @@ CPLErr GDALDriver::QuietDelete(const char *pszName, if (papszAllowedDrivers) { GDALOpenInfo oOpenInfo(pszName, GDAL_OF_ALL); - for (CSLConstList papszIter = papszAllowedDrivers; *papszIter; - ++papszIter) + for (const char *pszDriverName : cpl::Iterate(papszAllowedDrivers)) { GDALDriver *poTmpDriver = - GDALDriver::FromHandle(GDALGetDriverByName(*papszIter)); + GDALDriver::FromHandle(GDALGetDriverByName(pszDriverName)); if (poTmpDriver) { const bool bIdentifyRes = @@ -2118,14 +2107,13 @@ int CPL_STDCALL GDALValidateCreationOptions(GDALDriverH hDriver, osDriver.Printf("driver %s", GDALDriver::FromHandle(hDriver)->GetDescription()); bool bFoundOptionToRemove = false; - for (CSLConstList papszIter = papszCreationOptions; papszIter && *papszIter; - ++papszIter) + for (const char *pszCO : cpl::Iterate(papszCreationOptions)) { for (const char *pszExcludedOptions : {"APPEND_SUBDATASET", "COPY_SRC_MDD", "SRC_MDD"}) { - if (STARTS_WITH_CI(*papszIter, pszExcludedOptions) && - (*papszIter)[strlen(pszExcludedOptions)] == '=') + if (STARTS_WITH_CI(pszCO, pszExcludedOptions) && + pszCO[strlen(pszExcludedOptions)] == '=') { bFoundOptionToRemove = true; break; @@ -2138,23 +2126,21 @@ int CPL_STDCALL GDALValidateCreationOptions(GDALDriverH hDriver, char **papszOptionsToFree = nullptr; if (bFoundOptionToRemove) { - for (CSLConstList papszIter = papszCreationOptions; - papszIter && *papszIter; ++papszIter) + for (const char *pszCO : cpl::Iterate(papszCreationOptions)) { bool bMatch = false; for (const char *pszExcludedOptions : {"APPEND_SUBDATASET", "COPY_SRC_MDD", "SRC_MDD"}) { - if (STARTS_WITH_CI(*papszIter, pszExcludedOptions) && - (*papszIter)[strlen(pszExcludedOptions)] == '=') + if (STARTS_WITH_CI(pszCO, pszExcludedOptions) && + pszCO[strlen(pszExcludedOptions)] == '=') { bMatch = true; break; } } if (!bMatch) - papszOptionsToFree = - CSLAddString(papszOptionsToFree, *papszIter); + papszOptionsToFree = CSLAddString(papszOptionsToFree, pszCO); } papszOptionsToValidate = papszOptionsToFree; } diff --git a/gcore/gdaljp2abstractdataset.cpp b/gcore/gdaljp2abstractdataset.cpp index 06a0a55a3475..6b6fbbb3b9fa 100644 --- a/gcore/gdaljp2abstractdataset.cpp +++ b/gcore/gdaljp2abstractdataset.cpp @@ -123,14 +123,14 @@ void GDALJP2AbstractDataset::LoadJP2Metadata(GDALOpenInfo *poOpenInfo, if (bGeorefSourcesConfigOption) { - for (char **papszIter = papszTokens; *papszIter; ++papszIter) + for (const char *pszToken : cpl::Iterate(papszTokens)) { - if (!EQUAL(*papszIter, "PAM") && !EQUAL(*papszIter, "GEOJP2") && - !EQUAL(*papszIter, "GMLJP2") && !EQUAL(*papszIter, "MSIG") && - !EQUAL(*papszIter, "WORLDFILE") && !EQUAL(*papszIter, "NONE")) + if (!EQUAL(pszToken, "PAM") && !EQUAL(pszToken, "GEOJP2") && + !EQUAL(pszToken, "GMLJP2") && !EQUAL(pszToken, "MSIG") && + !EQUAL(pszToken, "WORLDFILE") && !EQUAL(pszToken, "NONE")) { CPLError(CE_Warning, CPLE_AppDefined, - "Unhandled value %s in GEOREF_SOURCES", *papszIter); + "Unhandled value %s in GEOREF_SOURCES", pszToken); } } } @@ -224,26 +224,24 @@ void GDALJP2AbstractDataset::LoadJP2Metadata(GDALOpenInfo *poOpenInfo, { GDALMultiDomainMetadata oLocalMDMD; oLocalMDMD.XMLInit(psXMLNode, FALSE); - char **papszDomainList = oLocalMDMD.GetDomainList(); - char **papszIter = papszDomainList; GDALDataset::SetMetadata(oLocalMDMD.GetMetadata()); - while (papszIter && *papszIter) + for (const char *pszDomain : + cpl::Iterate(oLocalMDMD.GetDomainList())) { - if (!EQUAL(*papszIter, "") && - !EQUAL(*papszIter, "IMAGE_STRUCTURE")) + if (!EQUAL(pszDomain, "") && + !EQUAL(pszDomain, "IMAGE_STRUCTURE")) { - if (GDALDataset::GetMetadata(*papszIter) != nullptr) + if (GDALDataset::GetMetadata(pszDomain) != nullptr) { CPLDebug( "GDALJP2", "GDAL metadata overrides metadata in %s domain " "over metadata read from other boxes", - *papszIter); + pszDomain); } - GDALDataset::SetMetadata(oLocalMDMD.GetMetadata(*papszIter), - *papszIter); + GDALDataset::SetMetadata(oLocalMDMD.GetMetadata(pszDomain), + pszDomain); } - ++papszIter; } CPLDestroyXMLNode(psXMLNode); } diff --git a/gcore/gdalmultidim.cpp b/gcore/gdalmultidim.cpp index c2eacdded4dd..1ac37009dae3 100644 --- a/gcore/gdalmultidim.cpp +++ b/gcore/gdalmultidim.cpp @@ -913,12 +913,11 @@ bool GDALGroup::CopyFrom(const std::shared_ptr &poDstRootGroup, CPLStringList aosArrayCO; bool bAutoScale = false; GDALDataType eAutoScaleType = GDT_UInt16; - for (CSLConstList papszIter = papszOptions; papszIter && *papszIter; - ++papszIter) + for (const char *pszItem : cpl::Iterate(papszOptions)) { - if (STARTS_WITH_CI(*papszIter, "ARRAY:")) + if (STARTS_WITH_CI(pszItem, "ARRAY:")) { - const char *pszOption = *papszIter + strlen("ARRAY:"); + const char *pszOption = pszItem + strlen("ARRAY:"); if (STARTS_WITH_CI(pszOption, "IF(DIM=")) { const char *pszNext = strchr(pszOption, ':'); diff --git a/gcore/gdalpamdataset.cpp b/gcore/gdalpamdataset.cpp index 44ebedd932f8..244549ce6514 100644 --- a/gcore/gdalpamdataset.cpp +++ b/gcore/gdalpamdataset.cpp @@ -1800,26 +1800,23 @@ void GDALPamDataset::ClearStatistics() { bool bChanged = false; GDALRasterBand *poBand = GetRasterBand(i); - char **papszOldMD = poBand->GetMetadata(); - char **papszNewMD = nullptr; - for (char **papszIter = papszOldMD; papszIter && papszIter[0]; - ++papszIter) + CPLStringList aosNewMD; + for (const char *pszStr : cpl::Iterate(poBand->GetMetadata())) { - if (STARTS_WITH_CI(*papszIter, "STATISTICS_")) + if (STARTS_WITH_CI(pszStr, "STATISTICS_")) { MarkPamDirty(); bChanged = true; } else { - papszNewMD = CSLAddString(papszNewMD, *papszIter); + aosNewMD.AddString(pszStr); } } if (bChanged) { - poBand->SetMetadata(papszNewMD); + poBand->SetMetadata(aosNewMD.List()); } - CSLDestroy(papszNewMD); } GDALDataset::ClearStatistics(); diff --git a/gcore/gdalpython.cpp b/gcore/gdalpython.cpp index 6fda83e8d88f..4d6387dac6a1 100644 --- a/gcore/gdalpython.cpp +++ b/gcore/gdalpython.cpp @@ -278,15 +278,15 @@ static bool LoadPythonAPI() #endif ) { - char **papszTokens = CSLTokenizeString2(pszPath, ":", 0); + const CPLStringList aosPathParts( + CSLTokenizeString2(pszPath, ":", 0)); for (int iTry = 0; iTry < 2; ++iTry) { - for (char **papszIter = papszTokens; - papszIter != nullptr && *papszIter != nullptr; ++papszIter) + for (const char *pszPathPart : aosPathParts) { struct stat sStat; CPLString osPythonBinary( - CPLFormFilename(*papszIter, "python", nullptr)); + CPLFormFilename(pszPathPart, "python", nullptr)); if (iTry == 0) osPythonBinary += "3"; if (lstat(osPythonBinary, &sStat) != 0) @@ -401,7 +401,6 @@ static bool LoadPythonAPI() if (!osVersion.empty()) break; } - CSLDestroy(papszTokens); } if (!osVersion.empty()) @@ -543,15 +542,15 @@ static bool LoadPythonAPI() #endif ) { - char **papszTokens = CSLTokenizeString2(pszPath, ";", 0); + const CPLStringList aosPathParts( + CSLTokenizeString2(pszPath, ";", 0)); for (int iTry = 0; iTry < 2; ++iTry) { - for (char **papszIter = papszTokens; - papszIter != nullptr && *papszIter != nullptr; ++papszIter) + for (const char *pszPathPart : aosPathParts) { VSIStatBufL sStat; CPLString osPythonBinary( - CPLFormFilename(*papszIter, "python.exe", nullptr)); + CPLFormFilename(pszPathPart, "python.exe", nullptr)); if (iTry == 1) osPythonBinary += "3"; if (VSIStatL(osPythonBinary, &sStat) != 0) @@ -559,43 +558,39 @@ static bool LoadPythonAPI() CPLDebug("GDAL", "Found %s", osPythonBinary.c_str()); - // Test when dll is in the same directory as the exe - char **papszFiles = VSIReadDir(*papszIter); - for (char **papszFileIter = papszFiles; - papszFileIter != nullptr && *papszFileIter != nullptr; - ++papszFileIter) { - if ((STARTS_WITH_CI(*papszFileIter, "python") || - // mingw64 uses libpython3.X.dll naming - STARTS_WITH_CI(*papszFileIter, "libpython3.")) && - // do not load minimum API dll - !EQUAL(*papszFileIter, "python3.dll") && - EQUAL(CPLGetExtension(*papszFileIter), "dll")) + // Test when dll is in the same directory as the exe + const CPLStringList aosFiles(VSIReadDir(pszPathPart)); + for (const char *pszFilename : aosFiles) { - osDLLName = CPLFormFilename( - *papszIter, *papszFileIter, nullptr); - osPythonBinaryUsed = osPythonBinary; - break; + if ((STARTS_WITH_CI(pszFilename, "python") || + // mingw64 uses libpython3.X.dll naming + STARTS_WITH_CI(pszFilename, "libpython3.")) && + // do not load minimum API dll + !EQUAL(pszFilename, "python3.dll") && + EQUAL(CPLGetExtension(pszFilename), "dll")) + { + osDLLName = CPLFormFilename( + pszPathPart, pszFilename, nullptr); + osPythonBinaryUsed = osPythonBinary; + break; + } } } - CSLDestroy(papszFiles); // In python3.2, the dll is in the DLLs subdirectory if (osDLLName.empty()) { - CPLString osDLLsDir( - CPLFormFilename(*papszIter, "DLLs", nullptr)); - papszFiles = VSIReadDir(osDLLsDir); - for (char **papszFileIter = papszFiles; - papszFileIter != nullptr && - *papszFileIter != nullptr; - ++papszFileIter) + const CPLString osDLLsDir( + CPLFormFilename(pszPathPart, "DLLs", nullptr)); + const CPLStringList aosFiles(VSIReadDir(osDLLsDir)); + for (const char *pszFilename : aosFiles) { - if (STARTS_WITH_CI(*papszFileIter, "python") && - EQUAL(CPLGetExtension(*papszFileIter), "dll")) + if (STARTS_WITH_CI(pszFilename, "python") && + EQUAL(CPLGetExtension(pszFilename), "dll")) { osDLLName = CPLFormFilename( - osDLLsDir, *papszFileIter, nullptr); + osDLLsDir, pszFilename, nullptr); break; } } diff --git a/gcore/gdalrelationship.cpp b/gcore/gdalrelationship.cpp index ae41683d531e..da82ad3e57be 100644 --- a/gcore/gdalrelationship.cpp +++ b/gcore/gdalrelationship.cpp @@ -242,12 +242,7 @@ char **GDALRelationshipGetLeftTableFields(GDALRelationshipH hRelationship) auto fields = GDALRelationship::FromHandle(hRelationship)->GetLeftTableFields(); - CPLStringList res; - for (const auto &field : fields) - { - res.AddString(field.c_str()); - } - return res.StealList(); + return CPLStringList(fields).StealList(); } /************************************************************************/ @@ -273,12 +268,7 @@ char **GDALRelationshipGetRightTableFields(GDALRelationshipH hRelationship) auto fields = GDALRelationship::FromHandle(hRelationship)->GetRightTableFields(); - CPLStringList res; - for (const auto &field : fields) - { - res.AddString(field.c_str()); - } - return res.StealList(); + return CPLStringList(fields).StealList(); } /************************************************************************/ @@ -302,15 +292,8 @@ char **GDALRelationshipGetRightTableFields(GDALRelationshipH hRelationship) void GDALRelationshipSetLeftTableFields(GDALRelationshipH hRelationship, CSLConstList papszFields) { - std::vector aosFields; - if (papszFields) - { - for (auto papszIter = papszFields; *papszIter; ++papszIter) - { - aosFields.emplace_back(*papszIter); - } - } - GDALRelationship::FromHandle(hRelationship)->SetLeftTableFields(aosFields); + GDALRelationship::FromHandle(hRelationship) + ->SetLeftTableFields(cpl::ToVector(papszFields)); } /************************************************************************/ @@ -334,15 +317,8 @@ void GDALRelationshipSetLeftTableFields(GDALRelationshipH hRelationship, void GDALRelationshipSetRightTableFields(GDALRelationshipH hRelationship, CSLConstList papszFields) { - std::vector aosFields; - if (papszFields) - { - for (auto papszIter = papszFields; *papszIter; ++papszIter) - { - aosFields.emplace_back(*papszIter); - } - } - GDALRelationship::FromHandle(hRelationship)->SetRightTableFields(aosFields); + GDALRelationship::FromHandle(hRelationship) + ->SetRightTableFields(cpl::ToVector(papszFields)); } /************************************************************************/ @@ -369,12 +345,7 @@ GDALRelationshipGetLeftMappingTableFields(GDALRelationshipH hRelationship) auto fields = GDALRelationship::FromHandle(hRelationship) ->GetLeftMappingTableFields(); - CPLStringList res; - for (const auto &field : fields) - { - res.AddString(field.c_str()); - } - return res.StealList(); + return CPLStringList(fields).StealList(); } /************************************************************************/ @@ -401,12 +372,7 @@ GDALRelationshipGetRightMappingTableFields(GDALRelationshipH hRelationship) auto fields = GDALRelationship::FromHandle(hRelationship) ->GetRightMappingTableFields(); - CPLStringList res; - for (const auto &field : fields) - { - res.AddString(field.c_str()); - } - return res.StealList(); + return CPLStringList(fields).StealList(); } /************************************************************************/ @@ -430,16 +396,8 @@ GDALRelationshipGetRightMappingTableFields(GDALRelationshipH hRelationship) void GDALRelationshipSetLeftMappingTableFields(GDALRelationshipH hRelationship, CSLConstList papszFields) { - std::vector aosFields; - if (papszFields) - { - for (auto papszIter = papszFields; *papszIter; ++papszIter) - { - aosFields.emplace_back(*papszIter); - } - } GDALRelationship::FromHandle(hRelationship) - ->SetLeftMappingTableFields(aosFields); + ->SetLeftMappingTableFields(cpl::ToVector(papszFields)); } /************************************************************************/ @@ -463,16 +421,8 @@ void GDALRelationshipSetLeftMappingTableFields(GDALRelationshipH hRelationship, void GDALRelationshipSetRightMappingTableFields(GDALRelationshipH hRelationship, CSLConstList papszFields) { - std::vector aosFields; - if (papszFields) - { - for (auto papszIter = papszFields; *papszIter; ++papszIter) - { - aosFields.emplace_back(*papszIter); - } - } GDALRelationship::FromHandle(hRelationship) - ->SetRightMappingTableFields(aosFields); + ->SetRightMappingTableFields(cpl::ToVector(papszFields)); } /************************************************************************/