Skip to content

Commit 75d33f1

Browse files
authored
Fix const correctness of virtual methods for GDAL 3.12 (#70)
1 parent 3c6ca76 commit 75d33f1

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

source/ogrgrass.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,20 @@ class OGRGRASSLayer final : public OGRLayer
3636
virtual ~OGRGRASSLayer();
3737

3838
// Layer info
39+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
40+
auto GetName() const -> const char * override
41+
#else
3942
auto GetName() -> const char * override
43+
#endif
4044
{
4145
return osName.c_str();
4246
}
47+
48+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
49+
auto GetLayerDefn() const -> const OGRFeatureDefn * override
50+
#else
4351
auto GetLayerDefn() -> OGRFeatureDefn * override
52+
#endif
4453
{
4554
return poFeatureDefn;
4655
}
@@ -58,8 +67,13 @@ class OGRGRASSLayer final : public OGRLayer
5867
}
5968
#endif
6069

61-
virtual auto GetSpatialRef() -> OGRSpatialReference * override;
70+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
71+
auto GetSpatialRef() const -> const OGRSpatialReference * override;
72+
auto TestCapability(const char *) const -> int override;
73+
#else
74+
auto GetSpatialRef() -> OGRSpatialReference * override;
6275
auto TestCapability(const char *) -> int override;
76+
#endif
6377

6478
// Reading
6579
void ResetReading() override;
@@ -145,13 +159,23 @@ class OGRGRASSDataSource final : public OGRDataSource
145159
{
146160
return osName.c_str();
147161
}
162+
163+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
164+
auto GetLayerCount() const -> int override
165+
#else
148166
auto GetLayerCount() -> int override
167+
#endif
149168
{
150169
return nLayers;
151170
}
152-
auto GetLayer(int) -> OGRLayer * override;
153171

172+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
173+
auto GetLayer(int) const -> const OGRLayer * override;
174+
auto TestCapability(const char *) const -> int override;
175+
#else
176+
auto GetLayer(int) -> OGRLayer * override;
154177
auto TestCapability(const char *) -> int override;
178+
#endif
155179

156180
private:
157181
OGRGRASSLayer **papoLayers{nullptr};

source/ogrgrassdatasource.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,23 @@ auto OGRGRASSDataSource::Open(const char *pszNewName, bool /*bUpdate*/,
186186
/************************************************************************/
187187
/* TestCapability() */
188188
/************************************************************************/
189+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
190+
auto OGRGRASSDataSource::TestCapability(const char * /* pszCap*/) const -> int
191+
#else
189192
auto OGRGRASSDataSource::TestCapability(const char * /* pszCap*/) -> int
193+
#endif
190194
{
191195
return FALSE;
192196
}
193197

194198
/************************************************************************/
195199
/* GetLayer() */
196200
/************************************************************************/
201+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
202+
auto OGRGRASSDataSource::GetLayer(int iLayer) const -> const OGRLayer *
203+
#else
197204
auto OGRGRASSDataSource::GetLayer(int iLayer) -> OGRLayer *
205+
#endif
198206
{
199207
if (iLayer < 0 || iLayer >= nLayers)
200208
return nullptr;

source/ogrgrasslayer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,11 @@ auto OGRGRASSLayer::GetExtent(OGREnvelope *psExtent, int /*bForce*/) -> OGRErr
10881088
/************************************************************************/
10891089
/* TestCapability() */
10901090
/************************************************************************/
1091+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
1092+
auto OGRGRASSLayer::TestCapability(const char *pszCap) const -> int
1093+
#else
10911094
auto OGRGRASSLayer::TestCapability(const char *pszCap) -> int
1095+
#endif
10921096
{
10931097
if (EQUAL(pszCap, OLCRandomRead))
10941098
return TRUE;
@@ -1112,7 +1116,11 @@ auto OGRGRASSLayer::TestCapability(const char *pszCap) -> int
11121116
/************************************************************************/
11131117
/* GetSpatialRef() */
11141118
/************************************************************************/
1119+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,12,0)
1120+
auto OGRGRASSLayer::GetSpatialRef() const -> const OGRSpatialReference *
1121+
#else
11151122
auto OGRGRASSLayer::GetSpatialRef() -> OGRSpatialReference *
1123+
#endif
11161124
{
11171125
return poSRS;
11181126
}

0 commit comments

Comments
 (0)