diff --git a/frmts/mem/memdataset.cpp b/frmts/mem/memdataset.cpp index 535e2832de1b..da0b1546d4f8 100644 --- a/frmts/mem/memdataset.cpp +++ b/frmts/mem/memdataset.cpp @@ -1675,33 +1675,18 @@ bool MEMGroup::Rename(const std::string &osNewName) } pParent->m_oMapGroups.erase(pParent->m_oMapGroups.find(m_osName)); } - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; + + BaseRename(osNewName); + if (pParent) { CPLAssert(m_pSelf.lock()); pParent->m_oMapGroups[m_osName] = m_pSelf.lock(); } - NotifyChildrenOfRenaming(); - return true; } -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void MEMGroup::ParentRenamed(const std::string &osNewParentFullName) -{ - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; - - NotifyChildrenOfRenaming(); -} - /************************************************************************/ /* NotifyChildrenOfRenaming() */ /************************************************************************/ @@ -2195,17 +2180,6 @@ bool MEMAbstractMDArray::IWrite(const GUInt64 *arrayStartIdx, return true; } -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void MEMAbstractMDArray::ParentRenamed(const std::string &osNewParentFullName) -{ - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; -} - /************************************************************************/ /* MEMMDArray() */ /************************************************************************/ @@ -2720,26 +2694,11 @@ bool MEMMDArray::Rename(const std::string &osNewName) } } - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; - - NotifyChildrenOfRenaming(); + BaseRename(osNewName); return true; } -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void MEMMDArray::ParentRenamed(const std::string &osNewParentFullName) -{ - MEMAbstractMDArray::ParentRenamed(osNewParentFullName); - - NotifyChildrenOfRenaming(); -} - /************************************************************************/ /* NotifyChildrenOfRenaming() */ /************************************************************************/ @@ -2859,9 +2818,7 @@ bool MEMAttribute::Rename(const std::string &osNewName) } } - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; + BaseRename(osNewName); m_bModified = true; @@ -2961,24 +2918,11 @@ bool MEMDimension::Rename(const std::string &osNewName) } } - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; + BaseRename(osNewName); return true; } -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void MEMDimension::ParentRenamed(const std::string &osNewParentFullName) -{ - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; -} - /************************************************************************/ /* CreateMultiDimensional() */ /************************************************************************/ diff --git a/frmts/mem/memmultidim.h b/frmts/mem/memmultidim.h index 0b5bfbab532d..3cf278d3ec81 100644 --- a/frmts/mem/memmultidim.h +++ b/frmts/mem/memmultidim.h @@ -69,8 +69,6 @@ class CPL_DLL MEMGroup CPL_NON_FINAL : public GDALGroup, std::weak_ptr m_pSelf{}; std::weak_ptr m_pParent{}; - void NotifyChildrenOfRenaming(); - protected: friend class MEMDimension; bool RenameDimension(const std::string &osOldName, @@ -80,6 +78,8 @@ class CPL_DLL MEMGroup CPL_NON_FINAL : public GDALGroup, bool RenameArray(const std::string &osOldName, const std::string &osNewName); + void NotifyChildrenOfRenaming() override; + public: MEMGroup(const std::string &osParentName, const char *pszName) : GDALGroup(osParentName, pszName ? pszName : "") @@ -144,8 +144,6 @@ class CPL_DLL MEMGroup CPL_NON_FINAL : public GDALGroup, CSLConstList papszOptions) override; bool Rename(const std::string &osNewName) override; - - void ParentRenamed(const std::string &osNewParentFullName) override; }; /************************************************************************/ @@ -237,8 +235,6 @@ class CPL_DLL MEMAbstractMDArray : virtual public GDALAbstractMDArray { m_bModified = bModified; } - - void ParentRenamed(const std::string &osNewParentFullName) override; }; /************************************************************************/ @@ -274,7 +270,7 @@ class MEMMDArray CPL_NON_FINAL : public MEMAbstractMDArray, bool Resize(const std::vector &anNewDimSizes, bool bResizeOtherArrays); - void NotifyChildrenOfRenaming(); + void NotifyChildrenOfRenaming() override; protected: MEMMDArray(const std::string &osParentName, const std::string &osName, @@ -396,8 +392,6 @@ class MEMMDArray CPL_NON_FINAL : public MEMAbstractMDArray, CSLConstList) override; bool Rename(const std::string &osNewName) override; - - void ParentRenamed(const std::string &osNewParentFullName) override; }; /************************************************************************/ @@ -465,8 +459,6 @@ class MEMDimension CPL_NON_FINAL : public GDALDimensionWeakIndexingVar return m_oSetArrays; } - void ParentRenamed(const std::string &osNewParentFullName) override; - bool Rename(const std::string &osNewName) override; }; diff --git a/frmts/netcdf/netcdfmultidim.cpp b/frmts/netcdf/netcdfmultidim.cpp index f613defef04d..f051b02b7cb0 100644 --- a/frmts/netcdf/netcdfmultidim.cpp +++ b/frmts/netcdf/netcdfmultidim.cpp @@ -246,8 +246,6 @@ class netCDFGroup final : public GDALGroup, public netCDFAttributeHolder m_oSetGroups.erase(poSubGroup); } - void NotifyChildrenOfRenaming(); - protected: friend class netCDFDimension; void RegisterDimension(GDALDimension *poDim) @@ -269,6 +267,8 @@ class netCDFGroup final : public GDALGroup, public netCDFAttributeHolder m_oSetArrays.erase(poArray); } + void NotifyChildrenOfRenaming() override; + public: netCDFGroup(const std::shared_ptr &poShared, int gid); @@ -324,8 +324,6 @@ class netCDFGroup final : public GDALGroup, public netCDFAttributeHolder void ClearStatistics() override; bool Rename(const std::string &osNewName) override; - - void ParentRenamed(const std::string &osNewParentFullName) override; }; /************************************************************************/ @@ -407,8 +405,6 @@ class netCDFDimension final : public GDALDimension } bool Rename(const std::string &osNewName) override; - - void ParentRenamed(const std::string &osNewParentFullName) override; }; /************************************************************************/ @@ -479,8 +475,6 @@ class netCDFAttribute final : public GDALAttribute const GDALExtendedDataType &GetDataType() const override; bool Rename(const std::string &osNewName) override; - - void ParentRenamed(const std::string &osNewParentFullName) override; }; /************************************************************************/ @@ -544,8 +538,6 @@ class netCDFVariable final : public GDALPamMDArray, public netCDFAttributeHolder NCGetPutVarmFuncType NCGetPutVarmFunc, ReadOrWriteOneElementType ReadOrWriteOneElement) const; - void NotifyChildrenOfRenaming(); - protected: netCDFVariable(const std::shared_ptr &poShared, int gid, int varid, @@ -571,6 +563,8 @@ class netCDFVariable final : public GDALPamMDArray, public netCDFAttributeHolder bool IAdviseRead(const GUInt64 *arrayStartIdx, const size_t *count, CSLConstList papszOptions) const override; + void NotifyChildrenOfRenaming() override; + public: static std::shared_ptr Create(const std::shared_ptr &poShared, @@ -675,8 +669,6 @@ class netCDFVariable final : public GDALPamMDArray, public netCDFAttributeHolder } bool Rename(const std::string &osNewName) override; - - void ParentRenamed(const std::string &osNewParentFullName) override; }; /************************************************************************/ @@ -1417,28 +1409,11 @@ bool netCDFGroup::Rename(const std::string &osNewName) if (ret != NC_NOERR) return false; - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; - - NotifyChildrenOfRenaming(); + BaseRename(osNewName); return true; } -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void netCDFGroup::ParentRenamed(const std::string &osNewParentFullName) -{ - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; - - NotifyChildrenOfRenaming(); -} - /************************************************************************/ /* NotifyChildrenOfRenaming() */ /************************************************************************/ @@ -1959,17 +1934,6 @@ std::shared_ptr netCDFDimension::GetIndexingVariable() const return candidateIndexingVariable; } -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void netCDFDimension::ParentRenamed(const std::string &osNewParentFullName) -{ - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; -} - /************************************************************************/ /* Rename() */ /************************************************************************/ @@ -1995,9 +1959,7 @@ bool netCDFDimension::Rename(const std::string &osNewName) if (ret != NC_NOERR) return false; - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; + BaseRename(osNewName); return true; } @@ -4087,28 +4049,11 @@ bool netCDFVariable::Rename(const std::string &osNewName) if (ret != NC_NOERR) return false; - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; - - NotifyChildrenOfRenaming(); + BaseRename(osNewName); return true; } -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void netCDFVariable::ParentRenamed(const std::string &osNewParentFullName) -{ - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; - - NotifyChildrenOfRenaming(); -} - /************************************************************************/ /* NotifyChildrenOfRenaming() */ /************************************************************************/ @@ -4676,23 +4621,11 @@ bool netCDFAttribute::Rename(const std::string &osNewName) if (ret != NC_NOERR) return false; - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; + BaseRename(osNewName); return true; } -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void netCDFAttribute::ParentRenamed(const std::string &osNewParentFullName) -{ - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; -} /************************************************************************/ /* OpenMultiDim() */ /************************************************************************/ diff --git a/frmts/zarr/zarr.h b/frmts/zarr/zarr.h index 19153e05d8bb..89b1946ba0c6 100644 --- a/frmts/zarr/zarr.h +++ b/frmts/zarr/zarr.h @@ -337,7 +337,7 @@ class ZarrGroupBase CPL_NON_FINAL : public GDALGroup bool RenameDimension(const std::string &osOldName, const std::string &osNewName); - void NotifyChildrenOfRenaming(); + void NotifyChildrenOfRenaming() override; public: ~ZarrGroupBase() override; @@ -573,8 +573,6 @@ class ZarrDimension final : public GDALDimensionWeakIndexingVar bool Rename(const std::string &osNewName) override; - void ParentRenamed(const std::string &osNewParentFullName) override; - bool IsModified() const { return m_bModified; @@ -764,7 +762,7 @@ class ZarrArray CPL_NON_FINAL : public GDALPamMDArray std::shared_ptr OpenTilePresenceCache(bool bCanCreate) const; - void NotifyChildrenOfRenaming(); + void NotifyChildrenOfRenaming() override; static void EncodeElt(const std::vector &elts, const GByte *pSrc, GByte *pDst); diff --git a/frmts/zarr/zarr_array.cpp b/frmts/zarr/zarr_array.cpp index 2147253bd4b4..65531fc011d3 100644 --- a/frmts/zarr/zarr_array.cpp +++ b/frmts/zarr/zarr_array.cpp @@ -2527,9 +2527,7 @@ void ZarrArray::NotifyChildrenOfRenaming() void ZarrArray::ParentRenamed(const std::string &osNewParentFullName) { - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; + GDALMDArray::ParentRenamed(osNewParentFullName); auto poParent = m_poGroupWeak.lock(); // The parent necessarily exist, since it notified us @@ -2539,8 +2537,6 @@ void ZarrArray::ParentRenamed(const std::string &osNewParentFullName) CPLFormFilename(CPLFormFilename(poParent->GetDirectoryName().c_str(), m_osName.c_str(), nullptr), CPLGetFilename(m_osFilename.c_str()), nullptr); - - NotifyChildrenOfRenaming(); } /************************************************************************/ @@ -2600,11 +2596,7 @@ bool ZarrArray::Rename(const std::string &osNewName) poParent->NotifyArrayRenamed(m_osName, osNewName); } - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; - - NotifyChildrenOfRenaming(); + BaseRename(osNewName); return true; } diff --git a/frmts/zarr/zarr_dimension.cpp b/frmts/zarr/zarr_dimension.cpp index 27838ebef210..73aed9d0d4e7 100644 --- a/frmts/zarr/zarr_dimension.cpp +++ b/frmts/zarr/zarr_dimension.cpp @@ -61,22 +61,9 @@ bool ZarrDimension::Rename(const std::string &osNewName) } } - m_osFullName.resize(m_osFullName.size() - m_osName.size()); - m_osFullName += osNewName; - m_osName = osNewName; + BaseRename(osNewName); m_bModified = true; return true; } - -/************************************************************************/ -/* ParentRenamed() */ -/************************************************************************/ - -void ZarrDimension::ParentRenamed(const std::string &osNewParentFullName) -{ - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; -} diff --git a/frmts/zarr/zarr_group.cpp b/frmts/zarr/zarr_group.cpp index 3aff55fe150c..b4309e4eebde 100644 --- a/frmts/zarr/zarr_group.cpp +++ b/frmts/zarr/zarr_group.cpp @@ -341,15 +341,9 @@ bool ZarrGroupBase::Rename(const std::string &osNewName) m_poSharedResource->RenameZMetadataRecursive(m_osDirectoryName, osNewDirectoryName); - std::string osNewFullName(m_osFullName); - osNewFullName.resize(osNewFullName.size() - m_osName.size()); - osNewFullName += osNewName; - m_osDirectoryName = osNewDirectoryName; - m_osFullName = osNewFullName; - m_osName = osNewName; - NotifyChildrenOfRenaming(); + BaseRename(osNewName); return true; } @@ -367,11 +361,7 @@ void ZarrGroupBase::ParentRenamed(const std::string &osNewParentFullName) m_osDirectoryName = CPLFormFilename(pParent->m_osDirectoryName.c_str(), m_osName.c_str(), nullptr); - m_osFullName = osNewParentFullName; - m_osFullName += "/"; - m_osFullName += m_osName; - - NotifyChildrenOfRenaming(); + GDALGroup::ParentRenamed(osNewParentFullName); } /************************************************************************/ diff --git a/gcore/gdal_priv.h b/gcore/gdal_priv.h index def03dd45969..b658cfe97ba7 100644 --- a/gcore/gdal_priv.h +++ b/gcore/gdal_priv.h @@ -2282,6 +2282,12 @@ class CPL_DLL GDALGroup : public GDALIHasAttribute GetInnerMostGroup(const std::string &osPathOrArrayOrDim, std::shared_ptr &curGroupHolder, std::string &osLastPart) const; + + void BaseRename(const std::string &osNewName); + + virtual void NotifyChildrenOfRenaming() + { + } //! @endcond public: @@ -2372,10 +2378,7 @@ class CPL_DLL GDALGroup : public GDALIHasAttribute virtual bool Rename(const std::string &osNewName); //! @cond Doxygen_Suppress - virtual void - ParentRenamed(CPL_UNUSED const std::string &osNewParentFullName) - { - } + virtual void ParentRenamed(const std::string &osNewParentFullName); //! @endcond //! @cond Doxygen_Suppress @@ -2432,6 +2435,13 @@ class CPL_DLL GDALAbstractMDArray const GInt64 *arrayStep, // step in elements const GPtrDiff_t *bufferStride, // stride in elements const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer); + + void BaseRename(const std::string &osNewName); + + virtual void NotifyChildrenOfRenaming() + { + } + //! @endcond public: @@ -2522,10 +2532,7 @@ class CPL_DLL GDALAbstractMDArray virtual bool Rename(const std::string &osNewName); //! @cond Doxygen_Suppress - virtual void - ParentRenamed(CPL_UNUSED const std::string &osNewParentFullName) - { - } + virtual void ParentRenamed(const std::string &osNewParentFullName); //! @endcond }; @@ -2770,6 +2777,7 @@ class CPL_DLL GDALMDArray : virtual public GDALAbstractMDArray, const GPtrDiff_t *bufferStride, const GDALExtendedDataType &bufferDataType, void *pDstBuffer) const; + //! @endcond public: @@ -3109,10 +3117,7 @@ class CPL_DLL GDALDimension virtual bool Rename(const std::string &osNewName); //! @cond Doxygen_Suppress - virtual void - ParentRenamed(CPL_UNUSED const std::string &osNewParentFullName) - { - } + virtual void ParentRenamed(const std::string &osNewParentFullName); //! @endcond protected: @@ -3122,6 +3127,9 @@ class CPL_DLL GDALDimension std::string m_osType; std::string m_osDirection; GUInt64 m_nSize; + + void BaseRename(const std::string &osNewName); + //! @endcond }; diff --git a/gcore/gdalmultidim.cpp b/gcore/gdalmultidim.cpp index aeb0fd6122ac..9f2b36694c61 100644 --- a/gcore/gdalmultidim.cpp +++ b/gcore/gdalmultidim.cpp @@ -1336,6 +1336,36 @@ bool GDALGroup::Rename(CPL_UNUSED const std::string &osNewName) return false; } +/************************************************************************/ +/* BaseRename() */ +/************************************************************************/ + +//! @cond Doxygen_Suppress +void GDALGroup::BaseRename(const std::string &osNewName) +{ + m_osFullName.resize(m_osFullName.size() - m_osName.size()); + m_osFullName += osNewName; + m_osName = osNewName; + + NotifyChildrenOfRenaming(); +} +//! @endcond + +/************************************************************************/ +/* ParentRenamed() */ +/************************************************************************/ + +//! @cond Doxygen_Suppress +void GDALGroup::ParentRenamed(const std::string &osNewParentFullName) +{ + m_osFullName = osNewParentFullName; + m_osFullName += "/"; + m_osFullName += m_osName; + + NotifyChildrenOfRenaming(); +} +//! @endcond + /************************************************************************/ /* ~GDALAbstractMDArray() */ /************************************************************************/ @@ -2235,6 +2265,36 @@ GDALAbstractMDArray::GetProcessingChunkSize(size_t nMaxChunkMemory) const return anChunkSize; } +/************************************************************************/ +/* BaseRename() */ +/************************************************************************/ + +//! @cond Doxygen_Suppress +void GDALAbstractMDArray::BaseRename(const std::string &osNewName) +{ + m_osFullName.resize(m_osFullName.size() - m_osName.size()); + m_osFullName += osNewName; + m_osName = osNewName; + + NotifyChildrenOfRenaming(); +} +//! @endcond + +//! @cond Doxygen_Suppress +/************************************************************************/ +/* ParentRenamed() */ +/************************************************************************/ + +void GDALAbstractMDArray::ParentRenamed(const std::string &osNewParentFullName) +{ + m_osFullName = osNewParentFullName; + m_osFullName += "/"; + m_osFullName += m_osName; + + NotifyChildrenOfRenaming(); +} +//! @endcond + /************************************************************************/ /* SetUnit() */ /************************************************************************/ @@ -8956,6 +9016,33 @@ bool GDALDimension::Rename(CPL_UNUSED const std::string &osNewName) return false; } +/************************************************************************/ +/* BaseRename() */ +/************************************************************************/ + +//! @cond Doxygen_Suppress +void GDALDimension::BaseRename(const std::string &osNewName) +{ + m_osFullName.resize(m_osFullName.size() - m_osName.size()); + m_osFullName += osNewName; + m_osName = osNewName; +} +//! @endcond + +//! @cond Doxygen_Suppress +/************************************************************************/ +/* ParentRenamed() */ +/************************************************************************/ + +void GDALDimension::ParentRenamed(const std::string &osNewParentFullName) +{ + m_osFullName = osNewParentFullName; + m_osFullName += "/"; + m_osFullName += m_osName; +} + +//! @endcond + /************************************************************************/ /************************************************************************/ /************************************************************************/