Coverage Report

Created: 2025-06-13 06:29

/src/gdal/ogr/ogrsf_frmts/generic/ogrdatasource.cpp
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  The generic portions of the GDALDataset class.
5
 * Author:   Frank Warmerdam, warmerdam@pobox.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 1999,  Les Technologies SoftMap Inc.
9
 * Copyright (c) 2008-2014, Even Rouault <even dot rouault at spatialys.com>
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13
14
#include "ogrsf_frmts.h"
15
#include "ogr_api.h"
16
#include "ograpispy.h"
17
18
/************************************************************************/
19
/*                            OGRDataSource()                           */
20
/************************************************************************/
21
22
0
OGRDataSource::OGRDataSource() = default;
23
24
/************************************************************************/
25
/*                           ~OGRDataSource()                           */
26
/************************************************************************/
27
28
0
OGRDataSource::~OGRDataSource() = default;
29
30
/************************************************************************/
31
/*                         DestroyDataSource()                          */
32
/************************************************************************/
33
34
//! @cond Doxygen_Suppress
35
void OGRDataSource::DestroyDataSource(OGRDataSource *poDS)
36
37
0
{
38
0
    delete poDS;
39
0
}
40
41
//! @endcond
42
43
/************************************************************************/
44
/*                           OGR_DS_Destroy()                           */
45
/************************************************************************/
46
47
void OGR_DS_Destroy(OGRDataSourceH hDS)
48
49
0
{
50
0
    if (hDS == nullptr)
51
0
        return;
52
0
    GDALClose(reinterpret_cast<GDALDatasetH>(hDS));
53
    // VALIDATE_POINTER0( hDS, "OGR_DS_Destroy" );
54
0
}
55
56
/************************************************************************/
57
/*                          OGR_DS_Reference()                          */
58
/************************************************************************/
59
60
int OGR_DS_Reference(OGRDataSourceH hDataSource)
61
62
0
{
63
0
    VALIDATE_POINTER1(hDataSource, "OGR_DS_Reference", 0);
64
65
0
    return GDALDataset::FromHandle(hDataSource)->Reference();
66
0
}
67
68
/************************************************************************/
69
/*                         OGR_DS_Dereference()                         */
70
/************************************************************************/
71
72
int OGR_DS_Dereference(OGRDataSourceH hDataSource)
73
74
0
{
75
0
    VALIDATE_POINTER1(hDataSource, "OGR_DS_Dereference", 0);
76
77
0
    return GDALDataset::FromHandle(hDataSource)->Dereference();
78
0
}
79
80
/************************************************************************/
81
/*                         OGR_DS_GetRefCount()                         */
82
/************************************************************************/
83
84
int OGR_DS_GetRefCount(OGRDataSourceH hDataSource)
85
86
0
{
87
0
    VALIDATE_POINTER1(hDataSource, "OGR_DS_GetRefCount", 0);
88
89
0
    return GDALDataset::FromHandle(hDataSource)->GetRefCount();
90
0
}
91
92
/************************************************************************/
93
/*                     OGR_DS_GetSummaryRefCount()                      */
94
/************************************************************************/
95
96
int OGR_DS_GetSummaryRefCount(OGRDataSourceH hDataSource)
97
98
0
{
99
0
    VALIDATE_POINTER1(hDataSource, "OGR_DS_GetSummaryRefCount", 0);
100
101
0
    return GDALDataset::FromHandle(hDataSource)->GetSummaryRefCount();
102
0
}
103
104
/************************************************************************/
105
/*                         OGR_DS_CreateLayer()                         */
106
/************************************************************************/
107
108
OGRLayerH OGR_DS_CreateLayer(OGRDataSourceH hDS, const char *pszName,
109
                             OGRSpatialReferenceH hSpatialRef,
110
                             OGRwkbGeometryType eType, char **papszOptions)
111
112
0
{
113
0
    VALIDATE_POINTER1(hDS, "OGR_DS_CreateLayer", nullptr);
114
115
0
    if (pszName == nullptr)
116
0
    {
117
0
        CPLError(CE_Failure, CPLE_ObjectNull,
118
0
                 "Name was NULL in OGR_DS_CreateLayer");
119
0
        return nullptr;
120
0
    }
121
0
    OGRLayerH hLayer =
122
0
        OGRLayer::ToHandle(GDALDataset::FromHandle(hDS)->CreateLayer(
123
0
            pszName, OGRSpatialReference::FromHandle(hSpatialRef), eType,
124
0
            papszOptions));
125
126
0
#ifdef OGRAPISPY_ENABLED
127
0
    if (bOGRAPISpyEnabled)
128
0
        OGRAPISpy_DS_CreateLayer(hDS, pszName, hSpatialRef, eType, papszOptions,
129
0
                                 hLayer);
130
0
#endif
131
132
0
    return hLayer;
133
0
}
134
135
/************************************************************************/
136
/*                          OGR_DS_CopyLayer()                          */
137
/************************************************************************/
138
139
OGRLayerH OGR_DS_CopyLayer(OGRDataSourceH hDS, OGRLayerH hSrcLayer,
140
                           const char *pszNewName, char **papszOptions)
141
142
0
{
143
0
    VALIDATE_POINTER1(hDS, "OGR_DS_CopyLayer", nullptr);
144
0
    VALIDATE_POINTER1(hSrcLayer, "OGR_DS_CopyLayer", nullptr);
145
0
    VALIDATE_POINTER1(pszNewName, "OGR_DS_CopyLayer", nullptr);
146
147
0
    return OGRLayer::ToHandle(GDALDataset::FromHandle(hDS)->CopyLayer(
148
0
        OGRLayer::FromHandle(hSrcLayer), pszNewName, papszOptions));
149
0
}
150
151
/************************************************************************/
152
/*                         OGR_DS_DeleteLayer()                         */
153
/************************************************************************/
154
155
OGRErr OGR_DS_DeleteLayer(OGRDataSourceH hDS, int iLayer)
156
157
0
{
158
0
    VALIDATE_POINTER1(hDS, "OGR_DS_DeleteLayer", OGRERR_INVALID_HANDLE);
159
160
0
#ifdef OGRAPISPY_ENABLED
161
0
    if (bOGRAPISpyEnabled)
162
0
        OGRAPISpy_DS_DeleteLayer(reinterpret_cast<GDALDatasetH>(hDS), iLayer);
163
0
#endif
164
165
0
    OGRErr eErr = GDALDataset::FromHandle(hDS)->DeleteLayer(iLayer);
166
167
0
    return eErr;
168
0
}
169
170
/************************************************************************/
171
/*                       OGR_DS_GetLayerByName()                        */
172
/************************************************************************/
173
174
OGRLayerH OGR_DS_GetLayerByName(OGRDataSourceH hDS, const char *pszLayerName)
175
176
0
{
177
0
    VALIDATE_POINTER1(hDS, "OGR_DS_GetLayerByName", nullptr);
178
179
0
    OGRLayerH hLayer = OGRLayer::ToHandle(
180
0
        GDALDataset::FromHandle(hDS)->GetLayerByName(pszLayerName));
181
182
0
#ifdef OGRAPISPY_ENABLED
183
0
    if (bOGRAPISpyEnabled)
184
0
        OGRAPISpy_DS_GetLayerByName(reinterpret_cast<GDALDatasetH>(hDS),
185
0
                                    pszLayerName, hLayer);
186
0
#endif
187
188
0
    return hLayer;
189
0
}
190
191
/************************************************************************/
192
/*                         OGR_DS_ExecuteSQL()                          */
193
/************************************************************************/
194
195
OGRLayerH OGR_DS_ExecuteSQL(OGRDataSourceH hDS, const char *pszStatement,
196
                            OGRGeometryH hSpatialFilter, const char *pszDialect)
197
198
0
{
199
0
    VALIDATE_POINTER1(hDS, "OGR_DS_ExecuteSQL", nullptr);
200
201
0
    OGRLayerH hLayer =
202
0
        OGRLayer::ToHandle(GDALDataset::FromHandle(hDS)->ExecuteSQL(
203
0
            pszStatement, OGRGeometry::FromHandle(hSpatialFilter), pszDialect));
204
205
0
#ifdef OGRAPISPY_ENABLED
206
0
    if (bOGRAPISpyEnabled)
207
0
        OGRAPISpy_DS_ExecuteSQL(reinterpret_cast<GDALDatasetH>(hDS),
208
0
                                pszStatement, hSpatialFilter, pszDialect,
209
0
                                hLayer);
210
0
#endif
211
212
0
    return hLayer;
213
0
}
214
215
/************************************************************************/
216
/*                      OGR_DS_ReleaseResultSet()                       */
217
/************************************************************************/
218
219
void OGR_DS_ReleaseResultSet(OGRDataSourceH hDS, OGRLayerH hLayer)
220
221
0
{
222
0
    VALIDATE_POINTER0(hDS, "OGR_DS_ReleaseResultSet");
223
224
0
#ifdef OGRAPISPY_ENABLED
225
0
    if (bOGRAPISpyEnabled)
226
0
        OGRAPISpy_DS_ReleaseResultSet(reinterpret_cast<GDALDatasetH>(hDS),
227
0
                                      hLayer);
228
0
#endif
229
230
0
    GDALDataset::FromHandle(hDS)->ReleaseResultSet(
231
0
        OGRLayer::FromHandle(hLayer));
232
0
}
233
234
/************************************************************************/
235
/*                       OGR_DS_TestCapability()                        */
236
/************************************************************************/
237
238
int OGR_DS_TestCapability(OGRDataSourceH hDS, const char *pszCapability)
239
240
0
{
241
0
    VALIDATE_POINTER1(hDS, "OGR_DS_TestCapability", 0);
242
0
    VALIDATE_POINTER1(pszCapability, "OGR_DS_TestCapability", 0);
243
244
0
    return GDALDataset::FromHandle(hDS)->TestCapability(pszCapability);
245
0
}
246
247
/************************************************************************/
248
/*                        OGR_DS_GetLayerCount()                        */
249
/************************************************************************/
250
251
int OGR_DS_GetLayerCount(OGRDataSourceH hDS)
252
253
0
{
254
0
    VALIDATE_POINTER1(hDS, "OGR_DS_GetLayerCount", 0);
255
256
0
#ifdef OGRAPISPY_ENABLED
257
0
    if (bOGRAPISpyEnabled)
258
0
        OGRAPISpy_DS_GetLayerCount(reinterpret_cast<GDALDatasetH>(hDS));
259
0
#endif
260
261
0
    return GDALDataset::FromHandle(hDS)->GetLayerCount();
262
0
}
263
264
/************************************************************************/
265
/*                          OGR_DS_GetLayer()                           */
266
/************************************************************************/
267
268
OGRLayerH OGR_DS_GetLayer(OGRDataSourceH hDS, int iLayer)
269
270
0
{
271
0
    VALIDATE_POINTER1(hDS, "OGR_DS_GetLayer", nullptr);
272
273
0
    OGRLayerH hLayer =
274
0
        OGRLayer::ToHandle(GDALDataset::FromHandle(hDS)->GetLayer(iLayer));
275
276
0
#ifdef OGRAPISPY_ENABLED
277
0
    if (bOGRAPISpyEnabled)
278
0
        OGRAPISpy_DS_GetLayer(reinterpret_cast<GDALDatasetH>(hDS), iLayer,
279
0
                              hLayer);
280
0
#endif
281
282
0
    return hLayer;
283
0
}
284
285
/************************************************************************/
286
/*                           OGR_DS_GetName()                           */
287
/************************************************************************/
288
289
const char *OGR_DS_GetName(OGRDataSourceH hDS)
290
291
0
{
292
0
    VALIDATE_POINTER1(hDS, "OGR_DS_GetName", nullptr);
293
294
0
    return GDALDataset::FromHandle(hDS)->GetDescription();
295
0
}
296
297
/************************************************************************/
298
/*                         OGR_DS_SyncToDisk()                          */
299
/************************************************************************/
300
301
OGRErr OGR_DS_SyncToDisk(OGRDataSourceH hDS)
302
303
0
{
304
0
    VALIDATE_POINTER1(hDS, "OGR_DS_SyncToDisk", OGRERR_INVALID_HANDLE);
305
306
0
    GDALDataset::FromHandle(hDS)->FlushCache(false);
307
0
    if (CPLGetLastErrorType() != 0)
308
0
        return OGRERR_FAILURE;
309
0
    else
310
0
        return OGRERR_NONE;
311
0
}
312
313
/************************************************************************/
314
/*                          OGR_DS_GetDriver()                          */
315
/************************************************************************/
316
317
OGRSFDriverH OGR_DS_GetDriver(OGRDataSourceH hDS)
318
319
0
{
320
0
    VALIDATE_POINTER1(hDS, "OGR_DS_GetDriver", nullptr);
321
322
0
    return reinterpret_cast<OGRSFDriverH>(
323
0
        reinterpret_cast<OGRDataSource *>(hDS)->GetDriver());
324
0
}
325
326
/************************************************************************/
327
/*                         OGR_DS_GetStyleTable()                       */
328
/************************************************************************/
329
330
OGRStyleTableH OGR_DS_GetStyleTable(OGRDataSourceH hDS)
331
332
0
{
333
0
    VALIDATE_POINTER1(hDS, "OGR_DS_GetStyleTable", nullptr);
334
335
0
    return reinterpret_cast<OGRStyleTableH>(
336
0
        GDALDataset::FromHandle(hDS)->GetStyleTable());
337
0
}
338
339
/************************************************************************/
340
/*                         OGR_DS_SetStyleTableDirectly()               */
341
/************************************************************************/
342
343
void OGR_DS_SetStyleTableDirectly(OGRDataSourceH hDS,
344
                                  OGRStyleTableH hStyleTable)
345
346
0
{
347
0
    VALIDATE_POINTER0(hDS, "OGR_DS_SetStyleTableDirectly");
348
349
0
    GDALDataset::FromHandle(hDS)->SetStyleTableDirectly(
350
0
        reinterpret_cast<OGRStyleTable *>(hStyleTable));
351
0
}
352
353
/************************************************************************/
354
/*                         OGR_DS_SetStyleTable()                       */
355
/************************************************************************/
356
357
void OGR_DS_SetStyleTable(OGRDataSourceH hDS, OGRStyleTableH hStyleTable)
358
359
0
{
360
0
    VALIDATE_POINTER0(hDS, "OGR_DS_SetStyleTable");
361
0
    VALIDATE_POINTER0(hStyleTable, "OGR_DS_SetStyleTable");
362
363
0
    GDALDataset::FromHandle(hDS)->SetStyleTable(
364
0
        reinterpret_cast<OGRStyleTable *>(hStyleTable));
365
0
}