Skip to content

Commit

Permalink
Multidim rename: factor code related to changing m_osFullName and add…
Browse files Browse the repository at this point in the history
… a NotifyChildrenOfRenaming() virtual method
  • Loading branch information
rouault committed May 8, 2023
1 parent 2e647df commit c81d12f
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 200 deletions.
68 changes: 6 additions & 62 deletions frmts/mem/memdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() */
/************************************************************************/
Expand Down Expand Up @@ -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() */
/************************************************************************/
Expand Down Expand Up @@ -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() */
/************************************************************************/
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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() */
/************************************************************************/
Expand Down
14 changes: 3 additions & 11 deletions frmts/mem/memmultidim.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class CPL_DLL MEMGroup CPL_NON_FINAL : public GDALGroup,
std::weak_ptr<MEMGroup> m_pSelf{};
std::weak_ptr<MEMGroup> m_pParent{};

void NotifyChildrenOfRenaming();

protected:
friend class MEMDimension;
bool RenameDimension(const std::string &osOldName,
Expand All @@ -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 : "")
Expand Down Expand Up @@ -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;
};

/************************************************************************/
Expand Down Expand Up @@ -237,8 +235,6 @@ class CPL_DLL MEMAbstractMDArray : virtual public GDALAbstractMDArray
{
m_bModified = bModified;
}

void ParentRenamed(const std::string &osNewParentFullName) override;
};

/************************************************************************/
Expand Down Expand Up @@ -274,7 +270,7 @@ class MEMMDArray CPL_NON_FINAL : public MEMAbstractMDArray,
bool Resize(const std::vector<GUInt64> &anNewDimSizes,
bool bResizeOtherArrays);

void NotifyChildrenOfRenaming();
void NotifyChildrenOfRenaming() override;

protected:
MEMMDArray(const std::string &osParentName, const std::string &osName,
Expand Down Expand Up @@ -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;
};

/************************************************************************/
Expand Down Expand Up @@ -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;
};

Expand Down
83 changes: 8 additions & 75 deletions frmts/netcdf/netcdfmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -269,6 +267,8 @@ class netCDFGroup final : public GDALGroup, public netCDFAttributeHolder
m_oSetArrays.erase(poArray);
}

void NotifyChildrenOfRenaming() override;

public:
netCDFGroup(const std::shared_ptr<netCDFSharedResources> &poShared,
int gid);
Expand Down Expand Up @@ -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;
};

/************************************************************************/
Expand Down Expand Up @@ -407,8 +405,6 @@ class netCDFDimension final : public GDALDimension
}

bool Rename(const std::string &osNewName) override;

void ParentRenamed(const std::string &osNewParentFullName) override;
};

/************************************************************************/
Expand Down Expand Up @@ -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;
};

/************************************************************************/
Expand Down Expand Up @@ -544,8 +538,6 @@ class netCDFVariable final : public GDALPamMDArray, public netCDFAttributeHolder
NCGetPutVarmFuncType NCGetPutVarmFunc,
ReadOrWriteOneElementType ReadOrWriteOneElement) const;

void NotifyChildrenOfRenaming();

protected:
netCDFVariable(const std::shared_ptr<netCDFSharedResources> &poShared,
int gid, int varid,
Expand All @@ -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<netCDFVariable>
Create(const std::shared_ptr<netCDFSharedResources> &poShared,
Expand Down Expand Up @@ -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;
};

/************************************************************************/
Expand Down Expand Up @@ -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() */
/************************************************************************/
Expand Down Expand Up @@ -1959,17 +1934,6 @@ std::shared_ptr<GDALMDArray> netCDFDimension::GetIndexingVariable() const
return candidateIndexingVariable;
}

/************************************************************************/
/* ParentRenamed() */
/************************************************************************/

void netCDFDimension::ParentRenamed(const std::string &osNewParentFullName)
{
m_osFullName = osNewParentFullName;
m_osFullName += "/";
m_osFullName += m_osName;
}

/************************************************************************/
/* Rename() */
/************************************************************************/
Expand All @@ -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;
}
Expand Down Expand Up @@ -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() */
/************************************************************************/
Expand Down Expand Up @@ -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() */
/************************************************************************/
Expand Down
6 changes: 2 additions & 4 deletions frmts/zarr/zarr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -764,7 +762,7 @@ class ZarrArray CPL_NON_FINAL : public GDALPamMDArray

std::shared_ptr<GDALMDArray> OpenTilePresenceCache(bool bCanCreate) const;

void NotifyChildrenOfRenaming();
void NotifyChildrenOfRenaming() override;

static void EncodeElt(const std::vector<DtypeElt> &elts, const GByte *pSrc,
GByte *pDst);
Expand Down
Loading

0 comments on commit c81d12f

Please sign in to comment.