Skip to content

Commit

Permalink
Merge pull request #9262 from rouault/xmlinit_const
Browse files Browse the repository at this point in the history
GDALDeserializeGCPListFromXML(), VRT and PAMDataset XMLInit(): make it take a const CPLXMLNode*
  • Loading branch information
rouault authored Feb 26, 2024
2 parents 82159d0 + e274363 commit 64cf9b4
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 141 deletions.
28 changes: 12 additions & 16 deletions frmts/vrt/vrtdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ VRTRasterBand *VRTDataset::InitBand(const char *pszSubclass, int nBand,
/* XMLInit() */
/************************************************************************/

CPLErr VRTDataset::XMLInit(CPLXMLNode *psTree, const char *pszVRTPathIn)
CPLErr VRTDataset::XMLInit(const CPLXMLNode *psTree, const char *pszVRTPathIn)

{
if (pszVRTPathIn != nullptr)
Expand All @@ -443,7 +443,7 @@ CPLErr VRTDataset::XMLInit(CPLXMLNode *psTree, const char *pszVRTPathIn)
/* -------------------------------------------------------------------- */
/* Check for an SRS node. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psSRSNode = CPLGetXMLNode(psTree, "SRS");
const CPLXMLNode *psSRSNode = CPLGetXMLNode(psTree, "SRS");
if (psSRSNode)
{
if (m_poSRS)
Expand Down Expand Up @@ -480,31 +480,28 @@ CPLErr VRTDataset::XMLInit(CPLXMLNode *psTree, const char *pszVRTPathIn)
/* -------------------------------------------------------------------- */
/* Check for a GeoTransform node. */
/* -------------------------------------------------------------------- */
if (strlen(CPLGetXMLValue(psTree, "GeoTransform", "")) > 0)
const char *pszGT = CPLGetXMLValue(psTree, "GeoTransform", "");
if (strlen(pszGT) > 0)
{
const char *pszGT = CPLGetXMLValue(psTree, "GeoTransform", "");
char **papszTokens = CSLTokenizeStringComplex(pszGT, ",", FALSE, FALSE);
if (CSLCount(papszTokens) != 6)
const CPLStringList aosTokens(
CSLTokenizeStringComplex(pszGT, ",", FALSE, FALSE));
if (aosTokens.size() != 6)
{
CPLError(CE_Warning, CPLE_AppDefined,
"GeoTransform node does not have expected six values.");
}
else
{
for (int iTA = 0; iTA < 6; iTA++)
m_adfGeoTransform[iTA] = CPLAtof(papszTokens[iTA]);
m_adfGeoTransform[iTA] = CPLAtof(aosTokens[iTA]);
m_bGeoTransformSet = TRUE;
}

CSLDestroy(papszTokens);
}

/* -------------------------------------------------------------------- */
/* Check for GCPs. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psGCPList = CPLGetXMLNode(psTree, "GCPList");

if (psGCPList != nullptr)
if (const CPLXMLNode *psGCPList = CPLGetXMLNode(psTree, "GCPList"))
{
GDALDeserializeGCPListFromXML(psGCPList, &m_pasGCPList, &m_nGCPCount,
&m_poGCP_SRS);
Expand All @@ -520,9 +517,9 @@ CPLErr VRTDataset::XMLInit(CPLXMLNode *psTree, const char *pszVRTPathIn)
/* -------------------------------------------------------------------- */

/* Parse dataset mask band first */
CPLXMLNode *psMaskBandNode = CPLGetXMLNode(psTree, "MaskBand");
const CPLXMLNode *psMaskBandNode = CPLGetXMLNode(psTree, "MaskBand");

CPLXMLNode *psChild = nullptr;
const CPLXMLNode *psChild = nullptr;
if (psMaskBandNode)
psChild = psMaskBandNode->psChild;
else
Expand Down Expand Up @@ -581,8 +578,7 @@ CPLErr VRTDataset::XMLInit(CPLXMLNode *psTree, const char *pszVRTPathIn)
}
}

CPLXMLNode *psGroup = CPLGetXMLNode(psTree, "Group");
if (psGroup)
if (const CPLXMLNode *psGroup = CPLGetXMLNode(psTree, "Group"))
{
const char *pszName = CPLGetXMLValue(psGroup, "name", nullptr);
if (pszName == nullptr || !EQUAL(pszName, "/"))
Expand Down
40 changes: 20 additions & 20 deletions frmts/vrt/vrtdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class CPL_DLL VRTSource
int bApproxOK, GDALProgressFunc pfnProgress,
void *pProgressData) = 0;

virtual CPLErr XMLInit(CPLXMLNode *psTree, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
std::map<CPLString, GDALDataset *> &) = 0;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) = 0;

Expand All @@ -172,17 +172,17 @@ class CPL_DLL VRTSource
};

typedef VRTSource *(*VRTSourceParser)(
CPLXMLNode *, const char *,
const CPLXMLNode *, const char *,
std::map<CPLString, GDALDataset *> &oMapSharedSources);

VRTSource *
VRTParseCoreSources(CPLXMLNode *psTree, const char *,
VRTParseCoreSources(const CPLXMLNode *psTree, const char *,
std::map<CPLString, GDALDataset *> &oMapSharedSources);
VRTSource *
VRTParseFilterSources(CPLXMLNode *psTree, const char *,
VRTParseFilterSources(const CPLXMLNode *psTree, const char *,
std::map<CPLString, GDALDataset *> &oMapSharedSources);
VRTSource *
VRTParseArraySource(CPLXMLNode *psTree, const char *,
VRTParseArraySource(const CPLXMLNode *psTree, const char *,
std::map<CPLString, GDALDataset *> &oMapSharedSources);

/************************************************************************/
Expand Down Expand Up @@ -335,7 +335,7 @@ class CPL_DLL VRTDataset CPL_NON_FINAL : public GDALDataset
char **papszOptions) override;

virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath);
virtual CPLErr XMLInit(CPLXMLNode *, const char *);
virtual CPLErr XMLInit(const CPLXMLNode *, const char *);

virtual CPLErr IBuildOverviews(const char *, int, const int *, int,
const int *, GDALProgressFunc, void *,
Expand Down Expand Up @@ -419,7 +419,7 @@ class CPL_DLL VRTWarpedDataset final : public VRTDataset
const char *pszDomain = "") override;

virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
virtual CPLErr XMLInit(CPLXMLNode *, const char *) override;
virtual CPLErr XMLInit(const CPLXMLNode *, const char *) override;

virtual CPLErr AddBand(GDALDataType eType,
char **papszOptions = nullptr) override;
Expand Down Expand Up @@ -481,10 +481,10 @@ class VRTPansharpenedDataset final : public VRTDataset

virtual CPLErr FlushCache(bool bAtClosing) override;

virtual CPLErr XMLInit(CPLXMLNode *, const char *) override;
virtual CPLErr XMLInit(const CPLXMLNode *, const char *) override;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;

CPLErr XMLInit(CPLXMLNode *psTree, const char *pszVRTPath,
CPLErr XMLInit(const CPLXMLNode *psTree, const char *pszVRTPath,
GDALRasterBandH hPanchroBandIn, int nInputSpectralBandsIn,
GDALRasterBandH *pahInputSpectralBandsIn);

Expand Down Expand Up @@ -567,7 +567,7 @@ class CPL_DLL VRTRasterBand CPL_NON_FINAL : public GDALRasterBand
VRTRasterBand();
virtual ~VRTRasterBand();

virtual CPLErr XMLInit(CPLXMLNode *, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
std::map<CPLString, GDALDataset *> &);
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
bool &bHasWarnedAboutRAMUsage,
Expand Down Expand Up @@ -709,7 +709,7 @@ class CPL_DLL VRTSourcedRasterBand CPL_NON_FINAL : public VRTRasterBand
virtual CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
const char *pszDomain = "") override;

virtual CPLErr XMLInit(CPLXMLNode *, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
std::map<CPLString, GDALDataset *> &) override;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
bool &bHasWarnedAboutRAMUsage,
Expand Down Expand Up @@ -916,7 +916,7 @@ class CPL_DLL VRTDerivedRasterBand CPL_NON_FINAL : public VRTSourcedRasterBand
void SetSourceTransferType(GDALDataType eDataType);
void SetPixelFunctionLanguage(const char *pszLanguage);

virtual CPLErr XMLInit(CPLXMLNode *, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
std::map<CPLString, GDALDataset *> &) override;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
bool &bHasWarnedAboutRAMUsage,
Expand Down Expand Up @@ -959,7 +959,7 @@ class CPL_DLL VRTRawRasterBand CPL_NON_FINAL : public VRTRasterBand
GDALDataType eType = GDT_Unknown);
virtual ~VRTRawRasterBand();

virtual CPLErr XMLInit(CPLXMLNode *, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
std::map<CPLString, GDALDataset *> &) override;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath,
bool &bHasWarnedAboutRAMUsage,
Expand Down Expand Up @@ -1010,7 +1010,7 @@ class VRTDriver final : public GDALDriver
const char *pszDomain = "") override;

VRTSource *
ParseSource(CPLXMLNode *psSrc, const char *pszVRTPath,
ParseSource(const CPLXMLNode *psSrc, const char *pszVRTPath,
std::map<CPLString, GDALDataset *> &oMapSharedSources);
void AddSourceParser(const char *pszElementName, VRTSourceParser pfnParser);
};
Expand Down Expand Up @@ -1091,7 +1091,7 @@ class CPL_DLL VRTSimpleSource CPL_NON_FINAL : public VRTSource
double dfYDstRatio);
virtual ~VRTSimpleSource();

virtual CPLErr XMLInit(CPLXMLNode *psTree, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
std::map<CPLString, GDALDataset *> &) override;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;

Expand Down Expand Up @@ -1240,7 +1240,7 @@ class VRTNoDataFromMaskSource final : public VRTSimpleSource
void SetParameters(double dfNoDataValue, double dfMaskValueThreshold,
double dfRemappedValue);

virtual CPLErr XMLInit(CPLXMLNode *psTree, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
std::map<CPLString, GDALDataset *> &) override;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
virtual const char *GetType() override
Expand Down Expand Up @@ -1332,7 +1332,7 @@ class CPL_DLL VRTComplexSource CPL_NON_FINAL : public VRTSimpleSource
void *pProgressData) override;

virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
virtual CPLErr XMLInit(CPLXMLNode *, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
std::map<CPLString, GDALDataset *> &) override;
virtual const char *GetType() override
{
Expand Down Expand Up @@ -1415,7 +1415,7 @@ class VRTKernelFilteredSource CPL_NON_FINAL : public VRTFilteredSource
VRTKernelFilteredSource();
virtual ~VRTKernelFilteredSource();

virtual CPLErr XMLInit(CPLXMLNode *psTree, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
std::map<CPLString, GDALDataset *> &) override;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;

Expand All @@ -1438,7 +1438,7 @@ class VRTAverageFilteredSource final : public VRTKernelFilteredSource
explicit VRTAverageFilteredSource(int nKernelSize);
virtual ~VRTAverageFilteredSource();

virtual CPLErr XMLInit(CPLXMLNode *psTree, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *psTree, const char *,
std::map<CPLString, GDALDataset *> &) override;
virtual CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
};
Expand All @@ -1454,7 +1454,7 @@ class VRTFuncSource final : public VRTSource
VRTFuncSource();
virtual ~VRTFuncSource();

virtual CPLErr XMLInit(CPLXMLNode *, const char *,
virtual CPLErr XMLInit(const CPLXMLNode *, const char *,
std::map<CPLString, GDALDataset *> &) override
{
return CE_Failure;
Expand Down
7 changes: 4 additions & 3 deletions frmts/vrt/vrtderivedrasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ int VRTDerivedRasterBand::IGetDataCoverageStatus(
/************************************************************************/

CPLErr VRTDerivedRasterBand::XMLInit(
CPLXMLNode *psTree, const char *pszVRTPath,
const CPLXMLNode *psTree, const char *pszVRTPath,
std::map<CPLString, GDALDataset *> &oMapSharedSources)

{
Expand Down Expand Up @@ -1468,10 +1468,11 @@ CPLErr VRTDerivedRasterBand::XMLInit(
return CE_Failure;
}

CPLXMLNode *psArgs = CPLGetXMLNode(psTree, "PixelFunctionArguments");
const CPLXMLNode *const psArgs =
CPLGetXMLNode(psTree, "PixelFunctionArguments");
if (psArgs != nullptr)
{
for (CPLXMLNode *psIter = psArgs->psChild; psIter != nullptr;
for (const CPLXMLNode *psIter = psArgs->psChild; psIter;
psIter = psIter->psNext)
{
if (psIter->eType == CXT_Attribute)
Expand Down
2 changes: 1 addition & 1 deletion frmts/vrt/vrtdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void VRTDriver::AddSourceParser(const char *pszElementName,
/************************************************************************/

VRTSource *
VRTDriver::ParseSource(CPLXMLNode *psSrc, const char *pszVRTPath,
VRTDriver::ParseSource(const CPLXMLNode *psSrc, const char *pszVRTPath,
std::map<CPLString, GDALDataset *> &oMapSharedSources)

{
Expand Down
4 changes: 2 additions & 2 deletions frmts/vrt/vrtfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ CPLErr VRTKernelFilteredSource::FilterData(int nXSize, int nYSize,
/************************************************************************/

CPLErr VRTKernelFilteredSource::XMLInit(
CPLXMLNode *psTree, const char *pszVRTPath,
const CPLXMLNode *psTree, const char *pszVRTPath,
std::map<CPLString, GDALDataset *> &oMapSharedSources)

{
Expand Down Expand Up @@ -705,7 +705,7 @@ CPLXMLNode *VRTKernelFilteredSource::SerializeToXML(const char *pszVRTPath)
/************************************************************************/

VRTSource *
VRTParseFilterSources(CPLXMLNode *psChild, const char *pszVRTPath,
VRTParseFilterSources(const CPLXMLNode *psChild, const char *pszVRTPath,
std::map<CPLString, GDALDataset *> &oMapSharedSources)

{
Expand Down
6 changes: 3 additions & 3 deletions frmts/vrt/vrtmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,7 @@ class VRTArraySource : public VRTSource
}

CPLErr
XMLInit(CPLXMLNode *psTree, const char *pszVRTPath,
XMLInit(const CPLXMLNode *psTree, const char *pszVRTPath,
std::map<CPLString, GDALDataset *> &oMapSharedSources) override;
CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;
};
Expand Down Expand Up @@ -2706,7 +2706,7 @@ ParseSingleSourceArray(const CPLXMLNode *psSingleSourceArray,
/************************************************************************/

CPLErr VRTArraySource::XMLInit(
CPLXMLNode *psTree, const char *pszVRTPath,
const CPLXMLNode *psTree, const char *pszVRTPath,
std::map<CPLString, GDALDataset *> & /*oMapSharedSources*/)
{
const auto poArray = ParseArray(psTree, pszVRTPath, "ArraySource");
Expand Down Expand Up @@ -2978,7 +2978,7 @@ static std::shared_ptr<GDALMDArray> ParseArray(const CPLXMLNode *psTree,
/************************************************************************/

VRTSource *
VRTParseArraySource(CPLXMLNode *psChild, const char *pszVRTPath,
VRTParseArraySource(const CPLXMLNode *psChild, const char *pszVRTPath,
std::map<CPLString, GDALDataset *> &oMapSharedSources)
{
VRTSource *poSource = nullptr;
Expand Down
15 changes: 8 additions & 7 deletions frmts/vrt/vrtpansharpened.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ char **VRTPansharpenedDataset::GetFileList()
/* XMLInit() */
/************************************************************************/

CPLErr VRTPansharpenedDataset::XMLInit(CPLXMLNode *psTree,
CPLErr VRTPansharpenedDataset::XMLInit(const CPLXMLNode *psTree,
const char *pszVRTPathIn)

{
return XMLInit(psTree, pszVRTPathIn, nullptr, 0, nullptr);
}

CPLErr VRTPansharpenedDataset::XMLInit(CPLXMLNode *psTree,
CPLErr VRTPansharpenedDataset::XMLInit(const CPLXMLNode *psTree,
const char *pszVRTPathIn,
GDALRasterBandH hPanchroBandIn,
int nInputSpectralBandsIn,
Expand All @@ -299,7 +299,7 @@ CPLErr VRTPansharpenedDataset::XMLInit(CPLXMLNode *psTree,
/* Parse PansharpeningOptions */
/* -------------------------------------------------------------------- */

CPLXMLNode *psOptions = CPLGetXMLNode(psTree, "PansharpeningOptions");
const CPLXMLNode *psOptions = CPLGetXMLNode(psTree, "PansharpeningOptions");
if (psOptions == nullptr)
{
CPLError(CE_Failure, CPLE_AppDefined, "Missing PansharpeningOptions");
Expand All @@ -325,7 +325,8 @@ CPLErr VRTPansharpenedDataset::XMLInit(CPLXMLNode *psTree,

if (hPanchroBandIn == nullptr)
{
CPLXMLNode *psPanchroBand = CPLGetXMLNode(psOptions, "PanchroBand");
const CPLXMLNode *psPanchroBand =
CPLGetXMLNode(psOptions, "PanchroBand");
if (psPanchroBand == nullptr)
{
CPLError(CE_Failure, CPLE_AppDefined, "PanchroBand missing");
Expand Down Expand Up @@ -433,8 +434,8 @@ CPLErr VRTPansharpenedDataset::XMLInit(CPLXMLNode *psTree,
}

std::vector<double> adfWeights;
CPLXMLNode *psAlgOptions = CPLGetXMLNode(psOptions, "AlgorithmOptions");
if (psAlgOptions != nullptr)
if (const CPLXMLNode *psAlgOptions =
CPLGetXMLNode(psOptions, "AlgorithmOptions"))
{
const char *pszWeights =
CPLGetXMLValue(psAlgOptions, "Weights", nullptr);
Expand Down Expand Up @@ -499,7 +500,7 @@ CPLErr VRTPansharpenedDataset::XMLInit(CPLXMLNode *psTree,
/* First pass on spectral datasets to check their georeferencing. */
/* -------------------------------------------------------------------- */
int iSpectralBand = 0;
for (CPLXMLNode *psIter = psOptions->psChild; psIter;
for (const CPLXMLNode *psIter = psOptions->psChild; psIter;
psIter = psIter->psNext)
{
GDALDataset *poDataset;
Expand Down
Loading

0 comments on commit 64cf9b4

Please sign in to comment.