Skip to content

Commit

Permalink
Avoid some duplicate code by moving identical methods to base class
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 22, 2024
1 parent 502f1a3 commit 9d207db
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 95 deletions.
6 changes: 0 additions & 6 deletions ogr/ogrsf_frmts/gpkg/ogr_geopackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,6 @@ class GDALGeoPackageDataset final : public OGRSQLiteBaseDataSource,
bool AddFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
std::string &failureReason) override;

std::vector<std::string>
GetRelationshipNames(CSLConstList papszOptions = nullptr) const override;

const GDALRelationship *
GetRelationship(const std::string &name) const override;

bool AddRelationship(std::unique_ptr<GDALRelationship> &&relationship,
std::string &failureReason) override;

Expand Down
39 changes: 0 additions & 39 deletions ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9823,45 +9823,6 @@ bool GDALGeoPackageDataset::AddFieldDomain(
return true;
}

/************************************************************************/
/* GetRelationshipNames() */
/************************************************************************/

std::vector<std::string> GDALGeoPackageDataset::GetRelationshipNames(
CPL_UNUSED CSLConstList papszOptions) const

{
if (!m_bHasPopulatedRelationships)
LoadRelationships();

std::vector<std::string> oasNames;
oasNames.reserve(m_osMapRelationships.size());
for (auto it = m_osMapRelationships.begin();
it != m_osMapRelationships.end(); ++it)
{
oasNames.emplace_back(it->first);
}
return oasNames;
}

/************************************************************************/
/* GetRelationship() */
/************************************************************************/

const GDALRelationship *
GDALGeoPackageDataset::GetRelationship(const std::string &name) const

{
if (!m_bHasPopulatedRelationships)
LoadRelationships();

auto it = m_osMapRelationships.find(name);
if (it == m_osMapRelationships.end())
return nullptr;

return it->second.get();
}

/************************************************************************/
/* AddRelationship() */
/************************************************************************/
Expand Down
6 changes: 0 additions & 6 deletions ogr/ogrsf_frmts/sqlite/ogr_sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,12 +792,6 @@ class OGRSQLiteDataSource final : public OGRSQLiteBaseDataSource
return m_bHaveGeometryColumns;
}

std::vector<std::string>
GetRelationshipNames(CSLConstList papszOptions = nullptr) const override;

const GDALRelationship *
GetRelationship(const std::string &name) const override;

bool AddRelationship(std::unique_ptr<GDALRelationship> &&relationship,
std::string &failureReason) override;
bool ValidateRelationship(const GDALRelationship *poRelationship,
Expand Down
5 changes: 4 additions & 1 deletion ogr/ogrsf_frmts/sqlite/ogrsqlitebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,12 @@ class OGRSQLiteBaseDataSource CPL_NON_FINAL : public GDALPamDataset
int nRowsExpected);

virtual void LoadRelationships() const;

void LoadRelationshipsFromForeignKeys(
const std::vector<std::string> &excludedTables) const;
std::vector<std::string>
GetRelationshipNames(CSLConstList papszOptions = nullptr) const override;
const GDALRelationship *
GetRelationship(const std::string &name) const override;

bool IsSpatialiteLoaded();
static int MakeSpatialiteVersionNumber(int x, int y, int z)
Expand Down
86 changes: 43 additions & 43 deletions ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,49 +275,6 @@ int OGRSQLiteBaseDataSource::GetSpatialiteVersionNumber()
return v;
}

/************************************************************************/
/* GetRelationshipNames() */
/************************************************************************/

std::vector<std::string> OGRSQLiteDataSource::GetRelationshipNames(
CPL_UNUSED CSLConstList papszOptions) const

{
if (!m_bHasPopulatedRelationships)
{
LoadRelationships();
}

std::vector<std::string> oasNames;
oasNames.reserve(m_osMapRelationships.size());
for (auto it = m_osMapRelationships.begin();
it != m_osMapRelationships.end(); ++it)
{
oasNames.emplace_back(it->first);
}
return oasNames;
}

/************************************************************************/
/* GetRelationship() */
/************************************************************************/

const GDALRelationship *
OGRSQLiteDataSource::GetRelationship(const std::string &name) const

{
if (!m_bHasPopulatedRelationships)
{
LoadRelationships();
}

auto it = m_osMapRelationships.find(name);
if (it == m_osMapRelationships.end())
return nullptr;

return it->second.get();
}

/************************************************************************/
/* AddRelationship() */
/************************************************************************/
Expand Down Expand Up @@ -842,6 +799,49 @@ void OGRSQLiteBaseDataSource::LoadRelationshipsFromForeignKeys(
}
}

/************************************************************************/
/* GetRelationshipNames() */
/************************************************************************/

std::vector<std::string> OGRSQLiteBaseDataSource::GetRelationshipNames(
CPL_UNUSED CSLConstList papszOptions) const

{
if (!m_bHasPopulatedRelationships)
{
LoadRelationships();
}

std::vector<std::string> oasNames;
oasNames.reserve(m_osMapRelationships.size());
for (auto it = m_osMapRelationships.begin();
it != m_osMapRelationships.end(); ++it)
{
oasNames.emplace_back(it->first);
}
return oasNames;
}

/************************************************************************/
/* GetRelationship() */
/************************************************************************/

const GDALRelationship *
OGRSQLiteBaseDataSource::GetRelationship(const std::string &name) const

{
if (!m_bHasPopulatedRelationships)
{
LoadRelationships();
}

auto it = m_osMapRelationships.find(name);
if (it == m_osMapRelationships.end())
return nullptr;

return it->second.get();
}

/***********************************************************************/
/* prepareSql() */
/***********************************************************************/
Expand Down

0 comments on commit 9d207db

Please sign in to comment.